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

CSCE106 Lab Session 5

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)
9 views1 page

CSCE106 Lab Session 5

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

The American University in Cairo

Computer Science & Engineering Department


CSCE 1001 – Fundamentals of Computer Science
Lab Session 5 Programming of Two-way Selections

Objectives:

- To become familiar with the control structures: sequence and selection.


- To learn how to compare numbers, characters, and strings.
- To learn how to use the relational and logical operators to write expressions that are type bool.
- To learn how to write two-way selection statements.
- To learn how to implement decisions in algorithms using if statement.

Problems:
Write a C++ program or each of the following problems:

1. Draw a Flow chart and write a program in C++ that reads a positive integer number to notify the
user with a message whether the integer number Even or Odd.

2. Draw a Flow chart and write a program in C++ that reads a real number to notify the user with
a message whether the real number Positive, Zero, or Negative.

3. Draw a Flow chart and write a C++ program to solve the quadratic equation ax2 + bx + c = 0
where coefficient a is not equal to 0. The equation has two real roots if its discriminator d = b2
– 4ac is greater or equal to zero. The program gets the three coefficients a, b, and c, computes
and displays the two real roots (if any). It first gets and tests a value for the coefficient a. if this
value is zero, the program displays an error message and terminates, otherwise it proceeds to
get a value for the coefficient b and a value for the coefficient c. Next it computes and tests the
discriminator d = b2 – 4ac. If the discriminator d is negative, the program displays an error
message “No Real Roots!!” and terminates, otherwise it proceeds to compute and display the two
real roots R1 and R2 according to the following formulas:

−𝑏+√𝑏2 −4𝑎𝑐 −𝑏−√𝑏2 −4𝑎𝑐


𝑅1 = and 𝑅2 =
2𝑎 2𝑎

Instructions:

- The TA solves problems 1 (20 minutes)


- The TA asks students to solve and submit in-Lab problem 2 (30 minutes)
- The TA asks students to solve problem 3 and submit in the next Lab session.

You might also like