Sie sind auf Seite 1von 1

Tutorial No: 02

1. Define suitable data type for following statements


I.
To hold student index number (Ex: AS2014234)
II.
To hold student age (Ex: 21)
III.
To hold student G.P.A (Ex: 3.67)
IV.
To hold course grade (Ex: A)
2. Briefly describe naming rules when declaring variables.
3. Convert each of the following mathematical formulas to C++ arithmetic expressions.
4.

What will be the output of the following program segments?


I.

5.

int a, b, s;
a = 5;
b = 4;
s = a + b;
cout << The sum of;
cout << a << and <<b;
cout << is << s << \n;

II.

Ffloat x, y, p;
Xx = 5.31;
Yy = 7.87;
Pp = x * y;
cout << The product of \n << x << and;
cout << y << is\n << p;

Write a complete C++ program that reads two whole numbers into two variables of type int,
and then outputs both the whole number part and the remainder when the first number is
divided by the second.

6. Given the following fragment the purports to convert from degrees Celsius to degrees
Fahrenheit, answer the following questions:
double c = 20;
double f;
f = (9/5) * c + 32.0;
I.
What value is assigned to f?
II.
Explain what is actually happening, and what the programmer likely wanted.
III.
Rewrite the code as the programmer intended.
Department of Statistics and Computer Science
University of Sri Jayewardenepura

Commented [g1]: Havent done strings. Remove this. Add an


example for long.

Das könnte Ihnen auch gefallen