Write A C Program To Implement The Multilevel In...

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

  Home Study tools

 My courses
 My books My folder Career Life 

Find solutions for your homework Search

home / study / engineering / computer science / computer science questions and answers / write a c++ program to implement the multilevel inhe…

Question: Write a C++ program to implement the Multilevel Inheritance … Post a question
Answers from our experts for your tough
homework questions

Write a C++ program to implement the Multilevel


Inheritance on the following.
Enter question
Create the class Student with Student number (snum),

Student(sname) and degree (deg) as data members and the


member

functions as:

getstud(): gets snum, sname and deg.

showstud(): prints snum, sname and deg


Continue to post
Create the class Marks with marks in three subjects m1, m2, m3
as

0 questions remaining
data members and the member functions as:

getmark(): gets m1, m2 and m3

showmark(): prints m1, m2 and m3

Derive the class Marks from the class Student in public mode

Create the class Result with total marks (total), average (avg)
and My Textbook Solutions
grade(gr) as data members and the member functions as:

Calresult(): Calculate the total marks and displays the


average

CalGrade(): Calculates Grade and displays the Grade.

If Average (60-100) grade A

If Average (40-59) : grade B

If Average ( 0-39): grade C

Showresult():displays avg, tot and gr Derive the class Result from


the class Mark in public mode.
Principles of... Structural... Personality...

9th Edition 6th Edition 6th Edition

View all solutions

Show transcribed image text

Expert Answer

Ram Aggarwal answered this


Was this answer helpful? 2 0
1,414 answers

If you have any doubts, please ask in the comments, I will try
to solve it as soon as possible. If you find my
answer helpful, do
UPVOTE.Thanks

The required C++ code is:


#include<iostream>

 
#include<iomanip>
Home Study tools
 My courses
 My books My folder Career Life 
#include<string.h>

using namespace std;

class Student{

int snum;

string sname;

string deg;

public:

//gets the student information

   void getstud(){

cout<<"\nEnter the Student Number: ";

cin>>snum;

fflush(stdin);

cout<<"\nEnter the Student Name: ";

getline(cin,sname);

cout<<"\nEnter the Student Degree: ";

getline(cin,deg);

//prints the student information

void showstud(){

cout<<"\nStudent Number: "<<snum;

cout<<"\nStudent Name: "<<sname;

cout<<"\nStudent Degree: "<<deg;

};

//class Marks inherits Student class in public mode

class Marks: public Student{

protected:

   //m1,m2,m3 are made protected so that they can be


accessed in the child class

   int m1;

   int m2;

   int m3;

  

    public:

//gets the Student Marks

void getmark(){

cout<<"\nEnter Marks 1: ";

cin>>m1;

cout<<"\nEnter Marks 2: ";

cin>>m2;

cout<<"\nEnter Marks 3: ";

cin>>m3;

   //prints the student marks

void showmark(){

cout<<"\nMark 1: "<<m1;

cout<<"\nMark 2: "<<m2;

cout<<"\nMark 3: "<<m3;

};

class Result: public Marks{

int total;

float avg;

char grade;

public:

//calculates the student result and print the average

void Calresult(){

total=m1+m2+m3;

avg=total/3.0;

cout<<"\nAverage is "<<avg;

//calculates the student grade and prints it

void Calgrade(){

if(avg>=60) grade='A';

else if(avg>=40) grade='B';

else grade='C';

cout<<"\nGrade: "<<grade;

//prints the student result

void Showresult(){

cout<<"\nTotal: "<<total;

cout<<"\nAverage: "<<avg;

cout<<"\nGrade: "<<grade;

};

//demo main function

int main(){

Result x;

x.getstud();

x.getmark();

x.Calresult();

 x.Calgrade(); Home Study tools


 My courses
 My books My folder Career Life 
}

Sample Output:

Comment


Questions viewed by other students

Q: 1. Write a C++ program to implement the Multilevel Inheritance on the following. ► Create the class Student with
Student number (snum), Student(sname) and degree (deg) as data members and the member functions as: •
getstud(): gets snum, sname and deg. • showstud(): prints snum, sname and deg ► Create the class Marks with
marks in three subjects m1, m2, m3 as data members and the...

A: See answer 100% (1 rating)

Q: i
need the solution in C++

A: See answer

Show more 

COMPANY

LEGAL & POLICIES

CHEGG PRODUCTS AND SERVICES

CHEGG NETWORK

CUSTOMER SERVICE

© 2003-2022 Chegg Inc. All rights reserved.


  Home Study tools
 My courses
 My books My folder Career Life 

You might also like