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

CSCE106 Lab Session 3

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

CSCE106 Lab Session 3

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 106/1001 – Fundamentals of Computer Science
Lab Session 3 Arithmetic Expressions & Operations

Objectives:

- To become more familiar with the algorithmic method of problem solving.


- To become more familiar with using Flow Chart to represent solution for a problem.
- To understand how to write assignment statements to change the values of variables.
- To learn how C++ evaluates arithmetic expressions and how to write them.
- To learn how to use the standard mathematical library <cmath>.
- To understand the differences between syntax errors, run-time errors, and logic errors and how to
avoid them and to correct them.

Problems:
Draw a Flow Chart and Write a C++ program to solve each of the following problems:

1. Given a, b, and c, compute and display R1 and R2 (rounded to the nearest hundredth) according to
the following formulas:

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


𝑅1 = and 𝑅2 =
2𝑎 2𝑎

(hint: To test your solution; choose input values such that a not equal to zero and b2 – 4ac not
negative)

2. Given a positive number, print its square and square root rounded to the nearest tenth.

3. Given the depth (in kilometers) inside the earth; compute and display the temperature at that depth
in degrees Celsius and Fahrenheit. The relevant formulas are:

Celsius = 10 x (depth) + 20 (Celsius temperature at depth in km)


Fahrenheit = 1.8 x (Celsius) + 32

4. The Pythagorean Theorem states that the sum of the squares of the sides of a right triangle is equal
to the square of the hypotenuse. For example, if two sides of a right triangle have lengths 3 and 4,
then the hypotenuse must have a length of 5. The integers 3, 4, and 5 together form a Pythagorean
triple. There is an infinite number of such triples. Given two positive integers, m and n, where m > n,
a Pythagorean triple can be generated by the following formulas.

Side1 = m2- n2
Side2 = 2mn
Hypotenuse = √𝑺𝒊𝒅𝒆𝟏𝟐 + 𝑺𝒊𝒅𝒆𝟐𝟐

Write a program that reads in values for m and n and prints the values of the Pythagorean triple
generated by the formulas above.

Instructions:

- The TA solves problem 1 (20 minutes)


- The TA asks students to solve and submit in-Lab problem 2 (40 minutes)
- The TA asks students to solve the other problems and submit within three working days.

You might also like