Sie sind auf Seite 1von 13

//WAP to show multilevel in classes

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
class COMPANY
{
char cname[20];
int nemp;

protected:
char hdoffice[80];

public:
void Input();
void Output();
};
class Branch : public COMPANY
{
char bran[20];
char badd[50];

protected:
int bno;

public:
void Enter();
void Show();
};
class EMPLOYEE : public Branch
{
char name[20];
int empno;
int noemp;

public:

void edetail();
void sdetail();
};
void COMPANY::Input()
{ cout << " Enter organisation name : ";
gets(cname);
cout << " Enter head office's address : ";
gets(hdoffice);
cout << " Enter number of employees all over the globe : ";
cin >> nemp;
}
void Branch::Enter()
{ cout << " Enter branch : ";
gets(bran);
cout << " Enter address : ";
gets(badd);
cout << " Enter branch id : ";
cin >> bno;
}
void EMPLOYEE::edetail()
{ COMPANY::Input();
Branch::Enter();
int i = 0;
cout << " Enter number of employees : ";
cin >> noemp;
}
void COMPANY::Output()
{ cout << " Company name : ";
puts(cname);
cout << " Head office's address : ";
puts(hdoffice);
cout << endl;
}
void Branch::Show()
{ cout << " Branch : ";

puts(bran);
cout << " Branch address : ";
puts(badd);
cout << " Branch number : ";
cout << bno << endl;
}
void EMPLOYEE::sdetail()
{ COMPANY::Output();
Branch::Show();
int i = 0;
cout << " No. of employees: ";
cout << noemp;
}
void main()
{ clrscr();
EMPLOYEE E;
E.edetail();
E.sdetail();
getch();
}

Output

//WAP to show multiple inheritance in classes

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
class COMPANY
{
char cname[50];
int nemp;

protected:
char hdoffice[80];

public:
void Input();
void Output();
};
class Branch
{
char bran[20];
char badd[50];

protected:
int bno;

public:
void Enter();
void Show();
};
class EMPLOYEE : public COMPANY, public Branch
{
int noemp;

public:

void edetail();
void sdetail();
};
void COMPANY::Input()
{
cout << " Enter company name : ";
gets(cname);
cout << " Enter head office's address : ";
gets(hdoffice);
cout << " Enter number of employees all over the globe : ";
cin >> nemp;
}
void Branch::Enter()
{
cout << " Enter branch : ";
gets(bran);
cout << " Enter address : ";
gets(badd);
cout << " Enter branch id : ";
cin >> bno;
}
void EMPLOYEE::edetail()
{
COMPANY::Input();
Branch::Enter();
cout << " Enter number of employees : ";
cin >> noemp;
}
void COMPANY::Output()
{
cout << " Company name : ";
puts(cname);
cout << " Head office's address : ";
puts(hdoffice);
cout << endl;

}
void Branch::Show()
{
cout << " Branch : ";
puts(bran);
cout << " Branch address : ";
puts(badd);
cout << " Branch number : ";
cout << bno << endl;
}
void EMPLOYEE::sdetail()
{
COMPANY::Output();
Branch::Show();
cout << " No. of employees: ";
cout << noemp;
}
void main()
{
clrscr();
EMPLOYEE E;
E.edetail();
E.sdetail();
getch();
}

Output

//WAP to pop an element from a link list


#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <process.h>
struct list
{
int detail;
list* cmg;
} * begn, *newptr, *store, *ptr, *last;
list* Create_List(int);
void put(list*);
void show(list*);
void dlnode();
void main()
{
clrscr();
begn = last = NULL;
int inf;
char ch = 'y';
while (ch == 'y' || ch == 'Y')
{
cout << " Enter the new node: ";

cin >> inf;


newptr = Create_List(inf);
if (newptr == NULL)
{
cout << "\nCan't create new node,Cancelling!\n";
exit(1);
}
put(newptr);
cout << " Press Y to enter,N to exit: ";
cin >> ch;
}
do
{
cout << " The list is :\n";
show(begn);
cout << " Do you want to delete 1st node?(y/n): ";
cin >> ch;
if (ch == 'Y' || ch == 'y')
dlnode();
} while (ch == 'Y' || ch == 'y');
}
list* Create_List(int n)
{
ptr = new list;
ptr->detail = n;
ptr->cmg = NULL;
return ptr;
}
void put(list* np)
{
if (begn == NULL)
begn = last = np;
else
{
last->cmg = np;

last = np;
}
}
void dlnode()
{
if (begn == NULL)
cout << "UNDERFLOW\n";
else
{
ptr = begn;
begn = begn->cmg;
delete ptr;
}
}
void show(list* np)
{
while (np != NULL)
{
cout << np->detail << "->";
np = np->cmg;
}
cout << "!?!\n";
}

Output

//WAP to show hierarchical inheritances in classes


#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
class School
{ char sname[20];
int ano;
protected:
char add[80];
public:
void Input();
void Output();
};
class Teachers : public School
{ int tno;

public:
void Enter();
void Show();
};
class Students : public School
{ int stno;
public:
void In();
void Out();
};
void School::Input()
{ cout << " Enter school name : ";
gets(sname);
cout << " Enter school address : ";
gets(add);
cout << " School authorise upto which class :";
cin >> ano;
}
void Teachers::Enter()
{ School::Input();
cout << " Enter number of teachers : ";
cin >> tno;
}
void Students::In()
{ School::Input();
cout << " Enter number of students : ";
cin >> stno;
}
void School::Output()
{ cout << "\n Details: \n";
cout << " School name : ";
puts(sname);
cout << " School's address : ";
puts(add);
cout << " Authorise upto class " << ano;

cout << endl;


}
void Teachers::Show()
{ School::Output();
cout << " Total number of teachers : ";
cout << tno << endl;
}
void Students::Out()
{ School::Output();
cout << " No. of students: ";
cout << stno;
}
void main()
{ clrscr();
char name[10];
cout << " In what way do you want to know about school :";
cout << "\n by teachers or students ? \n";
cout << " Please type here " << endl;
gets(name);
if (strcmpi(name, "teachers") == 0)
{ Teachers t;
t.Enter();
t.Show();
}
else if (strcmpi(name, "students") == 0)
{ Students s;
s.In();
s.Out();
}
else
{ cout << " No others means available\n";
cout << " If you want to know about the infrastructure or about any other things\n";
cout << " Please contact at reception";
}
getch();

Output

Das könnte Ihnen auch gefallen