Slip15
Q.1) Write a C++
program to create a class which contains two data members. Write member
functions to accept display and swap two entered numbers using call by
reference.
#include<iostream.h>
#include<conio.h>
class integer
{
public:
int x,y;
void getdata();
void display();
void swap(int &, int
&);
};
void integer::getdata()
{
cout<<"Enter
value of x and y:-\n";
cin>>x>>y;
}
void integer::display()
{
cout<<"x="<<x;
cout<<"\ty="<<y;
}
void integer::swap(int
&p, int &q)
{
int temp;
temp=p;
p=q;
q=temp;
cout<<"\n\nAfter
swap\n\n";
cout<<"x="<<x;
cout<<"\ty="<<y;
}
void main()
{
int x,y;
integer i;
clrscr();
i.getdata();
i.display();
i.swap(x,y);
getch();
}
Q.2)Create a base class
Student(Roll_No, Name, Class) which derives two classes
Internal_Marks(IntM1,IntM2,IntM3,IntM4,IntM5) and
External_Marks(ExtM1 ExtM2, ExtM3, ExtM4, ExtM5). Class Result(T1, T2, T3, T4,
T5) inherits both Internal_Marks and External_Marks classes. (Use
Virtual Base Class)Write a C++ menu driven program to perform the following
functions:
i. To Accept and display
student details
ii. Calculate Subject wise
total marks obtained. Check whether student has passed in Internal
and External Exam of each subject. Also check whether he has passed in
respective subject or not and display result accordingly.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
class student
{
int rollno;
char
name[20],sclass[10];
public:
void get()
{
cout<<"\nEnter
roll number:\t";
cin>>rollno;
cout<<"Enter
name.:\t";
cin>>name;
cout<<"Enter
class.:\t";
cin>>sclass;
}
void put()
{
cout<<"\nRoll
number:\t"<<rollno;
cout<<"\nName.:\t"<<name;
cout<<"\nClass.:\t"<<sclass;
}
};
class internal:virtual
public student
{
public:
int i1,i2,i3,i4,i5;
void getinternal()
{
cout<<"\n\nEnter
internal marks:\t";
cout<<"\nsubject
1:\t";
cin>>i1;
cout<<"\nsubject
2:\t";
cin>>i2;
cout<<"\nsubject
3:\t";
cin>>i3;
cout<<"\nsubject
4:\t";
cin>>i4;
cout<<"\nsubject
5:\t";
cin>>i5;
}
};
class external:virtual
public student
{
public:
int e1,e2,e3,e4,e5;
void getexternal()
{
cout<<"\n\nEnter
external marks:\t";
cout<<"\nsubject
1:\t";
cin>>e1;
cout<<"\nsubject
2:\t";
cin>>e2;
cout<<"\nsubject
3:\t";
cin>>e3;
cout<<"\nsubject
4:\t";
cin>>e4;
cout<<"\nsubject
5:\t";
cin>>e5;
}
};
class result:public
internal, public external
{
int t1,t2,t3,t4,t5;
public:
void putsub1()
{
cout<<"\nMarks
of subject 1:\t";
cout<<"\nInternal:\t"<<i1;
if(i1>=8)
cout<<":\tPass";
else
cout<<":\tFail";
cout<<"\nExternal:\t"<<e1;
if(e1>=32)
cout<<":\tPass";
else
cout<<":\tFail";
t1=i1+e1;
cout<<"\nTotal:\t"<<t1;
if(i1>=8 &&
e1>=32)
cout<<":\tPass";
else
cout<<":\tFail";
}
void putsub2()
{
cout<<"\nMarks
of subject 2:\t";
cout<<"\nInternal:\t"<<i2;
if(i2>=8)
cout<<":\tPass";
else
cout<<":\tFail";
cout<<"\nExternal:\t"<<e2;
if(e2>=32)
cout<<":\tPass";
else
cout<<":\tFail";
t2=i2+e2;
cout<<"\nTotal:\t"<<t2;
if(i2>=8 &&
e2>=32)
cout<<":\tPass";
else
cout<<":\tFail";
}
void putsub3()
{
cout<<"\nMarks
of subject 3:\t";
cout<<"\nInternal:\t"<<i3;
if(i3>=8)
cout<<":\tPass";
else
cout<<":\tFail";
cout<<"\nExternal:\t"<<e3;
if(e3>=32)
cout<<":\tPass";
else
cout<<":\tFail";
t3=i3+e3;
cout<<"\nTotal:\t"<<t3;
if(i3>=8 &&
e3>=32)
cout<<":\tPass";
else
cout<<":\tFail";
}
void putsub4()
{
cout<<"\nMarks
of subject 4:\t";
cout<<"\nInternal:\t"<<i4;
if(i4>=8)
cout<<":\tPass";
else
cout<<":\tFail";
cout<<"\nExternal:\t"<<e4;
if(e4>=32)
cout<<":\tPass";
else
cout<<":\tFail";
t4=i4+e4;
cout<<"\nTotal:\t"<<t4;
if(i4>=8 &&
e4>=32)
cout<<":\tPass";
else
cout<<":\tFail";
}
void putsub5()
{
cout<<"\nMarks
of subject 5:\t";
cout<<"\nInternal:\t"<<i5;
if(i5>=8)
cout<<":\tPass";
else
cout<<":\tFail";
cout<<"\nExternal:\t"<<e5;
if(e5>=32)
cout<<":\tPass";
else
cout<<":\tFail";
t5=i5+e5;
cout<<"\nTotal:\t"<<t5;
if(i5>=8 &&
e5>=32)
cout<<":\tPass";
else
cout<<":\tFail";
}
};
void main()
{
int i,ch,sub;
result r;
clrscr();
do
{
cout<<"\n\n1.Accept
and display student details\t";
cout<<"\n2.Display
result of specific subject\t";
cout<<"\n3.Exit\t";
cout<<"\n\nEnter
choise\t";
cin>>ch;
clrscr();
switch(ch)
{
case 1:
{
r.get();
r.put();
r.getinternal();
r.getexternal();
}
break;
case 2:
{
cout<<"\n\nEnter
subject number";
cin>>sub;
switch(sub)
{
case 1:
r.putsub1();
break;
case 2:
r.putsub2();
break;
case 3:
r.putsub3();
break;
case 4:
r.putsub4();
break;
case 5:
r.putsub5();
break;
default:
cout<<"Wrong
choice";
}
}
break;
case 3:
exit(0);
default:
cout<<"Wrong
choice";
}
}while(ch!=3);
getch();
}