Vous êtes sur la page 1sur 2

LAB 6 DS & OOP

Instructor: Mujtaba Saeed

Task 1: (Task 3 of lab 5)


Create a class Grade with public data members char letter and float score & member function
void calcGrade() , void setScore(float) & float getScore(). calcGrade() will calculate grade
according to the score.
Write Test class which is derived from Grade class using public class access, with private data
members int numQuestions, float pointsEach, int numMissed, float pointsObtEach and public
member function float calcScore() which returns score according to above data members.
Write another member function void calcGrade() which will calculate grade according to the
score calculated by calcScore().
calcGrade() must have different definitions for both of classes(its function over riding)
Also you have to make default constructors for both of the classes printing a line like Test
constructor created or Grade constructor created.
In the main function you have to make one object of each class. And call setScore(), getScore()
& calcGrade() for Grade class. Call calcScore(), getScore() and calcGrade() for the Test class.
Then set the score of test class by calling setScore() and again call getScore() and calcGrade().

Task 2:
For task 1 call calcGrade() function using this operator in getScore() function to show static
binding i.e. now whether getScore() is called with the instance of Grade or Test it will calculate
grade for Grade classs score.

Task 3:
For task 1 now use virtual function calcGrade() and then call in getScore() function to show
dynamic binding. i.e. now when getScore() is called with the instance of Grade it will calculate
grade for Grade classs score. And when called with Test it will calculate grade according to Test
class Score.
Task 4:
Define a class person with data members name, address, contact #, height_in_meters,
weight_in_kg. Define a member function Calc_BMI() which will calculate BMI according to
following formula and display these results.
BMI= weight_in_kg/ height_in_meters^2

Below 18.5 Underweight


18.524.9 Normal
25.029.9 Overweight
30.0 and Above Obese
Also define setdata() function to take all these inputs.
Define a class student derived from person which is having data members student_id,
department, CGPA. Define setdata() function which inherits setdata() from person class also
take inputs for student_id & department. Define a function calc_gpa() which will take input of
number of semesters, sgpa and credit hours for those semesters and calculate CGPA
accordingly and prints CGPA.
Define a class Faculty derived from student whose data members are faculty_id, department,
salary. Define setdata() function which inherits setdata() from person class also take inputs for
faculty_id & department. Define a function calc_salary() which will take input for no_of_days,
no_of_lectures_delivered and salary_per_lecture and calculate and return the salary
accordingly and prints it.
Define a class Teacher_Assistant derived from faculty and student. Define setdata() function for
this class which will inherit setdata() from both parent classes.
In the main function create objects of all classes. Call setdata() and Calc_BMI() for all objects.
Call calc_gpa() for student and Teacher_Assistant object. Call calc_salary() for faculty and
Teacher_Assistant object.

Vous aimerez peut-être aussi