Professional Documents
Culture Documents
Binary
Octal
HexaDecimal
111001.011010
35.25
5A.F5B
Compiled by Mulugeta H
Page 1
Page 2
21. Specify the possible data types you have to use with suitable declarations for variables to
represent the following items? Be sure to choose meaningful identifiers.
a. the number of students in a class
b. the grade (a letter) attained by a student in the class
c. the average mark in a class
d. the distance between two points
e. the population of a city
f. for a program to add two numbers?
g. the weight of a postage stamp
h. the registration letter of a car
22. Specify how many bytes are occupied by the following data types in a 32-bit system:
a. Type int
b. Type long double
c. Type float
d. Type long
23. Write a constant declaration that declares constants to hold the number of days in a week
and the number of weeks in a year. In a separate constant statement declare a constant pi as
3.1415927
24. If a is 5, b is 10, c is 15 and d is 0 what are the truth values of the following expressions?
(a) c == a+b || c == d
(b) a != 7 && c >= 6 || a+c <= 20
(c) !(b <= 12) && a % 2 == 0
(d) !(a >5) || c < a+b
Compiled by Mulugeta H
Page 3
Compiled by Mulugeta H
Page 4
Compiled by Mulugeta H
Page 5
Except that it should be 20 lines high, instead of the 5 lines shown here. One way to
do this is to nest two inner loops, one to print spaces and one to print Xs, inside an
outer loop that steps down the screen from line to line.
8. A series of positive numbers are to be entered from the keyboard with the end of the series
indicated by a negative number. The computer should output the sum of the positive
numbers. Write an algorithm for this task. Use a while type of loop with the condition
`number just entered is positive'. Think carefully about what initializations are required
before entering the while loop. Do a desk check of your algorithm with a small data set; say
3 positive numbers then a negative number. What would your algorithm do if the user
entered a negative number first? Is what your algorithm would do in this circumstance
sensible?
9. Using functions write a C++ programming code in your text editor to solve the problems
related the following activities;
a) Ask the user to enter one natural number N then your program should display the
factorial of the entered number in the form N!=N*(N-1)*(N-2)**3*2*1.For
example if the users input number is 5 then the output should be
5!=5*4*3*2*1=120
NB: ask your user to try for other number (if hi/she press some specific key) before
exiting the screen otherwise exit the program.
b) Ask request to the user that how many numbers he/she wants to enter (N). Once
the user specify the size (N numbers) input these numbers from keyboard sort
them both in ascending and descending order. Example for 5 numbers entered from
keyboard (0 7 -2 12 -11) the output should be
The numbers are before sorting are: 0 7 -2 12 -11
The numbers sorting in ascending order: -11 -2 0 7 12
The numbers sorting in descending order: 12 7 0 -2 -11
c) Ask request to the user that how many numbers he/she wants to enter (N). Once
the user specify the size (N numbers) input these numbers from keyboard find the
smallest and largest numbers and their occurrences and display the information to
the screen. Example for 10 input numbers(let 1 5 4 98 23 -2 3 45 -2 8) our out
should be ;
The 10 input numbers are: 1 5 4 98 23 -2 3 45 -2 8
The smallest number is -2 and it occurs 2 times
The largest number is 98 and it occurs 1 times
Compiled by Mulugeta H
Page 6
g) Ask your user to enter one number (N)and then the second number (P) for power
from keyboard then compute NP in the form NP = N*N*N*N P times=?
Example: for request first enter the number > 3
Now please enter the power >2
The result is: 32 =3*3= 9
NB: ask your user to try for other number (if hi/she press some specific key) before
exiting the screen otherwise exit the program
Compiled by Mulugeta H
Page 7
Compiled by Mulugeta H
Page 8