You are on page 1of 1

1. A metric ton is 35,273.92 ounces.

Write a program that will read the weight


of a package of breakfast cereal in ounces and output the weight in metric tons as
well as the number of boxes needed to yield one metric ton of cereal.
2. You sometimes see numeric intervals given as 2 < x < 3. In C++, this interval
does not have the meaning you may expect. Explain and give the correct C++ Boolean
expression that specifies x lies between 2 and 3.
3. Write an if-else statement that outputs the word “High” if the value of the
variable score is greater than 100 and Low if the value of score is at most 100.
The variable score is of type int.
4. Suppose savings and expenses are variables of type double that have been
given values. Write an if-else statement that outputs the word Solvent, decreases
the value of savings by the value of expenses, and sets the value of expenses to
zero provided that savings is at least as large as expenses. If, however, savings
is less than expenses, the if-else statement simply outputs the word Bankrupt and
does not change the value of any variables.
5. What is the output of the following code?
int x = 2;
cout << "Start\n";
if (x <= 3)
if (x != 0)
cout << "Hello from the second if.\n";
else
cout << "Hello from the else.\n";
cout << "End\n";
cout << "Start again\n";
if (x > 3)
if (x != 0)
cout << "Hello from the second if.\n";
else
cout << "Hello from the else.\n";
cout << "End again\n";
6. A program is required which will read in the breadth and height of a
rectangle and which will output the area and the length of the perimeter of the
rectangle. Write an algorithm for this problem.
7. Write a program that takes three numbers as input, arranges them in ascending
order and displays the result. For example if the user inputs three numbers 9, 4, 7
the output should be 4, 7, 9.