worksheet1

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Jimma University

Jimma Institute of Technology


Faculty of Computing and Informatics

Cosc1013: Fundamentals of Programming I - LAB Session

Laboratory Practical (Worksheet 1)


Academic Year: 2023
Year: III Physics Students

1. Write the algorithm description (Pseudo code) and draw a flowchart to find the
following sum.
Sum = 0 + 2 + 4 + 6 + 8 + ……………………..+ 100
2. Design a program that reads three natural numbers and determines the largest of
three natural numbers by following the steps in program development process.
You are expected to plan a solution (design the program) using both:
a. Pseudo code(algorithm description) and
b. Flowchart
3. Declare two constant variables named INCOME_TAX_RATE and
BASE_CHARGE having values 0.12 and 345.00 respectively, do it in a single
declaration?
4. Suppose our program has the following declaration
int u, v, w, x, y, z;
and let us assume that at some point during program execution, the value of
variables are:
u = 10, v = 9, w = 8, x = 5, y = 3, z = 2;
Find the result of the following arithmetic expression. (You should have to show
the precedence of each operator clearly).
( ( ( (u %v) % (y + x) ) / (u – w + y) ) – ( (z * y) % u ) )
5. Suppose we have the following declaration:
int x = 6;
float y;
Cast x into float data type, increment it by 5.0 and assign it to y.
6. Write equivalent C++ program code to the following Arithmetic expressions and
formulas. (Hint use C++ mathematical library functions).
a. (sin x)2 + (cos x)2

b. √(yx– (tan ex))

7. What will be the value of the following logical / Boolean expressions?


a. ( ( 2 % 8 / 5 ) = = ( 7 / 10 % 3 ) ) && ( ( 6 / 3 * 4 % 7) = = (4 – 1 % 2) )
b. 10 + 5 / 8 = =10 % 12 && 3 * 2 / 5 - 1 < = 10 % 12 / 3

1
8. What will be the output of the following C++ program code?
#include<iostream.h>
int main(){
int x,y=5;
do{
x = y--;
cout<<x<<",";
cout<<y<<",";
}while(y>0);
system("PAUSE");
return 0;
}
9. Write a statement to accomplish the following
a) State that a program will calculate the product of three integers.
b) Declare the variables x, y, z and result to be of type int.
c) Prompt the user to enter three integers.
d) Read three integers from the keyboard and store them in variables x, y, z;
e) Compute the product of the three integers contained in variables x, y and
z, and assign the result to the variable result that you declared before.
f) Print “The product is” followed by the value of the variable result.
10. Write a program that asks the user to enter two numbers, obtains the two numbers
from the user, and it prints the quotient of the two numbers, if the denominator
number is zero, it will displays undefined message?
11. Calculate the sum of all odd numbers from 1 to some integer denoted by n by
using
a. The ‘while’ statement(while loop)
b. The ‘do-while’ statement(do loop)
c. The ‘for’ statement (for loop)
12. Write a switch statement that prints “Monday” if a variable choice is ‘M’ or ‘m’,
prints “Tuesday” if choice is ‘T’ or ‘t’, prints “Wednesday” if choice is ‘W’ or
‘w’, prints “Friday” if choice is ‘F’ or ‘f’, and prints “Unknown Response”
otherwise.
13. Convert the above switch statement in to if-else if -else statement that you did
before on question number Twelve (12)?
14. Write a C++ program that displays the following serious of numbers by using
nested for loop.
I) II) III)
12345 54321 543212345
1234 4321 4321234
123 321 32123
12 21 212
1 1 1

You might also like