0% found this document useful (0 votes)
18 views

Lecture 4

The document discusses several programming practice exercises and problems including calculating heat transfer, data type sizes, name and ID output, algebraic expressions, triangle area, sphere volume, elapsed time for a trip, Fahrenheit to Celsius conversion, and swapping variable contents.

Uploaded by

DANIEL WELDAY
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)
18 views

Lecture 4

The document discusses several programming practice exercises and problems including calculating heat transfer, data type sizes, name and ID output, algebraic expressions, triangle area, sphere volume, elapsed time for a trip, Fahrenheit to Celsius conversion, and swapping variable contents.

Uploaded by

DANIEL WELDAY
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/ 13

ASTU

CSE 1061 Fundamentals of Programming

Lecture #4

Spring 2016

Computer Science & Engineering Program


The School of EE & Computing
Adama Science & Technology University
ASTU

• Basic C++ Programming Practice


– Heat Transfer Case Study
– Size of Data Types
– Practice Exercise 1
– Practice Exercise 2
– General Problems(Maths and Physics)

2
Case Study: Heat Transfer ASTU

• In Lecture 1 you developed simple al


gorithm for the heat transfer problem
• Finish the remaining steps
– Coding
– Testing

3
Size of Data Types ASTU

• A unique feature of C++ is that you can


see where and how values are stored
– sizeof() operator provides the number of
bytes used to store values of the data type
named in the parenthesis
– Values returned by sizeof() are compiler
dependent

4
Size of Data Types ASTU

5
Practice Exercise 1 ASTU

• Using cout, write a C++ program that di


splays your name on one line, your id nu
mber on a second line, and your city, sta
te, and phone number on a third line
• Run the program

6
Practice Exercise 2 ASTU

• For the following correct algebraic expre


ssions and corresponding incorrect C++
expressions, find the errors and write co
rrected C++ expressions in one C++ pro
gram
Algebra C++ Expression
(2)(3)+(4)(5) (2)(3)+(4)(5)
6+18/2

4.5/12.2-3.1

4.6(3.0+14.9) 4.6(3.0+14.9)

7
Practice Exercise 2… ASTU

• Write a C++ program that displays the r


esults of the expressions
3.0*5.0,
7.1 * 8.3 - 2.2
3.2 / (6.1 * 5).
• Calculate the value of these expressions
manually to verify that the displayed v
alues are correct.

8
General Problems ASTU

• Design, write, compile, and run a C++ pr


ogram that calculates and displays the a
rea of a triangle, with a base of 1 in and
a height of 1.5 in.

• Test the program with different values

9
General Problems ASTU

• Design, write, compile, and run a C++ pr


ogram to calculate the volume of a sphe
re with a radius, r, of 2 in.
• Test the program with different values

10
General Problems ASTU

• Design, write, compile, and run a C++ pr


ogram to calculate the elapsed time it ta
kes to make a 183.67-mile trip. This is th
e formula for computing elapsed time
elapsed time = total distance / average speed
The average speed during the trip is 58 mph.
• Test it with different average speeds

11
General Problems ASTU

• Write a program that accepts the value o


f temperature in Fahrenheit and converts
to its Celsius equivalent. (hint C=F-32*5/
9)
• Test it with different temperatures

12
General Problems ASTU

• Swap the contents of two variables usin


g a third variable.
• Swap the contents of two variables usin
g a third variable.

13

You might also like