0% found this document useful (0 votes)
11 views2 pages

Practice Questions

The document contains practice questions for writing C++ programs involving class creation and inheritance. It includes tasks to create classes for student information, shapes, and grade calculation, with specific member functions for data input, calculations, and displaying information. Each question requires creating objects and calling functions to demonstrate the functionality of the classes designed.

Uploaded by

mafh7212
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)
11 views2 pages

Practice Questions

The document contains practice questions for writing C++ programs involving class creation and inheritance. It includes tasks to create classes for student information, shapes, and grade calculation, with specific member functions for data input, calculations, and displaying information. Each question requires creating objects and calling functions to demonstrate the functionality of the classes designed.

Uploaded by

mafh7212
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/ 2

PRACTICE QUESTIONS

Q1. Write a C++ Program to

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.

Q2. Write a C++ Program to

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.

Q3. Write a C++ Program to

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 an object of Circle and call getRadiusInfo, and displayInfo.

Q5. Write a C++ Program to

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.

Create an object of Student_Marks and call getStudentInfo, getMarksInfo, and displayInfo.

You might also like