Write a program that inputs data about few
students and professors and displays whether student or processor is
outstanding or not using one for loop.
SOLUTION:
#include<iostream.h>
#include<conio.h>
class person
{
public:
char first_name[20],last_name[20];
int grade[3],i;
void gradefun();
};
void person::gradefun()
{
for (int i=0;i<3;i++)
{
if (grade[i]>=90)
cout<<"\nGrade is outsatndaing for the"<<"\t"<<first_name[i]<<"\t"<<last_name[i];
else
cout<<"\nGrade isnot outstanding for the"<<"\t"<<first_name[i]<<"\t"<<last_name[i];
}
}
class professor:public person
{
public:
void inputfun();
};
void professor::inputfun()
{
cout<<"Enter the recods of the three professors:";
for (int i=0;i<3;i++)
{
cout<<"\n\nEnter the Professor First name:";
cin>>first_name[i];
cout<<"Enter the Professor Last Name:";
cin>>last_name[i];
cout<<"Enter the garde for the Professor:";
cin>>grade[i];
}
}
class student: public person
{
public:
void inputfun();
};
void student::inputfun()
{
cout<<"\n\nEnter the recods of three students:";
for (int i=0;i<3;i++)
{
cout<<"\n\nEnter the Student First name:";
cin>>first_name[i];
cout<<"Enter the Student Last Name:";
cin>>last_name[i];
cout<<"Enter the garde for the Student:";
cin>>grade[i];
}
}
void main()
{
int ch;
professor p;
student s;
clrscr();
p.inputfun();
s.inputfun();
cout<<"Press\n1.For Professor grade\n2.For Student grade";
cout<<"\nEnter your choice:";
cin>>ch;
switch (ch)
{
case 1:
p.gradefun();
break;
case 2:
s.gradefun();
break;
default:
cout<<"\nYou didnot enter the correct choice.";
break;
}
getch();
}
OUTPUT:
SOLUTION:
#include<iostream.h>
#include<conio.h>
class person
{
public:
char first_name[20],last_name[20];
int grade[3],i;
void gradefun();
};
void person::gradefun()
{
for (int i=0;i<3;i++)
{
if (grade[i]>=90)
cout<<"\nGrade is outsatndaing for the"<<"\t"<<first_name[i]<<"\t"<<last_name[i];
else
cout<<"\nGrade isnot outstanding for the"<<"\t"<<first_name[i]<<"\t"<<last_name[i];
}
}
class professor:public person
{
public:
void inputfun();
};
void professor::inputfun()
{
cout<<"Enter the recods of the three professors:";
for (int i=0;i<3;i++)
{
cout<<"\n\nEnter the Professor First name:";
cin>>first_name[i];
cout<<"Enter the Professor Last Name:";
cin>>last_name[i];
cout<<"Enter the garde for the Professor:";
cin>>grade[i];
}
}
class student: public person
{
public:
void inputfun();
};
void student::inputfun()
{
cout<<"\n\nEnter the recods of three students:";
for (int i=0;i<3;i++)
{
cout<<"\n\nEnter the Student First name:";
cin>>first_name[i];
cout<<"Enter the Student Last Name:";
cin>>last_name[i];
cout<<"Enter the garde for the Student:";
cin>>grade[i];
}
}
void main()
{
int ch;
professor p;
student s;
clrscr();
p.inputfun();
s.inputfun();
cout<<"Press\n1.For Professor grade\n2.For Student grade";
cout<<"\nEnter your choice:";
cin>>ch;
switch (ch)
{
case 1:
p.gradefun();
break;
case 2:
s.gradefun();
break;
default:
cout<<"\nYou didnot enter the correct choice.";
break;
}
getch();
}
OUTPUT:
No comments:
Post a Comment