Professional Documents
Culture Documents
sum_of_credits _type_of_car
while SECTION_6
bingo-square 3_4_87
initial tree final_#
sum 2nd_total
secondsum long
TOTAL-PAY column 1
total_pay abcde3456
if switch
num1 number_two?
12. Identify either the following C++ statement is valid or invalid
1
13. Determine the output of the following C++ Program
main()
char name[20];
cout<<“Enter a name…”;
cin>>name;
2 float
3 double
4 char
2
}
3. Write C++ Program to display the following output
I Love ETHIOPIA!
4. Write C++ program to display the following output using char data type and character strings:
A) C D E F
C) P R O G R A M
5. The following C++ program has its own errors and violates some rules of C++
programming. Determine the errors of the program and rewrite the program to correct the
errors.
main ( ) {
answer=a+b
answer=a-b
cin<<"\n"<<"Answer="<<"a-b="<<answer;
answer=a*b;
cout<<"\n"<<"Answer="<<"a*b="<<answer;
6. What is the output of the following two C++ program? Write the output these two
program inside the box below and indicate that why the output of these two program is
different each other?.
3
Output of program one
#include<iostream.h>
7. Determine the following variables named are valid or invalid and reason out why the
variable named are invalid or valid? (4 point).
2 % deduction
3 10number
4 switch
charmiddle_initial, union_code;
intnum_dependents;
doublegross_pay, net_pay;
Integer num_dependents;
4
char ‘a’,
9. Observe the following program and determine its output.
#include<iostream.h>
main()
{ Output
int x;
x=65;
cout<< x<<endl;
x= 90;
cout<<endl<<x;
}
#include<iostream.h>
int main()
{ // shows the difference between m++ and ++m:
intm,n;
m = 44;
n= ++m; // the pre-increment operator is applied to m
cout<< "m="<<m<<",n="<<n<<endl;
m = 44;
n= m++; // the post-increment operator is applied to m
cout<< "m="<<m<<",n="<<n<<endl;
}
12. Write C++ program to display the following output. Use assignment operator to write
your program?
5
The sum of C=a+b is 120
13. Write algorithm expression or pseudo code program and C++ program for the following
mathematical expression.
x+ y x− y
A) – B) x=√ a2 +b 2
z z−x
p−q
C) + m*n D) F= (9/5 * C) +32
r−s
if----else if ladder
2
3 switch
6
6. Write C++ program to determine whether the number is positive or not?
7. Write C++ program to check either a given number is odd or even using if-else statement
8. Write C++ program to display the following output using if-else statement.
i=3, j=10
i is not greater than 4
k set equal to i
9. Write C++ program that performs the following input and output operation .
Input Output
A Excellent
B Very Good
C Satisfactory
D Not Satisfactory
F Failure
otherwise Invalid Input
10. Write C++ program to display a letter grade when users enters different range of marks. Use
the following input and output information for your work.
Input Output
(marks>=90) and (marks<=100) A
(marks>=70) and (marks<90) B
(marks>=55)and (marks<70) C
(marks>=35)and (marks<55) D
(marks>=1) and (marks<35) F
otherwise I
11. Refer Question no. 10. Write the above program again using switch statement and test the
output of the program. Rewrite this program again assuming that the program accepts input
of upper and lower case letters and display the same result when accepts both upper and
lower case letters as an input?
12. Write C++ program using if-else-if or switch statement to calculate Income Tax, pension and
net payment of an employees. The program is expected to accept salary of an employee as
input and displays income tax, pension, total deduction and net payment of a salary as output.
Use 6% of basic salary to compute pension and use the following information for tax
competition.
Salary Tax
<=150 0
150-650 10%
650-1400 15%
1400-2350 20%
2350-3550 25%
3550-5000 30%
>5000 35%
7
14. Write the syntax for the control structure of, FOR-----LOOP, While----Loop and do---
while Loop statements
4 for----Loop
5 while----Loop
6 do----while Loop
16. Write C++ program using for_loop to determine sum and average of the first n positive
numbers, assuming that the program accepts input from the user?
17. Write C++ program using for loop to print “Welcome to C++ Programming Course”
statement ten(10) times
18. Determine the output of the following simple C++ program
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
int main() { Output
clrscr ();
for (int x=1; x <= 6; x++){
for (int y=1; y <= 6; y++)
if (y > x) {
break;
8
}
else {
cout<<setw(4) << x*y;
}
cout<<endl;
}
return 0;
}
19. What is the output of the following simple C++ program?
#include<iostream.h>
#include<conio.h>
void main() {
clrscr(); Output
for(int i=0;i<=4;i++) {
for(int j=0;j<=4;j++) {
if (i==j)
cout<<'*';
else
cout<<'#';
}
cout<<endl;
}
getch();
}
20. Write C++ program to display the following output using for loop?
21. A certain company plan to give a 40% of bonus to each of its employees at the end of
every year for those who are working more than two years in the company. If an
employee has been working ten or more years of the company, she/he to get an additional
birr 100 in addition to bonus. Analyze and design the algorithm of this problem and write
C++ program to calculate (compute) a bonus of an employee
22. Write a program to display the following shapes
a) **** b) * c) ****
**** ** ***
**** *** **
**** *
d) * e) *
*** **
***** ***
******* ****
23. Write C++ program to count the number down starting from 8 using while loop.
Assuming that users enter the number 8 while running the program?
24. Write a program to calculate sum of the first 10 natural numbers using while loop
9
25. Write C++ Program to display the following output?
28. Write C++ program to display (prints) the following output using do----while loop?
10
UNIT FOUR: - FUNCTIONS
1. Define function and describe why we use function to write a real world program
2. Identify the two categories of functions in C++ and explain with examples
3. Write C++ program to display or print the following output
4. Write the syntax to define user defined function. And explain what each part of the
functions clearly
5. Determine the output of the following C++ program
//Program to define a function by the name addition.
#include<iostream.h>
#include<conio.h>
int addition (int a, int b){
int r;
r= a+b;
return (r);
}
int main (){
clrscr();
int z;
z= addition(5,3);
cout<<"The result is:"<<z;
return 0;
}
6. Define a function by the name skipthree(), to display “Title Line 1” and “Title Line 2”
respectively by skipping three lines between these two outputs when the skipthree()
function is called?
7. Write the syntax used for function prototype declaration in C++ programming language
and explain the difference with function definition and describe the reason why we use
function prototype while you are writing a program?
8. Define a function that calculates the Area of a Circle and Volume of a Box by
considering the necessary variables used to perform area of a circle and volume of a box.
9. Define a function that prints your first and last name in a separate line but a function
prints the name after one blank line.
10. Determine the output of the following C++ program?
// FunctionFactorial
#include <iostream.h>
11
int Factorial(int M);
int main() {
cin>> number;
result = Factorial(number);
//Output result
return 0;
int Factorial(int M) {
int factorial=1;
factorial = factorial*i;
11. Identify the syntax errors you observed for the following C++ program and write your
answer inside the box provided below
12
#include <iostream.h>
float Convert();
int main()
{
cout<< "Please enter the temperature in Fahrenheit: ";
cin>>TempFer;
TempCel = Convert(TempFer);
cout<< "\n The temperature in Celsius: "<<TempCel<<endl;
return 0;
}
float (float TempFer) Syntax Errors
{
TempCel = ((TempFer - 32) * 5) / 9;
returnTempCel;
}
12. The following C++ program has syntax errors and violates some rules of C++
programming. Determine the errors of the program and rewrite the program to correct the
errors
Syntax Errors
#include <iostream.h>
#include <conio.h>
void myFunction()
int x = 5, y = 7;
int main() {
cout << "x from main: " << x << "\n";
cout << "y from main: " << y << "\n\n";
cout << "Back from myFunction!\n\n";
cout << "x from main: " << x << "\n";
cout << "y from main: "
return 0;
}
void myFunction() //Function Definition
{
int y = 10;
13
cout << "x from myFunction: " << x << "\n";
cout << "y from myFunction: " << y << "\n\n";
13. What is the output of the following two C++ program? Write the output of the program
inside the box below and indicate that what is the implementation of the program?
#include <iostream.h>
#include <conio.h>
voidmyFunc();
int main()
{
Output
int x = 5;
cout<< "\n In main x is: " << x;
myFunc();
cout<< "\n Back in main, x is: " << x;
return 0;
}
voidmyFunc() {
int x = 8;
cout<< "\n In myFunc, local x: " << x <<endl;
{
cout<< "\n In block in myFunc, x is: " << x;
int x = 9;
cout<< "\n Very local x: " << x;
}
cout<< "\n Out of block, in myFunc, x: " << x <<endl;
}
14. Determine the output of the following C++ program
#include<iostream.h>
#include<conio.h> Output
void duplicate(int &a, int &b, int &c);
int main() {
clrscr();
int x=2, y=5, z=10;
duplicate(x, y, z);
cout<<"x= "<<x<<", y="<<y<<" , z= "<<z;
return 0;
}
void duplicate(int &a, int &b, int &c) {
a*=3;
b*=3;
c*=3;
}
14
15. Write the difference between local and global variables and show the difference using
examples
16. Explain the difference between argument passed by value and argument passed by
references and show the difference using examples
17. Write C++ program to calculate volume of the box to implement argument passed by
value when a function is called by defining the necessary function
18. Write C++ program to perform multiplication and division of two numbers by defining
your own function to implement local and global variables and also use variables visible
to only within the block.
15