Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Programming Lab 1 C++ Basics

Task 1
Write a program named triangle.cpp to input the base b and height h of a triangle, and
output its area.
Notes:
It is useful to draw the problem on paper (Figure 1), and draw a flow chart to help guide
the development of your program (Figure 2). Also take care to declare your variables with
the appropriate type.
start
area A = b h / 2

height, h

Input triangle base


and height
integers
Input b, h

base, b
Figure 1

A=bh/2

the area is , A
Check that your program runs correctly.
For example input the values 1.1 and 10.0;
the output should be the area is 5.5
Figure 2

end

Task 2
Write a program named circle.cpp to input the radius r of a circle and output the
circumference and area of the circle. Before writing the C++ source code, draw a
diagram of the problem and a flow chart of the solution to help you develop the program.

Task 3
Write a program that inputs the name of a student and three exam scores.The program
should then calculate a total score and a grade and output the results to the screen.Before
writing the C++ source code, draw a diagram of the problem and a flow chart of the
solution to help you develop the program.

You might also like