Pages

Wednesday, 21 June 2017

CBSE Class 12 - Computer Science - C++ Practical Class Design Snippet-3 (#cbseNotes)

C++ Practical
Class Design Snippet-3

CBSE Class 12 - Computer Science - C++ Practical Class Design Snippet-3  (#cbseNotes)

Question : Write a Program to define the classes PERSON, GAME and STUDENT & to access the essential data using multiple inheritance?


Answer:



/* Program to define the classes PERSON, GAME and STUDENT & to access the essential data using multiple inheritance.*/

#include <iostream.h>
#include <stdio.h>
#include <conio.h>

class person
{ 
 char name[21];
 int age;
 public:
     void indata()
     {
     cout<< "\nEnter the name of Student: " ;
     gets(name);
     cout<< "\nEnter the age : ";
     cin >> age;
     }
     void outdata();
};

void person::outdata()  // since the function contains loop so it is not made inline
{
    cout<<"\n";
    for(int i=0; i<79; i++)
     cout<<"-";
    cout<<"\nName of the student is: "<<name;
    cout<<"\nAge of the student is : "<<age;
    }

class game {
    char game_name[20];
    public:
    void input()
       {
 cout<<"\n\nEnter the game name : ";
 cin.get();cin.getline(game_name,20);
       }

   void output()
 {
 cout<<"\n\nGame opted by the student is : "<<game_name;
       }
};

class student: public person, public game
{
    float Tmarks;
    int rollno;
    public:
 char calgrade()
 {
 if(Tmarks>90)
   return 'A';
 else if(Tmarks>80&&Tmarks<=90)
   return 'B';
 else if(Tmarks>70&&Tmarks<=80)
   return 'C';
 else if(Tmarks>60&&Tmarks<=70)
   return 'D';
 else
   return 'E';
 }

    void enter()
    {
 indata(); // indata() of class person called here
 cout << "\nEnter the roll number: "; cin>>rollno;
 input(); // input() of class game called here
 cout << "\nEnter total marks (out of 100) : ";
 cin >> Tmarks;
    }

    void display()
    {
      outdata();
      cout<<"\n\nRoll number : "<<rollno;
      output();
      cout<<"\n\nTotal marks are : "<<Tmarks;
      cout<<"\n\nGrade = "<<calgrade();
    }
};

void main()
{
   clrscr();
   student A;
   A.enter();
   A.display();
   getch();
}



CBSE Class 12 - Computer Science - C++ Practical Class Design Snippet-3  (#cbseNotes)
Program Output




No comments:

Post a Comment

We love to hear your thoughts about this post!

Note: only a member of this blog may post a comment.