Compsci Midterm Chapter 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

. Which of the following is a compiler directive:

#include <iostream>

What is the value of the following arithmetic expression if the variables have these values? a b c 7 3 10 a + b % c

10

What is the value of the following arithmetic expression if the variables have these values: p s x 5 20 6 p + 3 * x - s

3

10. What is the escape sequence for a linefeed?

Answer: '\n'

17. What is the result of the following arithmetic expression? 7 - 2 * (4 + 1)

Answer: -3

1. What symbol indicates that the following line is a comment?

Answer: // (or /*)

Write the following number in normal decimal notation: 734E-4

Answer: 0.0734

14. What is the output of the following code segment if the data entered are 3, 2 and 4? int x, y, z; cout << "Enter three numbers: "; cin >> x >> y >> z; y = x + z; x = z + 1; cout << x << " " << y<< " " << z;

Answer: 5 7 4

16. What is the result of the following arithmetic expression? 5 + 7/3

Answer: 7

6. What is an identifier?

Answer: A name for the data elements used in a program.

11. What is the following kind of statement called? int counter;

Answer: A variable declaration.

13. What is a prompt?

Answer: An output statement that informs the user what to enter.

2. What are the two kinds of statements inside a function?

Answer: Declaration statements and executable statements

5. What is the name for a word that has a specific meaning in C++?

Answer: Reserved word (or keyword)

15. Why do programmers use comments?

Answer: To help others read and understand the program.

18. Write the following statement in C++: a = 2bc^3

Answer: a = 2 * b * c * c * c

7. What would be the best choice for the data type for a person's middle initial?

Answer: char

4. What C++ word is used to read information in from the keyboard?

Answer: cin

12. If the variables name and color contain these values: name color "Elmo" "red" write a statement using these variables that will output: Elmo, the puppet, is red!

Answer: cout << name << ", the puppet, is " << color << "!";

8. What would be the best choice for the data type for the distance between two houses?

Answer: float (or double or long double)

19. Write the following statement in C++: x= (3y)/(5-z)

Answer: x = (3 * y)/(5 - z) OR x = 3 * y / (5 - z)

T/F: >> is used for output.

False

T/F: A C++ statement cannot extend over more than one line.

False

T/F: All data types take up the same amount of storage.

False

T/F: In C++ addition is always evaluated before subtraction.

False

T/F: It is best to use very short identifiers.

False

T/F: The computer will carry out the instructions that follow the symbol //

False

T/F: The following is an example of a declaration statement: cout << "Enter a number: ";

False

T/F: There is no limit on the size of the numbers that can be stored in the int data type.

False

3. What does the following statement do? cout << "This is good.";

It displays the words This is good on the screen

T/F: 76.45e-2 is a valid value for a float data type.

True

T/F: A program must have a main function.

True

T/F: An identifier must start with a letter or an underscore.

True

T/F: In the statement: cout << "Hello!" "Hello!" is called a string literal.

True

T/F: It is good program style to put spaces between words and symbols.

True

T/F: The value of 3/7 is 0.

True

T/F: There are only two possible values for the bool data type.

True

Which of the following could be used as an identifier?

first_name

What would be the best choice for the data type for a person's take home pay?

float

main is a:

function

Which of the following is not a valid identifier?

help!

What would be the best choice for the data type for the number of students in a class?

int

Which of the following statements is correct?

int day, night;

Which of the following is not a C++ reserved word?

number

Which of the following would be the best choice for a pay rate of a student?

pay_rate

What would be the best choice of data type for a person's address?

string

What kind of error is the following: float height = 6.0,

syntax

iostream is part of:

the C++ standard library

Which of the following lines must end with a semicolon (;)?

using namespace std


Set pelajaran terkait

Chapter 11.6 Cyclical Unemployment

View Set

Content Area IX, RHIT Exam: Health Information Privacy and Security

View Set

EPHE 487: Strength & Power Training to Improve Sport (Part 1)

View Set

220-1101 & 220-1102 Quiz Q&A part 1

View Set

Quiz - What is an Operating System

View Set

Practice Questions - Ch 22, 23 ,25

View Set

bio test 3 chapter 13 connect questions

View Set