Font size
WorksheetsQuiz 2: C++ Basics
Total questions: 11
Worksheet time: 8mins
Given the following string variable declaration and statements:
string title;
int i;
title = "One String";
which of the following is the correct statement that assigns the length of the variable title to the variable i?
i = One String.length();
i = string.length();
i = title.length();
i = length();
Given the following string variable declaration and statements:
string title;
int j;
title = "This is Adam";
cout << title.substr(1,5) << endl;
What is the correct output?
(a)
Write a C++ statement that declares the variable firstInitial to be a character variable.
(a)
Given the following string variable declaration:
string name;
string lastName = "Green";
string firstName = "Cathy";
which of the following statement is the correct statement that assigns Green, Cathy to the variable name.
name = "Green Cathy";
name = lastName +", " + firstName;
name = Green, Cathy;
name = Green + ", " + Cathy;
What is the result of the following expression?
9/8
(a)
What is the result of the following expression?
11%9
(a)
Which of the following is the correct function call to calculate 12^5
power(12,5)
power(5,12)
pow(12,5)
exp(12,5)
Suppose a program contains the following variable declarations:
int test1Score;
int test2Score;
Which of the following input statement is the correct statement to read two input values?
cin << test1Score << test2Score;
cin >> test1Score,test2Score;
cin >> test1Score >> test2Score >> endl;
cin >> test1Score >> test2Score;
Which of the following is an invalid name for an identifier?
7Length
M2
total7
lengthTotal
Write a C++ statement that declares the named constant PI which contains the value 3.14 and is a floating point constant.
(a)
Suppose a program contains the following variable declarations and assignments:
int test1Score = 90;
int test2Score = 80;
int sumOfScores = test1Score + test2Score;
Which of the following output statements will produce the output below (notice that the values stored in the variables have been output):
90 + 80 = 170
cout << test1Score << + << test2Score << = << sumOfScores << endl;
cout << test1Score + test2Score = sumOfScores << endl;
cout << test1Score << " + "<< test2Score <<" = "<< sumOfScores << endl;
cout << "test1Score" <<" + "<<" test2Score "<<" = "<< "sumOfScores" << endl;
