C++ Chapters 1-5
Who designed the first programmable computer?
Babbage
Who developed C++?
Bjarne Stroustrup
From which language did C++ directly evolve?
C
The programmer usually enters source code into a computer using:
C) A text editor
One of the biggest differences between C and C++ is
C++ is object-oriented
The acronym CPU stands for
Central Processing Unit.
This step will uncover any syntax errors in your program.
Compiling
Given the following code fragment, what is the output? int x = 5; if( x > 5) cout << "x is bigger than 5. "; cout << "That is all. "; cout << "Goodbye\n";
That is all. Goodbye
What does the term hardware refer to?
The physical components that a computer is made of
What does the following line of code display to the screen? cout << "This is the computer\n programming book\n";
This is the computer programming book
A CPU really only understands instructions that are written in machine language.
True
Which of the following is a valid identifier?
_three
An algorithm is
a finite set of steps to solve a problem
int number; is
a variable declaration.
Executing one or more statements one or more times is known as
iteration.
Given the following code fragment, and an input value of 5, what is the output? int x; if( x < 3) { cout << "small\n"; } else { if( x < 4) { cout << "medium\n"; } else { if( x < 6) { cout << "large\n"; } else { cout << "giant\n"; } } }
large
What is the output of the following code fragment if x is 15? if(x < 20) if(x < 10) cout << "less than 10 "; else cout << "large\n";
large
Which of the following is not a phase of the program-design process?
marketing the final program
What is wrong with the following statement? cout << "Hello to everyone\n;
missing a "
What is wrong with the following statement? cout << "Hello to everyone\n"
missing a semicolon
The output of the compiler is called
object code
Which of the following is not an example of a program bug?
operator error
Which boolean operation is described by the following table? A B Operation True True True True False True False True True False False False
or
The set of instructions that a computer will follow is known as
program
RAM stands for
random access memory
Which of the following is not a valid identifer?
return
If you need to write a do-while loop that will ask the user to enter a number between 2 and 5 inclusive, and will keep asking until the user enters a correct number, what is the loop condition?
(number < 2 || number > 5)
If you want a loop to quit iterating if x < 10 and y > 3, what would be the proper loop condition test?
(x >= 10 || y <= 3)
Which of the following are equivalent to (!(x < 15 && y >= 3))?
(x >= 15 || y < 3)
Which of the following boolean expressions tests to see if x is between 2 and 15 (including 2 and 15)?
(x >= 2 && x <= 15)
Which of the following symbols has the highest precedence?
++
What is the output of the following code fragment? int i = 5; switch(i) { case 0:i = 15;break; case 1:i = 25;break; case 2:i = 35;break; case 3:i = 40; break; default:i = 0; break; } cout << i <<endl;
0
How many times is "Hi" printed to the screen? for(int i = 0;i < 14;i ++ ); cout << "Hi\n";
1
What is the value of x after the following statement? float x; x = 3.0/4.0 + (3 + 2)/5;
1.75
Given the following code fragment, what is the final value of y? int x, y; x = -1; y = 0; while(x <= 3) { y += 2; x += 1; }
10
What is the value of x after the following statements? double x; x = 0; x += 3.0 * 4.0; x -= 2.0;
10.0
What is the value of x after the following code executes? int x = 10; if(x ++ > 10) { x = 13; }
11
What is the value of x after the following code executes? int x = 10; if( ++ x > 10) { x = 13; }
13
What is the output of the following code fragment? int x = 0; { int x = 13; cout << x <<","; } cout << x << endl;
13,0
What is the correct way to write the condition y < x < z?
((y < x) && (x < z))
Given the following code fragment and the input value of 2.0, what output is generated? float tax; float total; cout << "enter the cost of the item\n"; cin >> total; if ( total >= 3.0) { tax = 0.10; cout << total + (total * tax) << endl; } else { cout << total << endl; }
2.0
What is the value of x after the following statements? int x; x = 15 %4;
3
What is the value of x after the following statements? int x; x = 15/4;
3
What is the value of x after the following statements? float x; x = 15/4;
3.0
Another way to write the value 3452211903 is ________
3.452211903e09
What is the value of x after the following statement? float x; x = 3.0/4.0 + 3 + 2/5;
3.75
What is the value of x after the following statements? int x; x = 0; x = x + 30;
30
What is the value of x after the following statements? int x, y, z; y = 10; z = 3; x = 3 + y * z;
33
What is the value of x after the following statements? int x, y, z; y = 10; z = 3; x = y * z + 3;
33
What is the output of the following code? float value; value = 33.5; cout << value << endl;
33.5
Given the following code, what is the final value of i? int i,j; for(i = 0;i < 4;i ++) { for(j = 0;j < 3;j ++ ) { if(i == 2) break; } }
4
Given the following code fragment and the input value of 4.0, what output is generated? float tax; float total; cout << "enter the cost of the item\n"; cin >> total; if ( total >= 3.0) { tax = 0.10; cout << total + (total * tax) << endl; } else { cout << total << endl; }
4.4
Given the following code, what is the final value of i? int i; for(i = 0; i <= 4;i ++ ) { cout << i << endl; }
5
What is the output of the following code fragment? int x = 0; while( x < 5) { x ++; } cout << x << endl;
5
Given the following enumerated data type definition, what is the value of SAT? enum myType{SUN,MON,TUE,WED,THUR,FRI,SAT,NumDays};
6
Given the following enumerated data type definition, what is the value of SAT? enum myType{SUN=3,MON=1,TUE=3,WED,THUR,FRI,SAT,NumDays};
7
A byte consists of how many bits?
8
Given the following code fragment, what is the final value of y? int x, y; x = -1; y = 0; while(x < 3) { y += 2; x += 1; }
8
An example of a secondary storage device is:
A hard disk
When testing a program with a loop, which of the following tests should be done?
A, B, and C
Which of the following data types can be used in a switch controlling expression?
A, B, and D
Who was the programmer for Charles Babbage's analytical engine?
Ada Lovelace
In programming, the terms "line" and "statement" always mean the same thing.
False
What does the following print to the screen? cout << "Hello Students/n";
Hello Students/n
Which of the following is not a good reason for choosing a certain loop control?
If the loop is in a function
What is the output of the following code? cout << "This is a \" << endl;
Nothing, it is a syntax error.
What is the output of the following code fragment? { int x = 13; cout << x <<","; } cout << x << endl;
Nothing, there is a syntax error.
The term OS stands for
Operating System
This is used in a program to mark the beginning or ending of a statement, or separate items in a list.
Punctuation
The statements written by the programmer are called:
Source code
Which of the following are allowed in the third section of the for loop statement?
all of the above
Which of the following data types may be used in a switch statement?
all of the above
A finite sequence of precise instructions that leads to a problem solution is
an algorithm.
#include <iostream> is
an include directive.
cin >> number; is
an input statement.
cout << "How many items would you want?\n"; is
an output statement.
Which boolean operation is described by the following table? A B Operation True True True True False False False True False False False False
and
What is wrong with the following switch statement? int ans; cout << "Type y for yes on n for no\n"; cin >> ans; switch (ans) { case 'y': case 'Y': cout << "You said yes\n"; break; case 'n': case 'N': cout << "You said no\n"; break; default: cout <<"invalid answer\n"; }
ans is a int
Which of the following are valid case statements in a switch?
case 1:
Which of the following statements is NOT legal?
char ch = "cc";
Which of the following lines correctly reads a value from the keyboard and stores it in the variable named myFloat?
cin >> myFloat;
Which of the following is not part of the Software Life Cycle?
data entry
Which loop structure always executes at least once?
do-while
If x is 0, what is the value of (!x == 0)?
false
During which stage does the central processing unit retrieve from main memory the next instruction in the sequence of program instructions?
fetch
What is the value of x after the following statements? int x; x = x + 30;
garbage
The physical machines that make up a computer is called the
hardware
What does the following code print to the screen? cout << "hello";
hello
C++ is an example of a
high-level language
Given the following code fragment, which of the following expressions is always true? int x; cin >> x;
if( x = 1)
What is the final value of x after the following fragment of code executes? int x = 0; do { x++; }while(x > 0);
infinite loop
What is wrong with the following for loop? for(int i = 0;i < 10;i -- ) { cout << "Hello\n"; }
infinite loop
If a programming language does not use short-circuit evaluation, what is the output of the following code fragment if the value of myInt is 0? int other = 3, myInt; if(myInt != 0 && other % myInt != 0) cout << "other is odd\n"; else cout << "other is even\n";
run-time error, no output
C++ statements end with a
semicolon
Which of the following is a valid identifier?
three_com
Software engineering is a field that encompasses designing, writing, testing, debugging, documenting, modifying, and maintaining computer programs.
true
What is the value of the following expression? (true && (4/3 || !(6)))
true
What is the output of the following code? float value; value = 33.5; cout << "value" << endl;
value
A memory address is
where a variable is stored.
Given the following code fragment, and an input value of 0, what is the output that is generated? int x; cout << "Enter a value\n"; cin >> x; if(x = 0) { cout << "x is zero\n"; } else { cout << "x is not zero\n"; }
x is not zero.