Q.Create a class student with data members name,class,section,roll no. and function
members getdata(),printdata(),and promoted().From this class derive a class 'Sr_std'
with additional data member stream.Also include another function member change_stream().
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
char ch[5];
class Student
{
private:
char name[30];
int cla;
char section[2];
int roll_no;
public:
Student()
{
strcpy(name,"ABCD");
cla=1;
strcpy(section,"A");
roll_no=1;
}
void getdata()
{
cout<<"Enter name:";
gets(name);
cout<<endl<<"Enter class:";
cin>>cla;
cout<<"Enter section:";
cin>>section;
cout<<"Enter roll number:";
cin>>roll_no;
}
void print()
{
cout<<endl<<"Name:";
puts(name);
cout<<endl<<"Class:";
cout<<cla;
cout<<endl<<"Section:";
cout<<section;
cout<<endl<<"Roll number:";
cout<<roll_no;
}
protected:
void promote()
{
cout<<"Congratulation!!! Promoted to:"<<cla+1;
cla=cla+1;
}
};
class Sr_std:public Student
{
private:
char stream[5];
public:
Sr_std()
{
strcpy(stream,"PCM");
}
void getdata()
{
Student::getdata();
cout<<"Enter stream:";
gets(stream);
}
void print()
{
Student::print();
cout<<endl<<"Stream:"<<stream;
}
void change_stream()
{
cout<<"Enter desired stream:";
gets(ch);
strcpy(stream,ch);
}
void promote()
{
Student::promote();
}
};
void main()
{
clrscr();
char str;
Sr_std A;
A.getdata();
cout<<endl<<"Want to change stream:(Y/N)";
cin>>ch;
if(strcmp(ch,"Y")==0)
{
A.change_stream();
A.print();
}
else
A.print();
int marks;
cout<<endl<<"Enter % marks obtained:";
cin>>marks;
if(marks>40)
A.promote();
else
cout<<"Fail!!!!";
getch();
}
members getdata(),printdata(),and promoted().From this class derive a class 'Sr_std'
with additional data member stream.Also include another function member change_stream().
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
char ch[5];
class Student
{
private:
char name[30];
int cla;
char section[2];
int roll_no;
public:
Student()
{
strcpy(name,"ABCD");
cla=1;
strcpy(section,"A");
roll_no=1;
}
void getdata()
{
cout<<"Enter name:";
gets(name);
cout<<endl<<"Enter class:";
cin>>cla;
cout<<"Enter section:";
cin>>section;
cout<<"Enter roll number:";
cin>>roll_no;
}
void print()
{
cout<<endl<<"Name:";
puts(name);
cout<<endl<<"Class:";
cout<<cla;
cout<<endl<<"Section:";
cout<<section;
cout<<endl<<"Roll number:";
cout<<roll_no;
}
protected:
void promote()
{
cout<<"Congratulation!!! Promoted to:"<<cla+1;
cla=cla+1;
}
};
class Sr_std:public Student
{
private:
char stream[5];
public:
Sr_std()
{
strcpy(stream,"PCM");
}
void getdata()
{
Student::getdata();
cout<<"Enter stream:";
gets(stream);
}
void print()
{
Student::print();
cout<<endl<<"Stream:"<<stream;
}
void change_stream()
{
cout<<"Enter desired stream:";
gets(ch);
strcpy(stream,ch);
}
void promote()
{
Student::promote();
}
};
void main()
{
clrscr();
char str;
Sr_std A;
A.getdata();
cout<<endl<<"Want to change stream:(Y/N)";
cin>>ch;
if(strcmp(ch,"Y")==0)
{
A.change_stream();
A.print();
}
else
A.print();
int marks;
cout<<endl<<"Enter % marks obtained:";
cin>>marks;
if(marks>40)
A.promote();
else
cout<<"Fail!!!!";
getch();
}
No comments:
Post a Comment