Mark the following statements as true or false.
An output stream is a sequence of characters from a computer to an output device. (1)
To use cin and cout in a
program , the program must include the header file iostream. (1, 2)Suppose pay is a variable of type double. The statement cin >> pay, requires the input of a decimal number. (2)
The statement cin >> length; and length >> cin; are equivalent. (2)
When the statement cin >> numl >> num2; executes, then after inputting a number into the variable numl the program skips all trailing whitespace characters. (2)
To use the predefined function sqrt in a program, the program must include the header file cmath. (3)
The statement cin.get (ch); inputs the next nonwhitespace character into the variable ch. (4)
When the input stream enters the fail state, the program terminates with an error message. (5)
To use the manipulators fixed and showpoint, the program does not require the inclusion of the header file iomanip. (6)
The statement cin >> right; sets the input of only the next variable right-justified. (7)
To input data from a file, the program must include the header file fstream. (10)
a.
An output stream is a stream from a computer to a destination.
An output stream is a sequence of characters from a computer to an output device. Hence, the given statement is “True”.
Explanation of Solution
An output stream is a stream from a computer to a destination, where the destination is an output device such as the computer screen (monitor), file, etc.
b.
To use cin and cout in a program, the program must include the header file iostream. This header file contains the definition of the input and output stream objects, cin and cout.
To use cin and cout in a program, the program must include the header file iostream. Hence, the given statement is “True”.
Explanation of Solution
To use cin and cout in a program, the program must include the header file iostream. This header file contains the definition of the input and output stream objects, cin and cout. So we can use these inbuilt objects provided by the standard header files of C++. To use cin and cout, every C++ program must use the preprocessor directive:
#include <iostream>
c.
The extraction operator >> is binary and thus takes two operands. The left-side operand must be an input stream variable, such as cin and the right-hand operand, a variable.
Suppose pay is a variable of type double, the statement cin >> pay; does not require the input to be only of a decimal number type. Hence, the given statement is “False”.
Explanation of Solution
The statement cin >> pay; can receive input of both integer and decimal types. If the input is of the integer type, it is converted into a decimal type with zero decimal part and then assigned to the pay variable of double type. If the input is decimal type, then the input is received and assigned to the variable without any conversion.
d.
The extraction operator >> is binary and thus takes two operands. The left-side operand must be an input stream variable, such as cin and the right-hand operand, a variable.
The statement cin >> length; and length >> cin; are not equivalent. Hence, the given statement is “False”.
Explanation of Solution
The extraction operator >> is binary and thus takes two operands. The left-side operand must be an input stream variable, such as cin and the right-hand operand, a variable. Since the order of the operands is fixed, the statement length >> cin; is not a valid C++ statement and the order of the operands is incorrect. cin >> length; is a syntactically correct statement.
e.
The extraction operator >> is binary and thus takes two operands. The left-side operand must be an input stream variable, such as cin and the right-hand operand, a variable. A single input statement can read more than one data item by using the operator >> several times. When scanning for the next input, >> skips all whitespace characters. Whitespace characters consist of blanks and non-printable characters, such as tabs and the newline character.
When the statement cin >> num1 >> num2; executes, then after inputting a number into the variable num1 the program skips all trailing whitespace characters. Hence, the given statement is “True”.
Explanation of Solution
A single input statement can read more than one data item by using the operator >> several times. When scanning for the next input, >> skips all whitespace characters. Whitespace characters consist of blanks and non-printable characters, such as tabs and the newline character. Hence, after inputting a number in the variable num1, the program skips all trailing whitespace characters and inputs the next number in the variable num2.
f.
C++ comes with a wealth of functions called predefined functions. These predefined functions are organized as a collection of libraries called header files. A particular header file may contain several functions. To use a particular function, one needs to know the name of the function, the return type and parameters to the function. cmath is one such header file which is part of the C++ system and contains functions such as sqrt, pow, etc.
To use the predefined function sqrt in a program, the program must include the header file cmath. Hence, the given statement is “True”.
Explanation of Solution
Since sqrt function is included as part of the header file cmath, it should be included using the preprocessor directive as below:
#include <cmath>
g.
The variable cin can access the stream function get, which is used to read character data. The get function inputs the very next character, including whitespace characters, from the input stream and stores it in the memory location passed to it as an argument. The syntax for the command is:
cin.get(varChar);
where carChar is a char type variable.
The statement cin.get(ch); can input either the next non-whitespace character or the next whitespace character in the variable ch. Hence, the given statement is “False”.
Explanation of Solution
The statement cin.get(ch); can input either the next non-whitespace character or the next whitespace character in the variable ch. So it is incorrect to say that only the next non-whitespace character is input.
h.
Attempting to read invalid data in a variable causes the input stream to enter the fail state. Once an input failure has occurred, the function clear can be used to restore the input stream to a working state. Once an input stream enters the fail state, all further I/O statements using that stream are ignored and the program continues to execute with whatever values are stored in variables and produces incorrect results.
When the input stream enters the fail state, the program does not terminate with an error message. Hence, the given statement is “False”.
Explanation of Solution
When the input stream enters the fail state, the program does not terminate with an error message, instead all further I/O statements using that stream are ignored and the program continues to execute with whatever values are stored in variables and produces incorrect results.
i.
To output floating-point numbers in a fixed decimal format, the manipulator fixed is used. When the computer is instructed to output the decimal number in a fixed decimal format, the output may not show the decimal point and the decimal part. To force the output to show the decimal point and trailing zeros, the manipulator showpoint is used.
To use the manipulators fixed and showpoint, the program does not require the inclusion of the header file iomanip. Hence, the given statement is “True”.
Explanation of Solution
To use the manipulators fixed and showpoint, the program does not require the inclusion of the header file iomanip. The iomanip header file is however required to use the manipulators set precision, setfill and setw.
j.
To right-justify the output and the manipulator right, the syntax to set the manipulator right is:
ostreamVar << right;
where ostreamVar is an output variable such as cout.
The statement cin >> right; sets the input of all the variables henceforth right-justified. Hence, the given statement is “False”.
Explanation of Solution
The statement cin >> right; sets the input of all the variables henceforth right-justified and not just the next variable. In order to change the setting, it has to be done explicitly using the syntax as follows:
cout.unsetf(ios::right);
k.
For file I/O, the statement #include <fstream> is to be used to include the header file fstream in the program. Also, variables of type ifstream for file input and of type ofstream for file output should be declared. open statements are then used to open input and output files. The header file fstream contains the definitions of ifstream and ofstream.
To input data from a file, the program must include the header file fstream. Hence, the given statement is “True”.
Explanation of Solution
To input data from a file, the program must include the header file fstream which contains the definition of ifstream and ofstream types. Variables of these types are then declared and used to open files for input and output.
Want to see more full solutions like this?
Chapter 3 Solutions
C++ Programming: From Problem Analysis to Program Design
- 1. Complete the routing table for R2 as per the table shown below when implementing RIP routing Protocol? (14 marks) 195.2.4.0 130.10.0.0 195.2.4.1 m1 130.10.0.2 mo R2 R3 130.10.0.1 195.2.5.1 195.2.5.0 195.2.5.2 195.2.6.1 195.2.6.0 m2 130.11.0.0 130.11.0.2 205.5.5.0 205.5.5.1 R4 130.11.0.1 205.5.6.1 205.5.6.0arrow_forwardAnalyze the charts and introduce each charts by describing each. Identify the patterns in the given data. And determine how are the data points are related. Refer to the raw data (table):arrow_forward3A) Generate a hash table for the following values: 11, 9, 6, 28, 19, 46, 34, 14. Assume the table size is 9 and the primary hash function is h(k) = k % 9. i) Hash table using quadratic probing ii) Hash table with a secondary hash function of h2(k) = 7- (k%7) 3B) Demonstrate with a suitable example, any three possible ways to remove the keys and yet maintaining the properties of a B-Tree. 3C) Differentiate between Greedy and Dynamic Programming.arrow_forward
- What are the charts (with their title name) that could be use to illustrate the data? Please give picture examples.arrow_forwardA design for a synchronous divide-by-six Gray counter isrequired which meets the following specification.The system has 2 inputs, PAUSE and SKIP:• While PAUSE and SKIP are not asserted (logic 0), thecounter continually loops through the Gray coded binarysequence {0002, 0012, 0112, 0102, 1102, 1112}.• If PAUSE is asserted (logic 1) when the counter is onnumber 0102, it stays here until it becomes unasserted (atwhich point it continues counting as before).• While SKIP is asserted (logic 1), the counter misses outodd numbers, i.e. it loops through the sequence {0002,0112, 1102}.The system has 4 outputs, BIT3, BIT2, BIT1, and WAITING:• BIT3, BIT2, and BIT1 are unconditional outputsrepresenting the current number, where BIT3 is the mostsignificant-bit and BIT1 is the least-significant-bit.• An active-high conditional output WAITING should beasserted (logic 1) whenever the counter is paused at 0102.(a) Draw an ASM chart for a synchronous system to providethe functionality described above.(b)…arrow_forwardS A B D FL I C J E G H T K L Figure 1: Search tree 1. Uninformed search algorithms (6 points) Based on the search tree in Figure 1, provide the trace to find a path from the start node S to a goal node T for the following three uninformed search algorithms. When a node has multiple successors, use the left-to-right convention. a. Depth first search (2 points) b. Breadth first search (2 points) c. Iterative deepening search (2 points)arrow_forward
- We want to get an idea of how many tickets we have and what our issues are. Print the ticket ID number, ticket description, ticket priority, ticket status, and, if the information is available, employee first name assigned to it for our records. Include all tickets regardless of whether they have been assigned to an employee or not. Sort it alphabetically by ticket status, and then numerically by ticket ID, with the lower ticket IDs on top.arrow_forwardFigure 1 shows an ASM chart representing the operation of a controller. Stateassignments for each state are indicated in square brackets for [Q1, Q0].Using the ASM design technique:(a) Produce a State Transition Table from the ASM Chart in Figure 1.(b) Extract minimised Boolean expressions from your state transition tablefor Q1, Q0, DISPATCH and REJECT. Show all your working.(c) Implement your design using AND/OR/NOT logic gates and risingedgetriggered D-type Flip Flops. Your answer should include a circuitschematic.arrow_forwardA controller is required for a home security alarm, providing the followingfunctionality. The alarm does nothing while it is disarmed (‘switched off’). It canbe armed (‘switched on’) by entering a PIN on the keypad. Whenever thealarm is armed, it can be disarmed by entering the PIN on the keypad.If motion is detected while the alarm is armed, the siren should sound AND asingle SMS message sent to the police to notify them. Further motion shouldnot result in more messages being sent. If the siren is sounding, it can only bedisarmed by entering the PIN on the keypad. Once the alarm is disarmed, asingle SMS should be sent to the police to notify them.Two (active-high) input signals are provided to the controller:MOTION: Asserted while motion is detected inside the home.PIN: Asserted for a single clock cycle whenever the PIN has beencorrectly entered on the keypad.The controller must provide two (active-high) outputs:SIREN: The siren sounds while this output is asserted.POLICE: One SMS…arrow_forward
- 4G+ Vo) % 1.1. LTE1 : Q B NIS شوز طبي ۱:۱۷ کا A X حاز هذا على إعجاب Mohamed Bashar. MEDICAL SHOE شوز طبي ممول . اقوى عرض بالعراق بلاش سعر القطعة ١٥ الف سعر القطعتين ٢٥ الف سعر 3 قطع ٣٥ الف القياسات : 40-41-42-43-44- افحص وكدر ثم ادفع خدمة التوصيل 5 الف لكافة محافظات العراق ופרסם BNI SH ופרסם DON JU WORLD DON JU MORISO DON JU إرسال رسالة III Messenger التواصل مع شوز طبي تعليق باسم اواب حمیدarrow_forwardA manipulator is identified by the following table of parameters and variables:a. Obtain the transformation matrices between adjacent coordinate frames and calculate the global transformation matrix.arrow_forwardWhich tool takes the 2 provided input datasets and produces the following output dataset? Input 1: Record First Last Output: 1 Enzo Cordova Record 2 Maggie Freelund Input 2: Record Frist Last MI ? First 1 Enzo Last MI Cordova [Null] 2 Maggie Freelund [Null] 3 Jason Wayans T. 4 Ruby Landry [Null] 1 Jason Wayans T. 5 Devonn Unger [Null] 2 Ruby Landry [Null] 6 Bradley Freelund [Null] 3 Devonn Unger [Null] 4 Bradley Freelund [Null] OA. Append Fields O B. Union OC. Join OD. Find Replace Clear selectionarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning