EEE2109 Final Spr2021
EEE2109 Final Spr2021
Type
1 Write a program that repeatedly asks the user to enter two money amounts Iteration
expressed in old-style British currency: pounds, shillings, and pence. and
The program should then add the two amounts and display the answer, Condition
again in pounds, shillings, and pence.
Use a do-while loop that asks the user whether the program should be
terminated.
To add the two amounts, you’ll need to carry 1 shilling when the pence
value is greater than 11, and carry 1 pound when there are more than 19
shillings. Typical interaction might be
2 Write a program to compute sin(x) for given x. The user should supply x and a
positive integer n. We compute the sine of x using the series and the computation
should use all terms in the series up through the term involving x
sin x = x - x3/3! + x5/5! - x7/7!+x9/9! .........
5 Create a structure named Employee. Include data fields to hold the Employee’s ID Structure
number, first name, last name, and hourly pay rate. Create an array of five employee
instances. Prompt the user to enter data for each Employee. Do not allow duplicate
ID numbers to be entered. Then prompt the user to choose whether to search for an
Employee by (1) ID number, (2) last name, or (3) hourly pay. After the user chooses
the field on which to search, prompt the user for the search value. Display an error
message if there is no Employee with matching criteria, otherwise display all the
data for every matching Employee (more than one Employee might have the same
last name or pay rate).
6 Imagine a tollbooth at a bridge. Cars passing by the booth are expected to pay a 50 Basic Class
cent toll. Mostly they do, but sometimes a car goes by without paying. The tollbooth
keeps track of the number of cars that have gone by, and of the total amount of
money collected.
Model this tollbooth with a class called TollBooth.
The two data items are a type unsigned int to hold the total number of cars,
and a type double to hold the total amount of money collected.
A constructor initializes both of these to 0.
A member function called payingCar() increments the car total and adds
0.50 to the cash total.
Another function, called nopayCar(), increments the car total but adds
nothing to the cash total.
Finally, a member function called display() displays the two totals.
Make appropriate member functions const.
Include a main() program to test this class. This program should allow the user to
push one key to count a paying car, and another to count a nonpaying car. Pushing
the Esc key should cause the program to print out the total cars and total cash and
then exit. [const int ESC=27; if ((ch = cin.get()) != ESC)]
7 Create a class Polar that represents the points on the plain as polar Operator
coordinates (radius and angle). Overloading
Create an overloaded +operator for addition of two Polar
quantities. “Adding” two points on the plain can be accomplished by adding
their X coordinates and then adding their Y coordinates. This gives the X
and Y coordinates of the “answer.” Thus you’ll need to convert two sets of
polar coordinates to rectangular coordinates, add them, then convert the
resulting rectangular representation back to polar. Note: (X,Y)
rad=√(X2+Y2) and angle= atan(Y/X), X= rad*cos(angle), Y=
rad*sin(angle).
8 Imagine a publishing company that markets both book and mp3 versions of its Inheritance
works. Create a class Publication that stores the title (a string) and price
(type float) of a Publication. From this class derive two classes: Book, which
adds a page_count (type int), and Mp3, which adds a playing_time in
minutes (type float). Each of these three classes should have a getdata()
function to get its data from the user at the keyboard, and a putdata() function to
display its data.
Write a main() program to test the Book and Mp3 classes by creating instances
of them, asking the user to fill in data with getdata(), and then displaying the
data with putdata().