slips 9


/* Slip no : 9_1 Write a C++ program to create a class Person which contains data members as P_Name, P_City, P_Contact_Number.Write member functions to accept and display five Persons information. Design User defined
   Manipulator to print P_Contact_Number. (For Contact Number set right justification,
   maximum width to 10 and fill remaining spaces with *) */

#include<iostream.h>
#include<conio.h>
//#include<manip.h>
class person
{
                char p_name[20],p_city[10];
                long int p_c_no;
                public:
                void getdata()
                {
                                cout<<"\n enter person name\t";
                                cin>>p_name;
                                cout<<"\n enter persons city\t";
                                cin>>p_city;
                                cout<<"enter person contact no\t";
                                cin>>p_c_no;
                }


                void display()
                {
                                cout<<"\n\n*************OUTPUT******************\n";
                                cout<<"\nperson name =\t"<<p_name;
                                cout<<"\nperson city =\t"<<p_city;
                                //cout<<"\npersons contact number is\t"<<p_c_no;
                                cout.width(10);
                                cout.fill('*');
                                cout<<p_c_no;
                                //cout<<cout.setw(10)<<p_c_no;
                }
};
void main()
{
                int i;
                clrscr();
                person p[5];
                for(i=0;i<1;i++)
                {
                                p[i].getdata();
                }
                for(i=0;i<1;i++)
                {
                                p[i].display();
                }
                getch();

}

/* Slip no : 9_2 Create  two base classes Learning_Info( Roll_No, Stud_Name, Class, Percentage) and Earning_Info(No_of_hours_worked, Charges_per_hour). Derive a class Earn_Learn_info from above two classes. Write necessary member functions to accept and display Student information. Calculate total money earned by the student. (Use constructor in derived class) */

#include<iostream.h>
#include<conio.h>
#include<string.h>
class learning_info
{
   public:
   int rno;
   char name[20],cls[10];
   float per;
   learning_info(int roll,char sname[],char cl[],float perc)
   {
      rno=roll;
      strcpy(name,sname);
      strcpy(cls,cl);
      per=perc;
   }
   void display()
   {
      cout<<"\n Roll no = "<<rno<<"\n Name="<<name<<"\n class = "<<cls;
      cout<<"\n Percentage = "<<per;
   }
};

class earning_info
{
    public:
   int hrs,charges;
   earning_info(int hr,int chrgs)
   {
     hrs=hr;
     charges=chrgs;
   }
   void display()
   {
     cout<<"\n Hours = "<<hrs;
     cout<<"\t charges = "<<charges;
   }
};

class earn_learn_info:public learning_info,public earning_info
{
   public:
   earn_learn_info(int roll,char sname[],char cl[],float perc,int hr,int chrgs):learning_info(roll,sname,cl,perc),earning_info(hr,chrgs)
   {
   }
   void display()
   {
      learning_info::display();
      earning_info::display();
   }
   void calculate()
   {
                  int total;
                  total=charges*hrs;
                  cout<<"\n Money earned by student:= "<<total;
   }
};

void main()
{
    clrscr();
    int rno,ch,hr;
    float p;
    char nm[10],c[10];
    earn_learn_info ob1(1,"abc","sy",77,5,50);
    ob1.display();
    ob1.calculate();
    cout<<"\n Enter rno : ";
    cin>>rno;
    cout<<"\n enter name : ";
    cin>>nm;
    cout<<"\n Enter class : ";
    cin>>c;
    cout<<"\n Enter percentage : ";
    cin>>p;
    cout<<"\n Enter working hr : ";
    cin>>hr;
    cout<<"\n Enter charges : ";
    cin>>ch;
    earn_learn_info ob2(rno,nm,c,p,hr,ch);
    ob2.display();
    ob2.calculate();
    getch();
}
slips 9  slips 9 Reviewed by Dinesh Varal on January 17, 2018 Rating: 5

No comments:

Powered by Blogger.