Post on 18-Jan-2018
description
CS 141Computer
Programming 1
Branching Statements
2
Question #1
Question
Find the errors and correct them..
a. If x<0 cout<<x<<"is negative";
b. If(x=2) y++;else; if(x=3) y+=2;
3
AnswerQuestion #1
a. If x<0 cout<<x<<"is negative";
b. If(x=2) y++;else; if(x=3) y+=2;
if(x==2)y++; else if (x==3)y+=2;
If (x<0) cout<<x<<"is negative";
4
Question #2
Question
Modify the following code to produce the output shown.
Use proper indentation techniques.
You must not make any changes other than inserting
braces
5
Question #2Question
6
Question #2Question Assuming x=5 and y=8, the following
output is produced.
7
Question #2Answer
8
Question #2Question Assuming x=5 and y=7, the following
output is produced.
9
Question #2Answer
10
Problems
11
Problem #1
Question
Write a program that asks the user to input his age and outputs whether he is older, younger or the same age as you.
12
Problem #1Answer
13
Problem #2
Question
Write a program that determines the maximum and the minimum of three
numbers.
14
Problem #2Answer
15
Problem #3Question
Write a program that checks the order of a medicine from a pharmacy store. The program should read the order quantity and the medicine quantity in the store.
The messages that will be displayed in that cases are“Your order is accepted” OR “You cannot order more than
16 item”
When the order quantity is more than the store quantity, your program should display the message “No enough quantity”.When the order quantity is less than the store quantity, you have to check that the order quantity must be not more than 16 except there is more than 40 items in the store.
16
Problem #3Question
17
Problem #3Answer
18
Problem #4Question
Write a program that calculates the areas of different shapes according to a character input signifying the shape:
The necessary input should be read after the character. Hint: use case
c for circle.r for rectangle.s for square.t for triangle.
19Problem #4Answer
20
Problem #5Question
Write a program to simulate a simple calculator. It should ask the user to enter a first number, the operation(as a character), and the second number. Addition, Subtraction, Division, Multiplication, and Modulus are the basic operations that should be implemented. (HINT: use case).
Enter a mathematical Expression:2+4The result is:2+4=6
21
Problem #5
Answer
22Problem #5output
Hadeel Al-Ateeq
23
EVALUATION!!
24
Problem #1 Question
Write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered by the user. A triangle is valid if the sum of all the three angles is equal to 180 degrees.
25
Problem #1Answer