Object Oriented Programming In C++, Class Creation - Wisdom Lighter

Tuesday, 22 May 2018

Object Oriented Programming In C++, Class Creation


Create a base/parent class name student. It has one data members of integer type and one of char type. All the data members should be public.
           Name
          Roll number
Provide a get_data( ) function to get data from user. Create a subclass marks which contain marks of at least three subjects from user by using get_marks (). In get_marks () firstly you have to call inherited function get_data( ) of parent class. You are also required to calculated percentage of marks in get_marks ().  Provide a display function to display all data of a student. You have to access all the functions in a main by using single object of class.
Program should be enough dynamic it provide the facility to user to enter the no record of students which he or she desires?




Program
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
          public:
                   char name[10];
                   introllno;
                   void get_data()
                   {
                             cout<<"enter your name"<<endl;
                             cin>>name;
                             cout<<"enter your roll no"<<endl;
                             cin>>rollno;
                   }
};
class marks:public student
{
          public:
                   float m1,m2,m3,sum,pre;
                   void get_data()
                   {

                             cout<<"enter the marks of oop"<<endl;
                             cin>>m1;
                             cout<<"enter the marks of maths"<<endl;
                             cin>>m2;
                             cout<<"enter the marks of ds"<<endl;
                             cin>>m3;
                             sum=m1+m2+m3;
                             cout<<"the total marks"<<"  "<<sum<<endl;
                             pre=(sum/300)*100;
                             cout<<"the percentage is"<<"  "<<pre;
                             func();
                   }
                   func()
                   {
                             int p;
                             cout<<"do you want to run the program if yes then press 1 else press 0="<<endl;
                             cin>>p;
                             if (p==1)
                             {
                                      get_data();
                             }
                             else
                             {
                                      return 0;
                             }
                   }
         
};
intmain()
{
          marks A1;
          student A2;
          A1.get_data();
          return 0;
}



No comments:
Write comments