Practice Questions
Practice Questions
Create a class named Student_Basic_Info having public members name, age, and gender.
Create a class named Student_Result_Info inherited from class Student_Basic_Info and provide
public members percentage, obtainedMarks, and totalMarks. Also, provide a member function
calculatePercentage to calculate the percentage and a member function displayInfo to display the
basic information and the percentage of the student.
Type the C++ code to create the object of the class and assign values to the public members
directly in the main function (name: "Ahmed", age: 15, gender: 'M', obtained marks: 400, total
marks: 500). Then call the function calculatePercentage to calculate the percentage and the
function displayInfo to print the basic information and percentage of the student.
Create a class Shape with protected members base and height. Include a member function
getShapeInfo to get base and height. Derive a class Triangle from Shape with a member function
calculateArea to compute the area of the triangle and a member function displayInfo to display
the base, height, and area of the triangle.
Create the object of the class Triangle and assign values to the public members directly in the
main function (base: 10, height: 5). Then call the function calculateArea to calculate the area of
the triangle and the function displayInfo to print the base, height, and area of the triangle.
Create a class Student with a protected member percentage. Include a member function
getPercentage to input the percentage. Derive a class GradeCalculator from Student with a
member function calculateGrade to compute the grade of the student and a member function
displayInfo to display the percentage and grade of the student.
Create the object of the class GradeCalculator and call the function getPercentage to input the
percentage. Then call the function calculateGrade to calculate the grade of the student and the
function displayInfo to print the percentage and grade of the student.
Q4. Write a C++ Program to
Create a class Shape with protected member radius. Derive a class Circle from Shape with a
member function getRadiusInfo to input 5 radius (use an array) and a member function
displayInfo to calculate and display the area of each circle.
Create a class Student with protected members name and rollNumber. Include a member function
getStudentInfo to input these details. Derive a class Student_Marks from Student with a member
function getMarksInfo to input marks in 5 subjects (use an array) and also calculate the
percentage. Also create a member function displayInfo to display all details along with the
percentage of the student.