lab 3: area under a lineEN47/COMP9, Fall 2009 the problemThe goal of this lab is to write a program that computes the area under a number of line segments, keeping track of the average of the areas computed so far. The area under a line segment is really just the area of the trapezoid formed by the projection of the line segment onto the x-axis (as shown in Tuesday's lecture). This assignment emphasizes the use of functions to increase the effectiveness of your code. You will write four functions:
The user interaction with your program should look something like below. The underlined text is entered by the user.
This program will compute the areas under several line segments.
Each line segment will be defined by its end points (left to right),
with each end point being specified by its integer coordinates.
This program will also keep track of the running average.
How many lines? 3
When prompted by the line number, please give the x-coordinate and
y-coordinate of each of the two end points separated by a space,
one point per line, left point first.
Line #1?
1 2
3 6
NUM AREA AVG
1 8 8
Line #2?
2 3
4 1
NUM AREA AVG
2 4 6
Line #3?
3 4
4 7
NUM AREA AVG
3 5.5 5.83333
the algorithmHere is one possible approach to this problem. You are welcome to use this as a guide in developing your solution.
After reading the problem description and sample algorithm, work out your approach on paper first. You are encouraged and expected to collaborate with classmates on this part. the programWhen you are finally ready to start writing code, create a directory for
today's lab ( Feel free to copy your code from the last lab into this directory, if you
think it would be useful to have as a reference. The file Some things to keep in mind:
extra creditWrite an additional function called void
--------------------------------------------------
--------------------------------------------------
Write your code in a new file named provide comp9 lab3ec lines_extra.cpp |