[go: up one dir, main page]

0% found this document useful (0 votes)
3 views5 pages

EEE2109 FinalExam Spring2020

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

Date of Examination: 08/06/2021

AHSANULLAH UNIVERSITY OF SCIENCE AND TECHNOLOGY


Department: Electrical and Electronic Engineering
Program: Bachelor of Science in Electrical and Electronic Engineering
Semester Final Examination: Spring 2020
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


PART A

There are 04 (four) Questions. Answer any 03 (three).

Question 1. [Marks: 10]

a) Write and use a C++ function that takes a number and changes the digit in such a [5]
way that, each pair of the number will be swapped. Consider the pairing from the
right side. If the number of digits is odd then keep the left-most digits as it is. [PO 2]

Sample output:

Input =123456 Output = 214365


Input = 1237896 Output =1328769

b) Write and apply a C++ function that will take an integer number from the user and [5]
find the maximum and minimum digit within that number. Afterward, it will find the
difference between maximum and minimum within that same number. [PO 2]

Sample output:

Input: 1235698
Difference: 9-1=8

Question 2. [Marks: 10]

a) Write and use a C++ function that will take two dates and find the difference between [5]
them. Then decides whether there is a difference of one month or not. As input, you
take the parameter as day and month of two different dates. Jan, March, May, July, [PO 2]
August, October, December consist of 31 days; whereas the rest of the months have
30 days. For simplicity, consider February month having 28 days.

b) Write and apply a C++ function that will find out the number of unique numbers [5]
within an array of numbers. The numbers will be given by the user.
[PO 2]
Sample output:

Input: 31, 58, 85, 98, 89, 89, 89, 74


Amount of Unique Numbers: 6

Page 1 of 5
Question 3. [Marks: 10]

a) Write and apply a C++ program that will count the number of vowels in a string that [5]
will be given by the user. Consider both uppercase and lowercase letters.
[PO 2]
Sample output:
Input: Bangladesh is a riverine country.
Output: A/a = 3, E/e = 3 , I/i = 3, O/o = 1, U/u = 1
b) Write and apply a C++ program that will create a new array of the size of an existing [5]
array. This half will be created by taking the average of pairs of numbers. Consider
int as data type. [PO 2]

Sample output:

Input Array: 7, 8, 9, 4, 5, 6, 1, 2, 3, 0, 45
Output Array: 7, 6, 5, 1, 1, 22
Calculation: (7+8)/2 = 7, (0+45)/2

If the numbers of array is odd, then keep the last element as it is.

Question 4. [Marks: 10]

a) Create a class named Instructor. It contains a first and last name and an office [5]
number, and its only constructor requires all three as arguments.
[PO 2]
Create a class named Classroom. It contains a building and a room number, and its
only constructor requires both as arguments.
Create a class named CollegeCourse. This class contains an Instructor, a
Classroom, and a number of credits. Its constructor requires a first and last name of
an instructor, the instructor’s office number, a Classroom building and room number,
and a number of credits.
Each of these classes contains a function that displays an object’s values.
Write and apply a C++ program that instantiates as many CollegeCourse objects
as the user wishes and displays their values.

b) Create a class named ConeIceCream with fields for flavor, number of scoops, type [5]
of cone, and price. Unless arguments are supplied, flavor defaults to “Vanilla”, the
[PO 2]
number of scoops defaults to 1, and cone type defaults to “Sugar”. The constructor
calculates the price based on 75 cents per scoop, with an additional 40 cents for a
waffle cone.
ConeType with extra cents is added: Cake (20), Waffle (40), Sugar (0), Pretzel (30),
WaffleBowls (20), TwinCones (25), KidCones (15) and ChocolateDipped (50).
IceCreamType with extra cents per scoop: Chocolate (10), Vanilla (0), Strawberry
(0), Coffee (15), Pistachio (15)and Mango (0).
Apply a vector containing object of class ConeIceCream. Each object will be

Page 2 of 5
created with the necessary parameters given by user as ConeType and
IceCreamType. If no parameters is given, then default will be applied.

The user can order as much as he/she wishes. After that the cash memo will be shown
with the item description and total price.

PART B
The answer script (one single pdf file) of this part (Part B) must be uploaded at designated location in
the provided google form link available in the google classroom.

There are 04 (four) Questions. Answer any 03 (three).

Question 5. [Marks: 10]

Implement a class named Fan to represent a fan. The class contains: [10]

 Three constants named SLOW, MEDIUM, and FAST with values 1, 2, and 3 to [PO 2]
denote the fan speed.
 A private int data field named speed that specifies the speed of the fan (default
SLOW).
 A private boolean data field named on that specifies whether the fan is on
(default false).
 A private double data field named radius that specifies the radius of the fan
(default 5).
 A string data field named color that specifies the color of the fan (default blue).
 The accessor and mutator methods for all four data fields.
 A no-argument constructor that creates a default fan.
 A method named toString() that returns a string description for the fan. If
the fan is on, the method returns the fan speed, color, and radius in one combined
string. If the fan is not on, the method returns fan color and radius along with
the string “fan is off” in one combined string.

Write and apply a C++ program that creates two Fan objects. Assign maximum speed,
radius 10, color yellow, and turn it on to the first object. Assign medium speed, radius
5, color blue, and turn it off to the second object. Display the objects by invoking their
toString method.

Question 6. [Marks: 10]

Write and apply a C++ program to calculate some features of a geometric object named [10]
line. Line is a connection between two Cartesian points in a Cartesian plane. For better
management of the program make a class named as Line with the following method: [PO 2]

 Line(x1, y1, x2, y2) ⇾ Default and parameterized Constructor

Page 3 of 5
 getSlope() ⇾ this will find the slope of the line, if the line is parallel to Y
axis, then the error occurs, check that special case.
 GetInsectofYaxis() ⇾ this will find the intersection of the line.
 CheckColinear(x,y) ⇾ this will check whether the point (x, y) exists in the
line.

Question 7. [Marks: 10]

Write and apply a C++ program that will simulate the Sundarban forest. Consider the [10]
forest as a grid of 100 x 100 positions. The four direction of movement is Up, Down,
Left, Right in the grid. There are five animals and there moving behavior is as follows: [PO 1]

 Tiger ⇾ jumps 5 steps to any direction and move 2 steps to clockwise direction.
 Deer ⇾ jumps 6 steps to any direction and move 3 steps to anticlockwise
direction.
 Monkey ⇾ jumps 7 steps to any direction and move 1 step to clockwise
direction.
 Cat ⇾ jumps 2 steps to any direction and move 1 step to anticlockwise direction.
 Snake ⇾ slither 2 steps to any direction and move 1 steps to clockwise direction
again slither 2 steps to previous direction and move 1 steps to anticlockwise
direction

At the initial stage of the simulation, generate animals of each category [1-100]
randomly with the random position. Then they will move continuously at each round.
Both of the animals will die if they fall in same grid point. The round will go on till all
animal die or at least only one remains.

Since, the generation of animal numbers is random, total number of animals can be odd.
In that case, one will remain at the end. If the number is even then all will be dead after
several simulations. If any animal tries to cross the border of grid point then, its motion
will be reversed so that it will again traverse in the forest.

Question 8. [Marks: 10]


Write and apply a C++ program that will simulate a scenario of Car-Ride sharing [10]
system.
[PO 1]
There are 20 stoppages which are 1km apart. In each stoppage, the number of cars [1-
5] is randomly generated at the initial stage. The direction of a car can be in both ways.
As an example, if the car starts from station 6 it can move in any direction either 5 or 7.
But, afterward, it will continue in the same direction until the end-station i.e. 1 or 20.
Then it will change the direction and continue moving. The number of passengers [10-
30] will be generated randomly with their choice at every simulation.

At a time, a maximum of 3 passengers can ride in a car. If the direction of the car agrees
with the passenger's choice of destination then the passenger will ride based on available
sit.

Page 4 of 5
The fare of ride per kilo is 10 Taka. At the end of the simulation generate a report of
each car with corresponding earned revenue.

To implement this simulation you need to create several classes such as Car,
Passenger, Station, etc.
Sample output:

Car No. Revenue.


1 650
2 900
3 780
… …
80 540

Page 5 of 5

You might also like