C++ Midterm

Only available on StudyMode
  • Download(s) : 78
  • Published : May 12, 2013
Open Document
Text Preview
Question 1

Which one of the following operators computes the remainder of an integer division? Answer /
%
\
!
.2 points
Question 2

Which one of the following is defined as a sequence of characters? Answer String
Constant
Integer
Variable
.2 points
Question 3

Which one of the following variables is assigned with valid literals? Answer int salary = 0; salary = 5000.50;
unsigned short salary1 = 0; salary1 = 1E6;
double salary2 = 0; salary2 = 2.96E-2;
unsigned long salary3 = 0; salary3 = 1E-6;
.2 points
Question 4

What is the value inside the "value" variable at the end of the given code snippet? #include <iostream>
using namespace std;
int main()
{
int value = 3;
value = value - 2 * value;
value++;
return 0;
}
Answer -2
0
2
4
.2 points
Question 5

What is the output of the following code snippet?
#include <iostream>
using namespace std;
int main()
{
int value = 3;
value++;
cout << value << endl;
return 0;
}
Answer 2
3
4
No output due to syntax error
.2 points
Question 6

Which of the following options is valid with reference to the code snippet? #include <iostream>
using namespace std;
int main()
{
double d = 45.326;
double r = d % 9.0;
cout << r;
return 0;
}
Answer The value inside the variable r will be 0.326
The value inside the variable r will be 5.036
Variable r has to be defined as an integer as the % operator always returns an integer The assignment statement for variable r is wrong, as the % operator expects integer values as operands .2 points

Question 7

Assuming that the user inputs a value of 25 for the price and 10 for the discount rate in the following code snippet, what is the output? int main()
{
cout << "Enter the price: ";
double price;
cin >> price;
cout << "Enter the discount rate: ";
double discount;
cin >> discount;
cout << "The new price is ";
cout << price - price * (discount / 100.0) << endl; return 0;
}
Answer The new price is 25
The new price is 15
The new price is 22.5
The new price is 20.0
.2 points
Question 8

Which of the following statements are valid about strings?
I. An empty string literal is represented as "".
II. A string stored in a string variable can be changed.
III. String variables are initialized automatically.
IV. A string variable can contain numbers and special characters. Answer Only II and III are valid.
Only III and IV are valid.
Only I and III are valid.
All four statements are valid.
.2 points
Question 9

Which of the following statements places input into the variable "value"? Answer value >> cin;
cin >> value;
value << cin;
cin << value;
.2 points
Question 10

What is the result of the following statement?
string s = "New" + " " + "Jersey";
Answer The string s has the following value: "New Jersey" The statement results in an error because the + operator can be used only with numbers. The statement results in an error because the + operation cannot be performed on string literals. The string s has the following value: "NewJersey"

.2 points
Question 11

Which of the following statements is correct about constants? Answer Constants are written using capital letters because the compiler ignores the constants declared in small letters. The data stored inside a const variable can be changed using an assignment statement. You can make a variable constant by using the constant keyword while declaring the variable. Constant variables make a code snippet more readable and easy to maintain. .2 points

Question 12

What is the output of the following code snippet?
#include <iostream>
using namespace std;
int main()
{
int value =...
tracking img