You are on page 1of 6

FINAL WORKSHEET

STUDENT’S NAME- Yana Shrivastava

STUDENT’S UID – 20BCS2279

CLASS AND GROUP – 15-(B)

SEMESTER – 2nd

Q.no.1
Write a program that takes information about
institute staff information for 1) Teacher
code, name, subject and publication 2) Officer
code, name and grade 3) Typist code, name,
speed and daily wages and displays it using
multiple inheritance.
PROGRAM CODE-

#include <iostream>
using namespace std;
class staff
{
protected:
int code;
char name[5];
public:
void getstaff()
{
cout<<"\n\nEnter code :-"<<endl;
cin>>code;
cout<<"Enter name :-"<<endl;
cin>>name;
}
void putstaff()
{
cout<<"\nNAME :-"<<name;
cout<<"\nCODE :-"<<code;
}
};
class teacher : public staff
{
char sub[20];
char pub[20];
public:
void getdata()
{
getstaff();
cout<<"Enter Subject :-"<<endl;
cin>>sub;
cout<<"Enter Publication :-"<<endl;
cin>>pub;
}
void putdata()
{
putstaff();
cout<<"\nSUBJECT :-"<<sub;
cout<<"\nPUBLICATION:-"<<pub;
}
};
class officer : public staff
{
char grade;
public:
void get_o()
SUBJECT NAME- OBJECT ORIENTED PROGRAMMING
USING C++ LAB SUBJECT CODE-CSP152
{
getstaff();
cout<<"Enter Grade :-"<<endl;
cin>>grade;
}
void put_o()
{
putstaff();
cout<<"\nGRADE :-"<<grade;
}
};
class typist : public staff
{
float speed, dw;
public:
void get_ty()
{
getstaff();
cout<<"Enter speed (wpm):-"<<endl;
cout<<"Enter daily wages:"<<endl;
cin>>speed;
cin>>dw;
}
void put_ty()
{
putstaff();
cout<<"\nSPEED :-"<<speed;
cout<<"\nWAGE :-"<<dw;
}
};
int main()
{
teacher t;
t.getdata();
t.putdata();
officer o;
o.get_o();
o.put_o();
typist i;
i.get_ty();
i.put_ty();
return 0;
}

OUTPUT-
Q.no.2
WAP to implement the exception handling with the
functionality of testing the throw
restrictions.

PROGRAM CODE-
#include <bits/stdc++.h>
using namespace std;

void handle(int test)


{

try {

if (test==0)

throw test; // throw int

if (test==1)

throw 'a'; // throw char

if (test==2)

throw 123.23; // throw double

catch(int i) { // catch an int exception

cout<< "Caught " << i << "\n"; }

catch(...) { // catch all other exceptions

cout<< "Caught one!\n"; }

}
int main( ) {

cout<< "start\n";

handle(0);

handle(1);

handle(2);

cout<< "end";

return 0;

OUTPUT

You might also like