We want to calculate the total marks of each student of a class in Physics,Chemistry and Mathematics and the average marks of the class. The number of students in the class are entered by the user. Create a class named Marks with data members for roll number, name and marks. Create three other classes inheriting the Marks class, namely Physics, Chemistry and Mathematics, which are used to define marks in individual subject of each student. Roll number of each student will be generated automatically using inheritance by c++
Question
We want to calculate the total marks of each student of a class in Physics,Chemistry and Mathematics and the average marks of the class. The number of students in the class are entered by the user. Create a class named Marks with data members for roll number, name and marks. Create three other classes inheriting the Marks class, namely Physics, Chemistry and Mathematics, which are used to define marks in individual subject of each student. Roll number of each student will be generated automatically using inheritance by c++
Solution
Sure, here is a simple implementation in C++:
#include<iostream>
using namespace std;
class Marks {
public:
static int rollNumberGenerator;
int rollNumber;
string name;
int marks;
Marks(string name, int marks) {
this->rollNumber = ++rollNumberGenerator;
this->name = name;
this->marks = marks;
}
};
int Marks::rollNumberGenerator = 0;
class Physics : public Marks {
public:
Physics(string name, int marks) : Marks(name, marks) {}
};
class Chemistry : public Marks {
public:
Chemistry(string name, int marks) : Marks(name, marks) {}
};
class Mathematics : public Marks {
public:
Mathematics(string name, int marks) : Marks(name, marks) {}
};
int main() {
Physics student1("John", 85);
Chemistry student2("Jane", 90);
Mathematics student3("Doe", 95);
cout << "Roll Number: " << student1.rollNumber << ", Name: " << student1.name << ", Physics Marks: " << student1.marks << endl;
cout << "Roll Number: " << student2.rollNumber << ", Name: " << student2.name << ", Chemistry Marks: " << student2.marks << endl;
cout << "Roll Number: " << student3.rollNumber << ", Name: " << student3.name << ", Mathematics Marks: " << student3.marks << endl;
return 0;
}
This program creates a base class Marks with data members for roll number, name, and marks. The roll number is automatically generated using a static variable rollNumberGenerator. Three other classes Physics, Chemistry, and Mathematics inherit from the Marks class and are used to define marks in individual subjects for each student.
Please note that this is a simple implementation and does not calculate the total marks of each student or the average marks of the class. You would need to add additional functionality to achieve that.
Similar Questions
Create a class called "Student" with private member variables for name, roll number, and marks in three subjects. Include public member functions to set the student details, calculate the average marks, and display the student detail
Create a class VIT with data members student roll no, name, marks define a constructor to initilize the data members create a derived class student ,define a member function to calculate the average mark of the student
Write a C program using structure student which allows users to input details for three students including their names, roll numbers, and marks in 5 subjects. Use a function calculateTotalMarks(struct Student) which calculates the total marks and percentage for each student and displays the information. Each subject test is for 10 marks. Total marks = 50. Percentage = (marks obtained/total marks)*100.
You are developing a Student Record Management System in C. The system needs to store and manage information for multiple students, including their names, roll numbers, and marks obtained in different subjects. Implement array in structures to read, write, and compute average marks and the students scoring above and below the average marks for a class of N students. INPUT/OUTPUT EXAMPLE: Enter the number of students: 3 Enter details for 3 students: Student 1: Name: A Roll Number: 1 Marks in 5 subjects: Subject 1: 12 Subject 2: 13 Subject 3: 14 Subject 4: 15 Subject 5: 16 Student 2: Name: BB Roll Number: 2 Marks in 5 subjects: Subject 1: 11 Subject 2: 13 Subject 3: 12 Subject 4: 15 Subject 5: 14 Student 3: Name: CC Roll Number: 10 Marks in 5 subjects: Subject 1: 13 Subject 2: 14 Subject 3: 16 Subject 4: 17 Subject 5: 11 Class average marks: 13.73 Students scoring above average: A (Roll Number: 1) CC (Roll Number: 10) Students scoring below average: BB (Roll Number: 2)
Create a base class External_exam with protected member : marks( out of 100)Create a constructor to read the marks.Create another base class Internal_exam with private members: cat1,cat2Create a constructor to read cat1 and cat2 marks(out of 50).Create a derived class exam from above 2 classes with member function : DA1,DA2,DA3Create a constructor to read DA1,DA2,DA3 marks(out of 10).Create a member function to calculate the total mark T.T=(0.40*marks)+(0.15*cat1)+ (0.15*cat2)+ DA1,DA2,DA3.Internal marks is (0.15*cat1)+ (0.15*cat2)+ DA1,DA2,DA3External mark is 0.40*marksSample Input78 (marks)34(cat1)28(cat2)9(da1)9(da2)8(da3)Sample OutputInternal:35.30External:31.20Total:66.50
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.