3. Variables
Q) Which of the following is a valid variable name in C++?
a) countCars&Trucks
b) numberFarmersInRegion2
c) 10BiggestProvincesPopulationAverage
d) return
(Demo Copilot answering this questions!)
Q) If there are 5 adults holding a total of 12 babies, which of the following statements best creates a variable which stores how many babies each adult is holding?
a) double numHolding = 12.0 / 5.0;
b) int numHolding = 5 / 12;
c) int numHolding = 12 % 5;
d) int numHolding = 12 / 5;
Q) Given the following variable:
string medicine = "Aspirin";
Which of the following C++ statements prints the character A?
a) println(medicine[0]);
b) println(medicine[0] + 'A');
c) println(medicine[1]);
d) println(medicine.length());
Q) Given the following variable declaration:
int cost = 120;
What statement displays "$ 120CAD"?
Note one space between $ and the number.
a) println("{$:4}CAD", cost);
b) println("$4{}CAD", cost);
c) println("${:4}CAD", cost);
d) println("${4}CAD", cost);
Q) Consider the following C++ statements:
int age;
println("{}", age);
What is the output of this program?
a) 0
b) Either 0 or 1
c) Prints nothing
d) None of the above
Answers
b) numberFarmersInRegion2
d) int numHolding = 12 / 5;
a) println(medicine[0]);
c) println("${:4}CAD", cost);
d) None of the above