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
- digital image processingWhat is the number of dark small square in set A after (A θ X)? a) 22b) 24c) 20d) Otherarrow_forwarddigital image processing By finding the necessary coding for the symbols according to the given symbol probability table, calculate code symbol for "001000011010000010110011". Note that in the initial state, the probability of 0,55 is expressed as 0 and the probability of 0,45 is 1.What is the first symbol of the result from the Huffman coding?A)=a6 B)=a3 C)=a1 D)=a2arrow_forwarddigital image processing(Using the transformation function shown in the figure below, apply contrast stretching for following input image A[2*2]. Where L=256.Find the output image B [2*2].)create output ımage C accordıng to the last three (3) least signifcantbits by bit plane slicing on image Aplease step by explaningarrow_forward
- Given a 16-bit word of 1011011001101001 read from memory, and assuming the original check bits were 10101, apply the Hamming error correction code to: a)Find the new check b)Calculate the syndrome c)Determine whether there is an error in the received word, and if so, correct it to find the original word stored in memoryarrow_forwardThis is a question that I have and would like someone who has experiences with scene graphs and entity component systems to answer.For context, I am currently implementing a game engine and currently I am debating on our current design.Our current design is we have a singular game component class that every component inherits from. Where we have components like SpriteRendererComponent, Mehs Component, etc. They inherit from this GameComponent class. The point of this is being able to have O(1) access to the scene to being able to modify components to attach more components with the idea of accessing those components to specific scene objects in a scene.Now, my question is what kinds of caveauts can this cause in terms of cache coherence? I am well aware that yes its O(1) and that is great but cache coherence is going to be really bad, but would like to know more explicit details and real-life examples such as write in RAM examples on how this is bad. A follow-up question that is part…arrow_forwardQ4: Consider the following MAILORDER relational schema describing the data for a mail order company. (Choose five only). PARTS(Pno, Pname, Qoh, Price, Olevel) CUSTOMERS(Cno, Cname, Street, Zip, Phone) EMPLOYEES(Eno, Ename, Zip, Hdate) ZIP CODES(Zip, City) ORDERS(Ono, Cno, Eno, Received, Shipped) ODETAILS(Ono, Pno, Qty) (10 Marks) I want a detailed explanation to understand the mechanism how it is Qoh stands for quantity on hand: the other attribute names are self-explanatory. Specify and execute the following queries using the RA interpreter on the MAILORDER database schema. a. Retrieve the names of parts that cost less than $20.00. b. Retrieve the names and cities of employees who have taken orders for parts costing more than $50.00. c. Retrieve the pairs of customer number values of customers who live in the same ZIP Code. d. Retrieve the names of customers who have ordered parts from employees living in Wichita. e. Retrieve the names of customers who have ordered parts costing less…arrow_forward
- Q4: Consider the following MAILORDER relational schema describing the data for a mail order company. (Choose five only). (10 Marks) PARTS(Pno, Pname, Qoh, Price, Olevel) CUSTOMERS(Cno, Cname, Street, Zip, Phone) EMPLOYEES(Eno, Ename, Zip, Hdate) ZIP CODES(Zip, City) ORDERS(Ono, Cno, Eno, Received, Shipped) ODETAILS(Ono, Pno, Qty) Qoh stands for quantity on hand: the other attribute names are self-explanatory. Specify and execute the following queries using the RA interpreter on the MAILORDER database schema. a. Retrieve the names of parts that cost less than $20.00. b. Retrieve the names and cities of employees who have taken orders for parts costing more than $50.00. c. Retrieve the pairs of customer number values of customers who live in the same ZIP Code. d. Retrieve the names of customers who have ordered parts from employees living in Wichita. e. Retrieve the names of customers who have ordered parts costing less than$20.00. f. Retrieve the names of customers who have not placed…arrow_forwardut da Q4: Consider the LIBRARY relational database schema shown in Figure below a. Edit Author_name to new variable name where previous surname was 'Al - Wazny'. Update book_Authors set Author_name = 'alsaadi' where Author_name = 'Al - Wazny' b. Change data type of Phone to string instead of numbers. عرفنه شنو الحل BOOK Book id Title Publisher_name BOOK AUTHORS Book id Author_name PUBLISHER Name Address Phone e u al b are rage c. Add two Publishers Company existed in UK. insert into publisher(name, address, phone) value('ali','uk',78547889), ('karrar', 'uk', 78547889) d. Remove all books author when author name contains second character 'D' and ending by character 'i'. es inf rmar nce 1 tic عرفته شنو الحل e. Add one book as variables data? عرفته شنو الحلarrow_forwardAdd a timer in the following code. public class GameGUI extends JPanel { private final Labyrinth labyrinth; private final Player player; private final Dragon dragon; private Timer timer; private long elapsedTime; public GameGUI(Labyrinth labyrinth, Player player, Dragon dragon) { this.labyrinth = labyrinth; this.player = player; this.dragon = dragon; String playerName = JOptionPane.showInputDialog("Enter your name:"); player.setName(playerName); elapsedTime = 0; timer = new Timer(1000, e -> { elapsedTime++; repaint(); }); timer.start(); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); int cellSize = Math.min(getWidth() / labyrinth.getSize(), getHeight() / labyrinth.getSize());}arrow_forward
- Change the following code so that when player wins the game, the game continues by creating new GameGUI with the same player. However the player's starting position is same, everything else should be reseted. public static void main(String[] args) { Labyrinth labyrinth = new Labyrinth(10); Player player = new Player(9, 0); Random rand = new Random(); Dragon dragon = new Dragon(rand.nextInt(10), 9); JFrame frame = new JFrame("Labyrinth Game"); GameGUI gui = new GameGUI(labyrinth, player, dragon); frame.setLayout(new BorderLayout()); frame.setSize(600, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(gui, BorderLayout.CENTER); frame.pack(); frame.setResizable(false); frame.setVisible(true); } public class GameGUI extends JPanel { private final Labyrinth labyrinth; private final Player player; private final Dragon dragon; private Timer timer; private long…arrow_forwardCreate a menu item which restarts the game. Also add a timer, which counts the elapsed time since the start of the game level. When the restart is pressed, the restarted game should ask the player' name (in the GameGUI constructor) and set the score of player to 0 (player.setScore(0)), and the timer should restart again. And create a logic so that if the player loses his life (checkGame if the condition is false), then save this number together with his name into two variables. And display two buttons where one quits the game altogether (System.exit(0)) and the other restarts the game. public class GameGUI extends JPanel { private final Labyrinth labyrinth; private final Player player; private final Dragon dragon; private final ImageIcon playerIcon = new ImageIcon("data/images/player.png"); private final ImageIcon dragonIcon = new ImageIcon("data/images/dragon.png"); private final ImageIcon wallIcon = new ImageIcon("data/images/wall.png"); private final ImageIcon…arrow_forwardPlease original work Analyze the complexity issues of processing big data What are five complexities and talk about the reasons they make the implementation complex. Please cite in text references and add weblinksarrow_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 Learning