56. Write a Program to define a class student with the following specifications.
Private: rn,name,per;
public: getd(),showd()
Answer :
#include<iostream.h>
#include<conio.h>
class student
{
private:
int rn;
char nm[20];
float per;
public:
Void getd()
{
cout<<"Enter Roll No:";
cin>>rn;
cout<<"Enter Name:";
cin>>nm;
cout<<"Enter Percentage:";
cin>>per;
}
Void showd()
{
cout<<rn;
cout<<nm;
cout<<per;
}
};
Void main()
{
student s1,s2;
s1.getd();
s2.getd();
s1.show();
s2.show();
getch();
}
...................................................................................................................................................................
57. Example of Classes in C++
Answer :
#include<iostream.h>
#include<conio.h>
class department
{
int dept id;
char hod[20];
char deptnm[20];
char location[20];
public:
department()
{
cout<<"\n Enter the Dept ID:";
cin>>deptid;
cout<<"\n Enter the HOD Name:";
gets(hod);
cout<<"\n Enter the Department Name:";
gets(deptnm);
cout<<"\n Enter the Location:";
gets(location);
}
Void print_department_info()
{
cout<<"\n Department Id:"<<deptid;
cout<<"\n Hod:"<<hod;
cout<<"\n Department Name:"<<deptnm;
cout<<"\n Location:'<<location;
}
};
class production : public department
{
char expert[20];
char product[20];
public:
production()
{
cout<<"\n Enter Your Expertise:";
gets(expert);
cout<<"\n Enter the Product Name:";
gets(product);
}
Void print_department_info()
{
department :: print_department_info();
cout<<"\n Expertise :"<<expert;
cout<<"\n Product :"<<product;
}
};
class marketing : public department
{
char zone[20];
public:
marketing()
{
cout<<"\n Enter the Zone in India:";
gets(zone);
}
Void print_department_info()
{
department :: print_department_info();
cout<<"\n Zone :"<<zone;
}
};
Void main()
{
int ch;
clrscr();
do
{
cout<<"\n Which Details you want to input and display \n 1. production \n 2. marketing \n
3. Exit \n Enter Your choice:";
cin>>ch;
if(ch == 1)
{
production p;
p.print_department_info();
}
else if(ch == 2)
{
marketing m;
m.print_department_info();
}
else if(ch == 3)
{
cout<<"Exiting....";
}
}
while (ch!=3);
getch();
}
Private: rn,name,per;
public: getd(),showd()
Answer :
#include<iostream.h>
#include<conio.h>
class student
{
private:
int rn;
char nm[20];
float per;
public:
Void getd()
{
cout<<"Enter Roll No:";
cin>>rn;
cout<<"Enter Name:";
cin>>nm;
cout<<"Enter Percentage:";
cin>>per;
}
Void showd()
{
cout<<rn;
cout<<nm;
cout<<per;
}
};
Void main()
{
student s1,s2;
s1.getd();
s2.getd();
s1.show();
s2.show();
getch();
}
...................................................................................................................................................................
57. Example of Classes in C++
Answer :
#include<iostream.h>
#include<conio.h>
class department
{
int dept id;
char hod[20];
char deptnm[20];
char location[20];
public:
department()
{
cout<<"\n Enter the Dept ID:";
cin>>deptid;
cout<<"\n Enter the HOD Name:";
gets(hod);
cout<<"\n Enter the Department Name:";
gets(deptnm);
cout<<"\n Enter the Location:";
gets(location);
}
Void print_department_info()
{
cout<<"\n Department Id:"<<deptid;
cout<<"\n Hod:"<<hod;
cout<<"\n Department Name:"<<deptnm;
cout<<"\n Location:'<<location;
}
};
class production : public department
{
char expert[20];
char product[20];
public:
production()
{
cout<<"\n Enter Your Expertise:";
gets(expert);
cout<<"\n Enter the Product Name:";
gets(product);
}
Void print_department_info()
{
department :: print_department_info();
cout<<"\n Expertise :"<<expert;
cout<<"\n Product :"<<product;
}
};
class marketing : public department
{
char zone[20];
public:
marketing()
{
cout<<"\n Enter the Zone in India:";
gets(zone);
}
Void print_department_info()
{
department :: print_department_info();
cout<<"\n Zone :"<<zone;
}
};
Void main()
{
int ch;
clrscr();
do
{
cout<<"\n Which Details you want to input and display \n 1. production \n 2. marketing \n
3. Exit \n Enter Your choice:";
cin>>ch;
if(ch == 1)
{
production p;
p.print_department_info();
}
else if(ch == 2)
{
marketing m;
m.print_department_info();
}
else if(ch == 3)
{
cout<<"Exiting....";
}
}
while (ch!=3);
getch();
}
0 comments:
Post a Comment