Answer:
The C++ code is given below with appropriate comments for better understanding
Explanation:
/*C++ program that prompts user to enter the name of input file(input.txt in this example) and print the sum of the values in the file to console. If file dosnot exist, then close the program */
//header files
#include <fstream>
#include<string>
#include <iostream>
#include <cstdlib> //needed for exit function
using namespace std;
//function prototype
int fileSum(string filename);
int main()
{
string filename;
cout << "Enter the name of the input file: ";
cin >> filename;
cout << "Sum: " << fileSum(filename) << endl;
system("pause");
return 0;
}
/*The function fileSum that takes the string filename and
count the sum of the values and returns the sum of the values*/
int fileSum(string filename)
{
//Create a ifstream object
ifstream fin;
//Open a file
fin.open(filename);
//Initialize sum to zero
int sum=0;
//Check if file exist
if(!fin)
{
cout<<"File does not exist ."<<endl;
system("pause");
exit(1);
}
else
{
int value;
//read file until end of file exist
while(fin>>value)
{
sum+=value;
}
}
return sum;
}//end of the fileSum
Macronutrients include carbon, phosphorous, oxygen, sulfur, hydrogen, nitrogen and zinc. (T/F)
Answer:
The answer to your question is False
Explanation:
Macronutrients are complex organic molecules, these molecules give energy to the body, promote the growing and the good regulation of the body. Examples of macromolecules are Proteins, carbohydrates, and Lipids.
Micronutrients are substances that do not give energy to the body but they are essential for the correct functioning of the body. Examples of micronutrients are Vitamins and Minerals.
What is the output of the following query? SELECT INSERT ('Knowledgeable', 5, 6, 'SUPER');
Answer:
The above query gives an error.
Explanation:
The query gives an error because is not the correct syntax of the select or inserts query.The syntax of the select query is as follows: "select Attributes_1_name, Attributes_2_name,...., Attributes_n_name from table_name;".The syntax of the insert query is : "insert into table_name (column_1_name, column_2_name,...,column_n_name) values (column_1_value, column_2_value,...,column_n_value);".The syntax of the insert and select query is : "insert into table_name (select Attributes_1_name, Attributes_2_name,...., Attributes_n_name from table_name);".But the above query does not satisfy any property which is defined above. Hence it gives a compile-time error.A(n) __________ in the name of a form indicates a hierarchy of namespaces to allow the computer to locate the Form class in a computer’s main memory.
Answer:
A dot member access operator in the name of a form indicates a hierarchy of namespaces to allow the computer to locate the Form class in a computer’s main memory.
Dot (.) operator is known as "Class Member Access Operator" in C++ programming language, it is used to grant access to public members of a class. Public members contain data members (variables) and member functions (class methods) of a class.
Which command would rename the file cows.txt to cheezburger.txt? Select one: a. mv cows.txt cheezburger.txt b. I can haz cheezburger! c. rename cows.txt d. rn cows.txt cheezburger.txt e. rm cows.txt
Answer:
Option A i.e., mv cows.txt cheezburger.txt is the correct option.
Explanation:
In Linux, mv means move that is used to move a file from one destination to other but the user also used the mv command for renaming the file because it is the easiest way to rename any file to others.
Syntax:
mv first_file.ext new_file.ext
In the above syntax, mv is the command and first_file is the name of that file whose name wants to be change and .ext is the file extension, new_file.ext is that file that name wants to be applied on first one.
We will pass in 2 values, X and Y. You should calculate XY XY and output only the final result. You will probably know that XY XY can be calculated as X times itself Y times. # Get X and Y from the command line:import sysX= int(sys.argv[1])Y= int(sys.argv[2])# Your code goes here
Answer:
import sys
# The value of the second argument is assigned to X
x = int(sys.argv[1])
# The value of the third argument is assigned to Y
y = int(sys.argv[2])
# The result of multiplication of x and y is assigned to 'result'
result = x * y
#The value of the result is displayed to the user
print("The result of multiplying ", x, "and ", y, "is", result)
Explanation:
First we import sys which allow us to read the argument passed when running the program. The argument is number starting from index 0; the name of the python file been executed is sys.argv[0] which is the first argument. The second argument is sys.argv[1] and the third argument is sys.argv[2].
The attached file is named multplyxy (it wasn't saved as py file because the platform doesn't recognise py file); we can execute it by running: python3 multiplyxy.py 10 23
where x will be 10 and y will be 23.
To run the attached file; it content must be saved as a py file: multiplyxy.py
Violations of security policies are considered to be a(n) __________ issue upon which proper disciplinary actions must be taken.
law enforcement
employer-employee
executive-staff
implementation
Answer:
Violations of security policies are considered to be a(n) law enforcement issue upon which proper disciplinary actions must be taken.
Explanation:
The security policies are considered as law enforcement issue, which may include the rules and regulations of the society decided by the government. These rules and regulations are necessary to maintain the norms of society.
The issue comes under the law enforcement are cyber crime, women rights security in working environment of the organization, use of technology that may cause threats for the society.
To enforce these law to maintain the security in the society, department of law and enforcement has been established such as Police department, Some intelligence agencies. They takes proper disciplinary action under the law enforcement to maintain the security in society against violation of rules.
Which of the following is required for counter-controlled repetition?
A. a boolean
B. a method
C. a condition
D. All of the above
Counter-controlled repetition requires a condition to determine when the loop should stop, involving initializing a counter, setting a condition for it, and updating the counter within the loop. No boolean or method is strictly required, just the condition.
Explanation:The question asks which of the following is required for counter-controlled repetition. The correct answer is C. a condition. In computer programming, counter-controlled repetition requires a condition to determine when the repetition should stop. This involves initializing a counter to a starting value, setting a condition for the counter (such as counter < 10), and updating the counter within the loop (often incrementing or decrementing). This loop continues to execute as long as the condition evaluates to true.
For example, in a for loop, you might see something like for(int i = 0; i < 10; i++), where i is the counter, i < 10 is the condition that must be true for the loop to continue, and i++ updates the counter. No boolean or method is strictly required for this process, just the condition that guides the repetition.
What is it called to persist in trying to multitask can result in this; the scattering bits of one’s attention among a number of things at any given time?
Select one:
a. attention
b. multi tasking
c. continuous partial attention
d. none of the choices are correct
Answer: is Option B.
B). Multi tasking: A person capability to carry out more than one task at the same time is called multitasking. Person performing more than one task at the same time is nearly impossible and it's hard for him to focus on each and every detail, thus leading to scatter attention among numbers of things at a time resulting in inaccuracy and greater numbers of fault in final result.
Explanation of other points:
A). Attention: is defined as performing tasks with special care and concentration.
C). Continuous partial attention: Under this category people perform tasks by concentrating on different sources to fetch information by only considering the most valid information among all information. people who use this technique to gather information works superficially concentrating on the relevant information out of numerous sources in a short period of thinking process.
Create a C++ program that consists of the following: In main create the following three variables: A char named theChar A double named theDouble An int named theInt Fill each of these variables with data taken as input from the keyboard using a single cin statement. Perform the following task on each variable: Increment theChar by one Decrement theDouble by two Square theInt This should be done on separate lines. Note, outputting theChar + 1 is not modifying the variable. It is simply outputting it. Output the value of each variable to the screen on separate lines using cout statements. Your program should also output the name of the variable followed by a colon.
Answer:
The source code and output is attached.
I hope it will help you!
Explanation:
Which of the following is a best practice for a strong password policy?
O Users must reuse one of the last five passwords.
O Passwords may be reset only after 30 days.
O Passwords must meet basic complexity requirements.
O Organizational Unit policy should be enforced over Domain policy.
Answer:
Passwords must meet basic complexity requirements.
Explanation:
Password should contain:
Uppercase lettersLowercase lettersdigits (0 through 9)special characters like @#$%^&*minimum length of 8Passwords should not contain:
user's name or surnamebirth year/datenot similar to previous passwordaccount/identity numberCourts are struggling with the privacy implications of GPStracking. In 2009, New York’s highest court held that policeofficers must have a ______________ in order to place a GPStracking device on a suspect’s car.
a. warrant
b. injunction
c. RFID tagtor
d. warrant
Answer:
warrant
Explanation:
New York State's highest court ruled in 2009 that tracking a person via the global positioning system (GPS) without a warrant violated his right to privacy.
One example of a Microsoft Store app is Select one: a. Photos. b. Paint. c. File Explorer. d. Notepad.
Answer:
b. Paint
Explanation:
Paint was one of Microsoft's application that allowed users to draw basic diagrams and visual representation of objects. Microsoft Paint was discontinued as an addition in the latest versions of Windows, however the app is available for download from Microsoft Store App. Photos is an application of Apple, whereas File Explorer and Notepad are default applications of Windows operating system.
One example of a Microsoft Store app is Paint. Therefore, the correct answer is option B.
Paint was one of Microsoft's application that allowed users to draw basic diagrams and visual representation of objects. Microsoft Paint was discontinued as an addition in the latest versions of Windows, however the app is available for download from Microsoft Store App. Photos is an application of Apple, whereas File Explorer and Notepad are default applications of Windows operating system.
Therefore, the correct answer is option B.
Learn more about the Microsoft Store app here:
https://brainly.com/question/3371513.
#SPJ6
In this new file write a function called swapInts that swaps (interchanges) the values of two integers that it is given access to via pointer parameters. Write a mainfunction that asks the user for two integer values, stores them in variables num1 and num2, calls the swap function to swap the values of num1 & num2, and then prints the resultant (swapped) values of the same variables num1 and num2.
Here is the C++ program to swap the values of two integers. However, let me know if you require the program in some other programming language.
Program:#include <iostream>
/*include is preprocessor directive that directs preprocessor to iostream header file that contains input output functions */
using namespace std;
// namespace is used by computer to identify cout endl cin
void swapInts(int* no1, int* no2) {
/*function swapInts definition which swaps two integer values having pointer type parameters */
int temp; //temporary variable to hold the integer values
temp = *no1; // holds the value at address of no1
*no1 = *no2; //places no2 to no1
*no2 = temp; } //places no2 to temp variable which is holding no1
int main() // enters body of the main function
{ int num1; //declares variable num1 of integer type
int num2; //declares variable num2 of integer type
cout << "Enter two integer values:" << endl;
// prompts the user to input two integer values
cin>>num1; // reads input value of num1
cin>>num2; // reads input value of num2
cout<<"The original value of num1 before swapping is = "<<num1<<endl;
/*displays the original value of integer in num1 variable before calling swapInts function*/
cout<<"The original value of num2 before swapping is = "<<num2<<endl;
/*displays the original value of integer in num2 variable before calling swapInts function*/
swapInts(&num1, &num2);
/*function call to swapInts()) function and here &num1 is address of num1 variable and &num2 is address of num2 variable */
cout << "The swapped value of num1 is = " << num1 << endl;
//displays the value of num1 after swapping
cout << "The swapped value of num2 is = " << num2 << endl; }
//displays the value of num2 integer after swapping/
Output:Enter two integer values:
3
5
The original value of num1 before swapping is = 3
The original value of num2 before swapping is = 5
The swapped value of num1 is = 5
The swapped value of num2 is = 3
Explanation:This swapInts(&num1, &num2); statement calls the function swapInts() by passing the addresses of variables num1 and num2 in function call instead of the values of variables. In simple words the function is called by passing values by pointer. For this purpose the symbol & is used which is called reference operator which is used to assign address of the variables.So this method is called passing by pointer, which means that address of an actual argument in call to the function is copied to the formal parameters of the called function. The passed argument also gets changed with the change made to the formal parameter.In void swapInts(int* no1, int* no2) statement no1 holds the address of num1 and no2 holds the address of num2. Also *no1 and *no2 give value stored at addresses num1 and num2. So to obtain the value which is stored in these addresses, dereference operator "*" is being used with pointer variables *no1 and *no2.The address of num1 and num2 is passed to this function instead of the values of num1 and num2 Now if any changes are made to *no1 and *no2 this will affect the value of num1 and num2 and their value will be changed too.If someone’s boss wanted to send a message to an employee that contains both a video and a Word processing document, which Internet service would be the most appropriate for her to use?\
Answer:
Email.
Explanation:
Email or electronic mail is a digital messaging platform that sends digitised data through the internet to a specific or group of specified receivers.
It uses the IMAP protocol to download copies of received data from the server to the client's computer and the POP protocol to store the data only on the server, with a copy sent to the client.
The email environment provides an attachment tool to add video, image or audio files to text documents on the message to be sent across.
State three reasons that Visual Basic is one of the most widely used programming languages in the world.
Visual Basic is widely used for three reasons: it is easy to learn, provides rapid application development, and integrates well with Microsoft products.
Explanation:Three Reasons Visual Basic is Widely UsedEasy to Learn: Visual Basic is known for its simplicity and beginner-friendly nature. The language uses a graphical user interface (GUI) and provides drag-and-drop functionality, making it easier for new programmers to understand and create applications.Rapid Application Development (RAD): Visual Basic offers a wide range of pre-built components and controls that simplify the development process. Developers can quickly prototype and create applications, reducing the time and effort required to build software.Integration with Microsoft Products: Visual Basic is developed and supported by Microsoft, which provides extensive documentation, resources, and integration with other Microsoft technologies like Excel, Word, and Access. This makes it a popular choice for building Windows-based applications.Learn more about Reasons for Visual Basic's popularity here:https://brainly.com/question/36344044
#SPJ3
What is the value of vals[4][1]? double[][] vals = {{1.1, 1.3, 1.5}, {3.1, 3.3, 3.5}, {5.1, 5.3, 5.5}, {7.1, 7.3, 7.5}};
Answer:
When the user concludes the value of "vals[4][1]", then it will give an exception of "ArrayIndexOutOfBoundsException".
Explanation:
It is because the size of the above array is [4*3] which takes the starting index at [0][0] and ending index at [3][2]. It is because the array index value starts from 0 and ends in (s-1). When the double dimension array size is [5][5], then it will conclude the value of [4][1].The above array have following index which value can be calculated :-- [0][0],[0][1],[0][2],[1][0], [1][1],[1][2], [2][0], [2][1], [2][2],[3][0],[3][1] and [3][2].Database management systems are expected to handle binary relationships but not unary and ternary relationships.'
True or false
Answer:
False
Database management systems are expected to handle binary, unary and ternary relationships.
Explanation:
Unary Relationship: It is a recursive relationship which includes one entity in a relationship which means that there is a relationship between the instances of the same entity. Primary key and foreign key are both the same here. For example a Person is married to only one Person. In this example there is a one-to-one relationship between the same entity i.e. Person.
Binary Relationships: It is a relationship involving two different entities. These two entities identified using two relations and another relation to show relationship between two entities and this relation holds primary keys of both entities and its own primary key is the combination of primary keys of the both relations of the two entities. For example Many Students can read a Book and many Books can be obtained by a Student.
Ternary Relationships: is a relationship involving three entities and can have three tables. For example a Supplier can supply a specific Part of many Mobiles. Or many Suppliers may supply several Parts of many Mobile models.
Final answer:
The claim that database management systems cannot handle unary and ternary relationships is false; they can manage unary, binary, and ternary relationships as well as other complex relationships.
Explanation:
The statement 'Database management systems are expected to handle binary relationships but not unary and ternary relationships.' is false. Modern database management systems (DBMS) are equipped to handle a variety of relationship types, including unary (or recursive), binary, and ternary relationships, among others. A unary relationship is an association between two instances of the same entity. For example, an employee entity might have a manager relationship that relates an employee to another employee who is the manager. A binary relationship exists between two different entities, such as an 'Employee' entity and a 'Department' entity where an employee works in a department. A ternary relationship involves three different entities at the same time, such as a 'Supplier', 'Product', and 'Consumer' entities, where a supplier provides products to a consumer.
Which of the following can be used to copy a file into OneDrive from the File Explorer window? Select all that apply.
A. select the file or folder
B. on the home tab in the clipboard group, click the copy button
C. navigate to the folder you want to move the file to and click the paste button
Final answer:
To copy a file to OneDrive from File Explorer, select the file, click the 'Copy' button in the Clipboard group under the Home tab, navigate to the OneDrive folder, and click 'Paste'. All the options are correct.
Explanation:
To copy a file into OneDrive from the File Explorer window, you would typically follow these steps:
Select the file or folder you wish to copy.On the Home tab in the Clipboard group, click the Copy button.Navigate to the OneDrive folder where you want to place the file.Click the Paste button to copy the file into the selected OneDrive folder.All of the actions listed - selecting the file or folder (A), clicking the copy button on the home tab in the clipboard group (B), and navigating to the folder you want to move the file to and clicking the paste button (C) - are steps in the process of copying a file to OneDrive.
To prevent users of the application from changing the size of the form. you must set the FormBorderStyle property to ____
Answer:
The answer is "Fixed-single".
Explanation:
A FormBorderStyle property is a part of the C# language, which is used to displays the form's border style for viewing an application form. This property uses the fixed-single attribute, which will be used to determine, if the template or form can be resized by the end-user, it can be dragged or resized by no border or a title bar. A fixed, single-line border.
What does this method do?
public static int foo(String [][] a)
{
int b = 0;
for (int I = 0; i
{
b++;
}
return b;
}
COMPLETE QUESTION:
What does this method do?
public static int foo(String [][] a)
{
int b = 0;
for (int i = 0; i<a.length; i++)
{
b++;
}
return b;
}
Answer:
Returns the value of b which is the dimension of the array
Explanation:
The method foo accepts a multi dimension array and returns the dimension of the array. A complete code implementation and call to the method is given below:
public class TestClass {
public static void main(String[] args) {
String [ ] [ ] arr = {{"gh","hj","fg", "re","tr"},{"","er","df","fgt", "tr"}};
System.out.println(foo(arr));
}
public static int foo(String [ ][ ] a)
{
int b = 0;
for (int i = 0; i<a.length; i++)
{
b++;
}
return b;
}
}
The output from the code snippet is the value of b which is 2
How will you ensure that all of the network's applications and tcp/ip services also support ipv6?
Answer:
Configure the Extended BSD API socket.
Explanation:
There are two types of logical network address, they are IP version 4 and up version 6. They are used to route packets to various destinations from various sources.
A network application must configure this IP addresses protocol. The IP version4 is the default address applications use. To enable IP version 6 the extended BSD API is configured on the network.
A(n) __________ is a set of technologies used for exchanging data between applications and for connecting processes with other systems across the organization, and with business partners. Select one:
a. ERP
b. mashup
c. SOA
d. Web service
Answer:
The answer is "Option ".
Explanation:
The SOA stands for "Service-Oriented Architecture", which is primarily known as a service set and these services enable you to communicate with each other. In the communication, it may require simple data to transfer to two or more services, which can be organized by those operations, and other options were incorrect, that can be explained as follows:
In option a, It is a business software, which is used to organized data, that's why it is wrong.Option b and Option d both are wrong because the mashup process is used only on web services, which is not a part of SOA , that's why it is wrong.Answer:
The correct answer is letter "C": SOA.
Explanation:
Service-oriented architecture (SOA) is a type of software structure oriented to the integration of applications that share the same network or between different software systems that are part of different domains. SOA has the objective of aligning users with all the Information Technology (IT) of their organization.
CTIVITY 2.2.2: Method call in expression. Assign to maxSum the max of (numA, numB) PLUS the max of (numY, numZ). Use just one statement. Hint: Call findMax() twice in an expression.
Answer:
The one statement is:
maxSum = maxFinder.findMax(numA, numB) + maxFinder.findMax(numY, numZ);
Explanation:
The given code in the Activity contains a method named findMax() in class SumOfMax which has two parameters num1 and num2. The method returns the maximum value after comparing the values of num1 and num2.In the main() function, 4 variables numA, numB, numY and numZ of type double are declared and assigned the values numA=5.0, numB=10.0, numY=3.0 and numZ=7.0. Also a variable maxSum is declared and initialized by 0. After that an object named maxfinder of SumOfMax class is created using keyword new.SumOfMax maxFinder = new SumOfMax();
We can invoke the method findMax() by using reference operator (.) with the object name. So the task is to assign to maxSum the maximum of numA, numB plus maximum of numY, numZ in one statement. Using findMax() method we can find the maximum of numA and numB and also can find the maximum numY and numZ. The other requirement is add (PLUS) the maximum of numA, numB to maximum of numY, numZ. The statement used for this is given below:maxSum = maxFinder.findMax(numA, numB) + maxFinder.findMax(numY, numZ);
So as per the hint given in the question statement, findMax() function is being called twice, at first to find the maximum between the values of variables numA and numB and then to find the maximum between the values of numY and numZ. According to the given values of each of these variables:numA=5.0, numB=10.0,
So numB>numA
Hence findMax returns numB whose value is greater than numA Now findMax() is being called again for these variables:numY=3.0 and numZ=7.0
So numZ>numY as 7.0>3.0
Hence findMax() returns numZ whose value is 7.0Finally according to the statement maximum will be added and the result of this addition will be assigned to variable maxSum10.0 is added to 7.0 which makes 17.0 System.out.print("maxSum is: " + maxSum);This statement displays the value of maxSum which is 17.0
___________ is the term used to describe the time taken from when a packet is sent to when the packet arrives at the destination. This is commonly referred to as "ping time" in various places such as online gaming.
Answer:
Packet delay
Explanation:
In measuring the efficiency of a network, one of the many factors to consider is packet delay. Packet delay is the total time taken for a data packet to travel from its source network to its destination. It is sometimes called latency.
High packet delay or latency are caused by, but not limited to, the following:
(i) The distance between the source network and the destination network
(ii) The size of the packet being transferred
(iii) The time taken to forward data - packet switching delay.
A data file "parttolerance.dat" stores on one line, a part number, and the minimum and maximum values for the valid range that the part could weigh. Write a script "parttol" that will read these values from the file, prompt the user for a weight, and print whether or not that weight is within range. For example, IF the file stores the following:>> type parttolerance.dat123 44.205 44.287Here might be examples of executing the script:>> parttolEnter the part weight: 44.33The part 123 is not in range>> parttolEnter the part weight: 44.25The part 123 is within range
Final answer:
The script 'parttol' reads a data file with part numbers and weight tolerances, prompts for a weight input, and assesses if it's within range, providing feedback on part validity.
Explanation:
The question involves writing a script parttol for reading a data file named parttolerance.dat which contains part numbers and their respective weight tolerance ranges. The script should then prompt the user for a weight input and determine if that weight is within the range specified for a part number.
Here's a pseudocode outline for the parttol script:
Open and read the contents of parttolerance.dat.Extract the part number, minimum, and maximum weight values.Prompt the user to enter a weight.Check if the entered weight is within the range.Print a message indicating whether the part is within range.The execution of this script provides feedback to the user about the validity of the part's weight, thereby ensuring quality control in a manufacturing or engineering context.
what is the maximum number of charters of symbols that can be represented by UNicode?
Answer: 16 bit
Explanation:
Do you believe that OOP should be phased out and we should start working on some alternative(s)? Provide your answer with Yes or No.
Give your opinion with two solid reasons to support your answer.
Answer:
I don't think so. In today's computer era, many different solution directions exist for any given problem. Where OOP used to be the doctrine of choice, now you would consider it only when the problem at hand fits an object-oriented solution.
Reason 1: When your problem can be decomposed in many different classes with each many instances, that expose complex interactions, then an OO modeling is justified. These problems typically produce messy results in other paradigms.
Reason 2: The use of OO design patterns provides a standardized approach to problems, making a solution understandable not only for the creator, but also for the maintainer of code. There are many OO design patterns.
A 'deny any-any' rule in a firewall ruleset is normally placed: a. Nowhere in the ruleset if it has a default allow policyb. Below the last allow rule, but above the first deny rule in the rulesetc. At the top of the rulesetd. At the bottom of the ruleset
Answer:
D. . At the bottom of the ruleset
Explanation:
The main purpose of firewalls is to drop all traffic that is not explicitly permitted. As a safeguard to stop uninvited traffic from passing through the firewall, place an any-any-any drop rule (Cleanup Rule) at the bottom of each security zone context
Write a series of conditional tests. Print a statement describing each test and your prediction for the results of each test. For example, your code may look something like this:car = 'subaru'print("Is car == 'subaru'? I predict True.")print(car == 'subaru')print("\nIs car == 'audi'? I predict False.")print(car == 'audi')Create at least 4 tests. Have at least 2 tests evaluate to True and another 2 tests evaluate to False.
Answer:
this:name = 'John'
print("Is name == 'John'? I predict True.")
print(name == 'John')
print("\nIs name == 'Joy'? I predict False.")
print(car == 'Joy')
this:age = '28'
print("Is age == '28'? I predict True.")
print(age == '28')
print("\nIs age == '27'? I predict False.")
print(age == '27')
this:sex = 'Male'
print("Is sex == 'Female'? I predict True.")
print(sex == 'Female')
print("\nIs sex == 'Female'? I predict False.")
print(sex == 'Joy')
this:level = 'College'
print("Is level == 'High School'? I predict True.")
print(level == 'High School')
print("\nIs level == 'College'? I predict False.")
print(age == 'College')
Conditions 1 and 2 test for name and age
Both conditions are true
Hence, true values are returned
Conditions 3 and 4 tests for sex and level
Both conditions are false
Hence, false values are returned.
Conditional tests in Python allow you to check if a certain condition is True or False. Here are four examples of conditional tests with predictions and code outputs.
Explanation:Conditional Tests in PythonConditional tests in Python allow you to check if a certain condition is True or False. They are often used in decision-making structures like if statements. Here are four examples of conditional tests:
age = 16
print('Is age greater than 18? I predict False.')
print(age > 18)
temperature = 25
print('Is temperature between 20 and 30? I predict True.')
print(20 < temperature < 30)
is_raining = False
print('Is it not raining? I predict True.')
print(not is_raining)
name = 'John'
print('Does name start with J? I predict True.')
print(name.startswith('J'))
These examples demonstrate how to use conditional statements in Python to check if certain conditions are True or False, and then execute different code based on the results.
Learn more about Conditional Tests here:https://brainly.com/question/34742710
#SPJ3
Using basic programming (for loops, while loops, and if statements), write two MATLAB functions, both taking as input:
- dimension n;
- n x n matrix A;
- n x n matrix B;
-n × 1 vector x.
Have the first function compute ABx through (AB)x and the second compute ABx through A(Bx). Have both output:
- the number of flops used.
(a) Print out or write out the first function.
(b) Print out or write out the second function.
(c) Apply both your functions to the case with random matrices and vectors for n = 100 and print out or write out the results. Do the same for 200 x 200, 400 x 400, and 800 x 800. Which approach of computing ABx is faster?
Answer:
For n = 100
(AB)x: 10100A(Bx): 200For n = 200
(AB)x: 40200A(Bx): 400For n = 400
(AB)x: 160400A(Bx): 800For n = 800
(AB)x: 640800A(Bx): 1600The faster approach is A(Bx)
Explanation step by step functions:
A(Bx) is faster because requires fewer interactions to find a result: for (AB)x you have (n*n)+n interactions while for A(Bx) you have n+n, to understand why please see the step by step:
a) Function for (AB)x:
function loopcount1 = FirstAB(A,B,x)
n = size(A)(1);
AB = zeros(n,n);
ABx = zeros(n,1);
loopcount1 = 0;
for i = 1:n
for j = 1:n
AB(i,j) = A(i,:)*B(:,j);
loopcount1 += 1;
end
end
for k = 1:n
ABx(k) = AB(k,:)*x;
loopcount1 += 1;
end
end
b) Function for A(Bx):
function loopcount2 = FirstBx(A,B,x)
n = size(A)(1);
Bx = zeros(n,1);
ABx = zeros(n,1);
loopcount2 = 0;
for i = 1:n
Bx(i) = B(i,:)*x;
loopcount2 += 1;
end
for j = 1:n
ABx(j) = A(j,:)*Bx;
loopcount2 += 1;
end
end
In this exercise we want to use computer and python knowledge to write the code correctly, so it is necessary to add the following to the informed code:
The correct code that corresponds to the question informed is attached in the photo and we can notice that the faster approach is A(Bx).
So knowing that the information given in the text is that;
For n = 100:
(AB)x: 10100 A(Bx): 200For n = 200:
(AB)x: 40200 A(Bx): 400For n = 400:
(AB)x: 160400 A(Bx): 800For n = 800:
(AB)x: 640800 A(Bx): 1600A(Bx) exist faster cause demand hardly any interplay to find a result: for (AB)x you bear (n*n)+n interplay while for A(Bx) you bear n+n, so we have that:
a)Watching the function for (AB)x:
function loopcount1 = FirstAB(A,B,x)
n = size(A)(1);
AB = zeros(n,n);
ABx = zeros(n,1);
loopcount1 = 0;
for i = 1:n
for j = 1:n
AB(i,j) = A(i,:)*B(:,j);
loopcount1 += 1;
end
end
for k = 1:n
ABx(k) = AB(k,:)*x;
loopcount1 += 1;
end
end
b) Watching the function for A(Bx):
function loopcount2 = FirstBx(A,B,x)
n = size(A)(1);
Bx = zeros(n,1);
ABx = zeros(n,1);
loopcount2 = 0;
for i = 1:n
Bx(i) = B(i,:)*x;
loopcount2 += 1;
end
for j = 1:n
ABx(j) = A(j,:)*Bx;
loopcount2 += 1;
end
end
See more about computer at brainly.com/question/950632