0% found this document useful (0 votes)
21 views3 pages

EEE2109 Final Spr2021

Uploaded by

tanvirm6985
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)
21 views3 pages

EEE2109 Final Spr2021

Uploaded by

tanvirm6985
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/ 3

Date of Examination:

AHSANULLAH UNIVERSITY OF SCIENCE AND TECHNOLOGY


Department: Electrical and Electronic Engineering
Program: Bachelor of Science in Electrical and Electronic Engineering
Semester Final Examination: Spring 2021
Year: 2 Semester: 1
Course Number: EEE 2109
Course Name: Programming Language
Time: 3 (Three) Hours Full Marks: 60

Use separate answer script for each part

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

Enter first amount: £5.10.6


Enter second amount: £3.2.6
Total is £8.13.0
Do you wish to continue (y/n)?

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! .........

3  A matrix is a two-dimensional array. Create a matrix that provides the Matrix


safety feature; that is, it checks to be sure no array index is out of bounds. (Array)
Make the size in the matrix a 10-by-10 array.
 A user prompt should allow the user to specify the actual dimensions of the
matrix (provided they’re less than 10 by 10).
 The user define function that accesses data in the matrix will now need two
index numbers: one for each dimension of the array.
 Here’s what a fragment of a main() program that operates on such a class
might look like:

matrix m1(3, 4); // define a matrix object


int temp = 12345; // define an int value
m1.putel(7, 4, temp);
// insert value of temp into matrix at 7,4
temp = m1.getel(7, 4);
// obtain value from matrix at 7,4
4  Write a function called reversit() that reverses a C-string (an array of String
char). Use a for loop that swaps the first and last characters, then the second
and next-to-last characters, and so on. The string should be passed to
reversit() as an argument.
 Write a program to exercise reversit(). The program should get a
string from the user, call reversit(), and print out the result. Use an
input method that allows embedded blanks.

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().

You might also like