0% found this document useful (0 votes)
4 views1 page

SH 2

Uploaded by

mostafaelsehy1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

SH 2

Uploaded by

mostafaelsehy1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Faculty of Engineering Mechatronics and Robotics Eng. Prog.

Assiut University Computer Programming (1)


1st Level - Bylaw 2021 Code: EE 222 (Bylaw 2021)
Academic Year 2024/2025 Sheet 2
Assiut University 1st Semester Faculty of Engineering Decisions Assiut University Faculty of Engineering

1) What output will be produced by the following code, when embedded in a complete program?
int x=3;
cout << "Start\n";
if (x<=3)
if (x!=0)
cout << x++ << endl;
else
cout << x-- << endl;
cout << "End\n";
cout << "Start again\n";
if (x>3)
if (x!=0)
cout << x+3 << endl;
else
cout << x-2 << endl;
cout << "End again\n";

2) Write an if..else statement that outputs the word High if the value of the variable score is greater
than 100 and Low if the value of score is at most 100. The variable score is of type int.
3) Suppose savings and expenses are variables of type double that have been given values. Write an
if..else statement that outputs the word Solvent, decreases the value of savings by the value of
expenses, and sets the value of expenses to 0, if savings is at least as large as expenses. However,
if savings is less than expenses, the if..else statement simply outputs the word Bankrupt and
does not change the value of any variables.
4) Write an if..else statement that outputs the word Passed if the value of the variable exam is
greater than or equal to 60 and the value of the variable programs done is greater than or equal
to 10. Otherwise, the if..else statement outputs the word Failed. The variables exam and
programs done are both of type int.
5) Write a C++ program that allows the user to enter three numbers of type int and outputs the
maximum of these numbers.
6) Create the equivalent of a four-function calculator. The program should ask the user to enter two
numbers of type float and an operator. It should then carry out the specified arithmetical operation:
adding, subtracting, multiplying, or dividing the two numbers. Use a switch statement to select the
operation. Finally, display the result.
A sample interaction with the program might look like this:
Enter first number, operator, second number: 10 / 3
Answer = 3.333333

Dr. Abdelrahman Morsi

You might also like