25
CS 141 Computer Programming 1 Branching Statements

CS 141 Computer Programming 1 Branching Statements

Embed Size (px)

DESCRIPTION

3 Answer Question #1 a. If x

Citation preview

Page 1: CS 141 Computer Programming 1 Branching Statements

CS 141Computer

Programming 1

Branching Statements

Page 2: CS 141 Computer 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;

Page 3: CS 141 Computer Programming 1 Branching Statements

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

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

5

Question #2Question

Page 6: CS 141 Computer Programming 1 Branching Statements

6

Question #2Question Assuming x=5 and y=8, the following

output is produced.

Page 7: CS 141 Computer Programming 1 Branching Statements

7

Question #2Answer

Page 8: CS 141 Computer Programming 1 Branching Statements

8

Question #2Question Assuming x=5 and y=7, the following

output is produced.

Page 9: CS 141 Computer Programming 1 Branching Statements

9

Question #2Answer

Page 10: CS 141 Computer Programming 1 Branching Statements

10

Problems

Page 11: CS 141 Computer Programming 1 Branching Statements

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

12

Problem #1Answer

Page 13: CS 141 Computer Programming 1 Branching Statements

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

14

Problem #2Answer

Page 15: CS 141 Computer Programming 1 Branching Statements

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

16

Problem #3Question

Page 17: CS 141 Computer Programming 1 Branching Statements

17

Problem #3Answer

Page 18: CS 141 Computer Programming 1 Branching Statements

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

19Problem #4Answer

Page 20: CS 141 Computer Programming 1 Branching Statements

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

21

Problem #5

Answer

Page 22: CS 141 Computer Programming 1 Branching Statements

22Problem #5output

Page 23: CS 141 Computer Programming 1 Branching Statements

Hadeel Al-Ateeq

23

EVALUATION!!

Page 24: CS 141 Computer Programming 1 Branching Statements

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

25

Problem #1Answer