cs 141 computer programming 1 branching statements
DESCRIPTION
3 Answer Question #1 a. If xTRANSCRIPT
![Page 1: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/1.jpg)
CS 141Computer
Programming 1
Branching Statements
![Page 2: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/2.jpg)
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;
![Page 3: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/3.jpg)
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";
![Page 4: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/4.jpg)
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
![Page 5: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/5.jpg)
5
Question #2Question
![Page 6: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/6.jpg)
6
Question #2Question Assuming x=5 and y=8, the following
output is produced.
![Page 7: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/7.jpg)
7
Question #2Answer
![Page 8: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/8.jpg)
8
Question #2Question Assuming x=5 and y=7, the following
output is produced.
![Page 9: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/9.jpg)
9
Question #2Answer
![Page 10: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/10.jpg)
10
Problems
![Page 11: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/11.jpg)
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.
![Page 12: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/12.jpg)
12
Problem #1Answer
![Page 13: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/13.jpg)
13
Problem #2
Question
Write a program that determines the maximum and the minimum of three
numbers.
![Page 14: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/14.jpg)
14
Problem #2Answer
![Page 15: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/15.jpg)
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.
![Page 16: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/16.jpg)
16
Problem #3Question
![Page 17: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/17.jpg)
17
Problem #3Answer
![Page 18: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/18.jpg)
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.
![Page 19: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/19.jpg)
19Problem #4Answer
![Page 20: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/20.jpg)
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
![Page 21: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/21.jpg)
21
Problem #5
Answer
![Page 22: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/22.jpg)
22Problem #5output
![Page 23: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/23.jpg)
Hadeel Al-Ateeq
23
EVALUATION!!
![Page 24: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/24.jpg)
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.
![Page 25: CS 141 Computer Programming 1 Branching Statements](https://reader035.vdocuments.mx/reader035/viewer/2022062311/5a4d1b4b7f8b9ab0599a57d1/html5/thumbnails/25.jpg)
25
Problem #1Answer