
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
- Compare the security services provided by a digital signature (DS) with those of a message authentication code (MAC). Assume that Oscar can observe all messages sent between Rina and Naseem. Oscar has no knowledge of any keys but the public one, in the case of DS. State whether DS and MAC protect against each attack and, if they do, how. The value auth(x) is computed with a DS or a MAC algorithm. In each scenario, assume the message M = x#####auth(x). (Message integrity) Rina has the textual data x = “Transfer $1000 to Mark” to send to Naseem. To ensure the integrity of the data, Rina generates auth(x), forms a message M, and then sends M in cleartext to Naseem. Oscar intercepts the message and replaces “Mark” with “Oscar.” Will Naseem detect this in the case of either DS or MAC? If yes, how will Naseem detect it? If not, why? (Replay) Rina has the textual data x = “Transfer $1000 to Mark” to send to Naseem. To ensure the integrity of the data, Rina generates auth(x), forms a message…arrow_forwardI need to resolve the following....You are trying to convince your boss that your company needs to invest in a license for MS-Project (project management software from Microsoft) before beginning a systems project. What arguments would you give her?arrow_forwardWhat are the four types of feasibility? what is the issues addressed by each feasibility component.arrow_forward
- I would like to get ab example of a situation where Agile Methods might be preferable versus the traditional SDLC? What are the characteristics of this situation that give Agile Methods an advantage?arrow_forwardWhat is a functional decomposition diagram? what is a good example of a high level task being broken down into tasks in at least two lower levels (three levels in all).arrow_forwardWhat are the advantages to using a Sytems Analysis and Design model like the SDLC vs. other approaches?arrow_forward
- 3. Problem Description: Define the Circle2D class that contains: Two double data fields named x and y that specify the center of the circle with get methods. • A data field radius with a get method. • A no-arg constructor that creates a default circle with (0, 0) for (x, y) and 1 for radius. • A constructor that creates a circle with the specified x, y, and radius. • A method getArea() that returns the area of the circle. • A method getPerimeter() that returns the perimeter of the circle. • • • A method contains(double x, double y) that returns true if the specified point (x, y) is inside this circle. See Figure (a). A method contains(Circle2D circle) that returns true if the specified circle is inside this circle. See Figure (b). A method overlaps (Circle2D circle) that returns true if the specified circle overlaps with this circle. See the figure below. р O со (a) (b) (c)< Figure (a) A point is inside the circle. (b) A circle is inside another circle. (c) A circle overlaps another…arrow_forward1. Explain in detail with examples each of the following fundamental security design principles: economy of mechanism, fail-safe default, complete mediation, open design, separation of privilege, least privilege, least common mechanism, psychological acceptability, isolation, encapsulation, modularity, layering, and least astonishment.arrow_forwardSecurity in general means the protection of an asset. In the context of computer and network security, explore and explain what assets must be protected within an online university. What the threats are to the security of these assets, and what countermeasures are available to mitigate and protect the organization from such threats. For each of the assets you identify, assign an impact level (low, moderate, or high) for the loss of confidentiality, availability, and integrity. Justify your answers.arrow_forward
- Please include comments and docs comments on the program. The two other classes are Attraction and Entertainment.arrow_forwardObject-Oriented Programming In this separate files. ent, you'll need to build and run a small Zoo in Lennoxville. All classes must be created in Animal (5) First, start by building a class that describes an Animal at a Zoo. It should have one private instance variable for the name of the animal, and one for its hunger status (fed or hungry). Add methods for setting and getting the hunger satus variable, along with a getter for the name. Consider how these should be named for code clarity. For instance, using a method called hungry () to make the animal hungry could be used as a setter for the hunger field. The same logic could be applied to when it's being fed: public void feed () { this.fed = true; Furthermore, the getter for the fed variable could be named is Fed as it is more descriptive about what it answers when compared to get Fed. Keep this technique in mind for future class designs. Zoo (10) Now we have the animals designed and ready for building a little Zoo! Build a class…arrow_forward1.[30 pts] Answer the following questions: a. [10 pts] Write a Boolean equation in sum-of-products canonical form for the truth table shown below: A B C Y 0 0 0 1 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 0 a. [10 pts] Minimize the Boolean equation you obtained in (a). b. [10 pts] Implement, using Logisim, the simplified logic circuit. Include an image of the circuit in your report. 2. [20 pts] Student A B will enjoy his picnic on sunny days that have no ants. He will also enjoy his picnic any day he sees a hummingbird, as well as on days where there are ants and ladybugs. a. Write a Boolean equation for his enjoyment (E) in terms of sun (S), ants (A), hummingbirds (H), and ladybugs (L). b. Implement in Logisim, the logic circuit of E function. Use the Circuit Analysis tool in Logisim to view the expression, include an image of the expression generated by Logisim in your report. 3.[20 pts] Find the minimum equivalent circuit for the one shown below (show your work): DAB C…arrow_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



