Professional Documents
Culture Documents
OOP Lab 2 Section C17
OOP Lab 2 Section C17
Problem 1:
Write a menu driven C++ program using switch statement to create a fraction calculator with
the help of functions’ concept.
1- Create a menu using the switch statement, that will be used to ask user which
function user wants to perform.
2- Provide user, four different options to choose from addition, subtraction,
multiplication and division.
3- Create four functions to perform following fraction operations:
a. Addition
b. Subtraction
c. Multiplication
d. Division
4- Every function is going to take four different parameters:
a. First parameter is going to be first numerator
b. Second parameter is going to be first denominator
c. Third parameter is going to be second numerator
d. Forth parameter is going to be second denominator
5- Following are the formulas for the four automatic operations applied in fractions.
a. Addition: a/b + c/d = (a*d + b*c) / (b*d)
b. Subtraction: a/b - c/d = (a*d - b*c) / (b*d)
c. Multiplication: a/b * c/d = (a*c) / (b*d)
d. Division: a/b / c/d = (a*d) / (b*c)
6- After performing the calculation please return the result and show that to output
screen.
7- Please make sure user should not enter a 0 value for the denominator as the division
by zero results in undefined.
Problem 2:
Write a C++ program, to find the distance between two points using the concept of
functions.
1- Create four different variables to store values for the x1, y1, x2 and y2 co-ordinates.
2- Ask the user to provide values for these co-ordinates.
3- Create a function to calculate the distance, function is going to take the four
parameters for four co-ordinates and after calculating the distance show the result on
the output screen.
4- Following the formulate to calculate the distance between two points.
5- Use the inbuilt library (cmatch) functions sqrt to perform the square root and pow to
get the power.
Problem 3:
Write a C++ program to ask user to provide his/her residential address and then show the
complete address on the output screen using the concept of functions.
1- Create a function with the name getData, in which ask user to provide
a. Name of the person
b. House number
c. Street address
d. Town name
e. City name
f. Postal Code
2- Now after getting the data in getData function, pass this data to another function
showCompleteResidentialAddress, this function is then going to print the complete
address on the output screen.
3- Please make sure, user must not enter empty string for any of the address fields, if
user tries to enter empty string, show a message to enter a valid value for the given
field.
Problem 4:
Write a C++ Program to Store Information of a Book. Please choose at-least 7 different
attributes about the book.
Problem 5:
Write a C++ Program to Store Information of a Student. Create two different functions one
to get student information from user and second function to show information of Student on
the output screen.
----------Good Luck----------