WORKSHEET ON FLOW OF PROGRAM(1)
WORKSHEET ON FLOW OF PROGRAM(1)
WORKSHEET ON FLOW OF PROGRAM(1)
if----else if ladder
2
3 switch
1
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. Draw a flow chart for the if----else if statement in C++ programming language
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
12. Write C++ program to calculate VAT(15%), Service Charge(5%), Total Cost before VAT
and Service Charge and Total Cash after VAT and Service Charge are added for the
service that any business provided to the Customer. Suppose the Program is expected to
accept Quantity and Unit Price as an input for the item or the service provided. And the
Program is expected to display quantity, unit price, VAT, Service Charge, Total Cost
before VAT and Service Charge and Total Cash as an output.
13. Use if-else statement and write C++ program to check either a number inputted by the
user is odd or even.
14. Use nested ifs---else statement to avoid dangling problem and write C++ program to
identify either the number x inputted by the user is “x is below average” if(x<=5) or “x is
above average” if(x<=10) or “Invalid Input” if the x value inputted by the user is >10.
15. Use if-else-if statement and write C++ program to calculate Income Tax, pension, total deduction
and net payment of an employees. The program is expected to accept basic salary, allowance and
credit association as an input and displays basic salary, allowance, credit association, growth
salary, pension, income tax, total deduction and net payment that an employee earn as an output.
Hint:
Use 7% of Basic salary to compute pension.
2
Employee earn additional money as allowance monthly (not fixed allowance).
Employee must pay money monthly as a credit association (different values)
GrowthSalary=(BasicSalary +allowance).
TotalDeduction=(Pension+ IncomeTax + CreditAssociation)
NetPay=(GrowthSalary-TotalDeduction)
Use the following input and output information for tax competition or calculation.
Salary Tax Deduction
0-600 0 00
601-1650 10% 60.00
1651-3200 15% 142.50
3201-5250 20% 302.50
5251-7800 25% 565.00
7801-10,900 30% 955.00
>10,900 35% 1500.00
16. Write the syntax for the control structure of, FOR-----LOOP, While----Loop and
do---while Loop statements
1 for----Loop
2 while----Loop
3 do----while Loop
3
17. Determine the output of the following C++ program
#include<iostream>
using namespace std;
int main ()
Output
{
for(int n=10;n>0;n--)
{
cout<<n<<“,”;
}
cout<<“FIRE!”;
return 0;
}
18. 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?
19. Write C++ program using for loop to print “Welcome to C++ Programming Course”
statement ten(10) times
20. Determine the output of the following simple C++ program
#include<iostream>
#include<iomanip>
using namespace std;
Output
int main() {
for (int x=1; x <= 6; x++){
for (int y=1; y <= 6; y++)
if (y > x) {
break;
}
else {
cout<<setw(4) << x*y;
}
cout<<endl;
}
return 0;
}
4
21. What is the output of the following simple C++ program?
#include<iostream>
Using namespace std;
void main() {
Output
for(int i=0;i<=4;i++) {
for(int j=0;j<=4;j++) {
if (i==j)
cout<<'*';
else
cout<<'#';
}
cout<<endl;
}
getch();
}
22. Write C++ program to display the following output using for loop?
23. 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
24. Write a program to display the following shapes
a) **** b) * c) ****
**** ** ***
**** *** **
**** *
d) * e) *
*** **
5
***** ***
******* ****
25. 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?
26. Write a program to calculate sum of the first 10 natural numbers using while loop
int main()
{
6
intn,i=0;
cout<< "Enter a positive integer: ";
cin>> n;
long sum=0;
do {
sum += i++;
}
while (i <= n);
cout<< "The sum of the first " << n << " integers is " << sum;
}
30. Write separate C++ program to calculate the reverse of sum of 10 even and odd
numbers using for statement.
31. Use for----loop and write C++ program to calculate square and sum of square of n
natural number inputted by the user.
32. . Use break statement in nested for loop and write C++ program to print the following
shapes. The program skips from the inner for loop if(j==i) is evaluated to true by
printing the statement next to the inner for loop and its iteration to the outer for loop is
continue.
33. Use continue statement in nested for loop and write C++ program to print the
following shapes. The program continue its iteration of the inner for loop as if(j>i) is
evaluated to true but executes the statement in the inner for loop if(j>i) is evaluated to
true and the outer for loop continue its iteration after the test condition of the inner for
loop is evaluated to true and prints cout statement (new line) inside the outer for loop.
7
34. Use continue and break statement together in a single for loop and write C++ program
to print a number 1 2 3 4 6 7 8 and 9. The program skips to print 5 when continue
statement is executed but its next iteration continues but terminate the loop when
break statement is executed when the control variable counts reach to 10.
35. Write C++ program allows the user to enter a maximum number of digits and then,
the program will sum up the odd and even numbers from 1 to entered digits using a
while loop and display its sum of both odd and even number.
36. Write C++ program to find and display the sum of an positive integer inputted by the
user and if the user inputs negative numbers, execute break and ends the loop and the
negative number inputted is not added to sum
37. Use do ---while loop and write C++ program to count and display positive integer
inputted by the user and terminate the loop when n number inputted by the user is
n<20.
38. Write C++ program allows the user to enter a maximum number of digits and then,
the program will sum up the odd and even numbers from 1 to entered digits using do
while loop and display its sum of both odd and even number
39. Read the following C++ program carefully, identify the syntax errors you observed
and write the syntax errors you observed inside the box below (5 pts)
#include<iostream>
using namespace std;
int main() {
<<"Enter days 1-7:"; Syntax Errors
cin>>day;
switch (day){
case 1 :
cout<< "Sunday";
break;
case 2 :
cout<< "Monday";
break;
case 3
cout<< "Tuesday";
break;
//===========================
8
case 4:
cout<< "Wednesday";
break
case 5 :
cout<< "Thursday";
break;
case 6 :
cout<< "Friday";
break;
case 7 :
cout<< "Saturday";
cout<< "Not an allowable day number";
return 0;
}//End of main ()
40. Identify the syntax errors you observed for the following C++ program and write your
answer inside the box provided below (5 pts).
#include<iostream>
int main (){
cout<<"Enter stud marks:"<<"\n";
cin>>; Syntax Errors
Test the condition or expression
if((mark>=90)&&(mark<=100)) {
grade='A';
<<"Grade="<<grade<<"\n";
}
else if((mark>=70)&&(mark<90)) {
grade='B';
cout<<"Grade="<<grade<<"\n";
}
if((mark>=60)&&(mark<70)) {
grade='C';
cout<<"Grade="<<grade<<"\n";
}
else if((mark>=40)&&(mark<50)) {
9
grade='D';
cout<<"Grade="<<grade<<"\n";
}
else if((mark>=10)&&(mark<40)) {
='F';
cout<<"Grade="<<grade<<"\n";
}
else{
cout<<"Invalid Input";
} //End of else
return 0;
}//End of main()
41. Read the following C++ code carefully and determine the output you expect from this
program and the output of the program inside the box below (5 Pts).
#include<iostream>
using namespace std;
int main (){
cout<<"**********BEGINING OF C++ PROGRAM**************"<<endl;
cout<<"WELCOME TO DEPARTMENT OF COMPUTER SCIENCE"<<endl;
cout<<"FOR THE COURSEFUNDAMENTALS OF PROGRAMMING"<<endl<<endl;
//Declaration of Variables
int x, y, s, p, d, mo;
x=100;
y=20;
cout<<"=====ARITHEMETIC OPERATOR====="<<endl;
cout<<"s="<<(x+y)<<endl;
cout<<"P="<<(x*y)<<endl;
cout<<"d="<<(x/y)<<endl;
cout<<"mo="<<(x%y)<<endl<<endl;
cout<<"====INCREMENT AND DECREMENT OPERATOR===="<<endl;
//Declaration of variable
int m, n;
m=111;
10
n=++m;//Pre-increment Operator
cout<<"m="<<m<<" "<<"n="<<n<<endl;
n=m++;//Post-increment ia applied in m;
cout<<"m="<<m<<" "<<"n="<<n<<endl;
n=--m;//Pre-decrement
cout<<"m="<<m<<" "<<"n="<<n<<endl;
n=m--;//Post decrement is applied on m
cout<<"m="<<m<<" "<<"n="<<n<<endl; Output
int k=20;
k=++k +10;
cout<<"K="<<k<<endl;
k=5;
//int a;
k=k++ +10;//Post Increment
cout<<"K="<<k<<endl;
k=5;
k=--k +10;//Pre-decrement
cout<<"K="<<k<<endl;
k=5;
k=k-- +10;//Post-decrement opera
cout<<"K="<<k<<endl<<endl;
cout<<"===OTHER OPERATORS========"<<endl;
int z=20;
z=(z+20);
cout<<"Z="<<z<<endl;
z=(z-20);
cout<<"Z="<<z<<endl;
z=(z*20);
cout<<"Z="<<z<<endl;
z=(z%2);
cout<<"Z="<<z<<endl;
z=(z/10);
cout<<"Z="<<z<<endl<<endl;
cout<<"========END OF PROGRAM======="<<endl;
11
return 0;
}
42. Read the following C++ code carefully and determine the output you expect from this
program and the output of the program inside the box below (5 Pts).
#include<iostream>
using namespace std;
int main (){
//Declaration of variables
int code=100;
//Test the condition
if(code==100){
cout<<"======BEGINING OF A PROGRAM====="<<endl;
cout<<"======START TO WRITE A PROGRAM==="<<endl;
cout<<"======USING C++ LANGUAGE========="<<endl<<endl;
}
Output
int n=200;
if(n>1){
cout<<"n is Positive"<<endl;
}
else if(n<1){
cout<<"n is negative"<<endl;
}
else{
cout<<"n is Zero"<<endl;
}
//Declaration of variables
const int MAX=200;
int x, y, z;
x=(MAX*2);
cout<<"MAX="<<MAX<<endl;
cout<<"x="<<x<<endl;
y=(x+MAX);
cout<<"y="<<y<<endl;
z=MAX;
12
cout<<"MAX="<<MAX<<endl;
cout<<"z="<<z<<endl<<endl;
cout<<"===========GOOD LUCK!=============="<<endl;
return 0;
}
43. Use switch Statement and write C++ program that performs the following input and
output operation. The program is expected to accept both small and English Capital
letter grade as an input and displays its corresponding output. Use logical Or (||)
operator to combine both small and capital letters as an input (5 Pts).
Input Output
A, a Excellent
B, b Very Good
C, c Satisfactory
D, d Not Satisfactory
F, f Failure
Otherwise Invalid Input
13