Advertisements
Home > Cpp > C++ Program to implement Virtual Class by using Multipath Inheritance – Q23

C++ Program to implement Virtual Class by using Multipath Inheritance – Q23


Q23. Program to implement Virtual Class by using Multipath Inheritance:

Issue the books to various members of library.
– Member-Membername, Age, Address
– Faculty (derived from member classs)- Department and integer type array for issuing books with upperlimit 10.
– Student (derived from member class)- Class, Rollno and integer type array for issuing books with upperlimit 4.
Daily Transaction (derived from Faculty and Student classes)- date of issue, date of return (calculated from date of issue as 15 days for students and 45 days for a faculty).

… from College notes (BCA/MCA assignments):

#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <dos.h>

class CDATE{
	private:
		int dd;
		int mm;
		int yy;
	public:
		struct date d;
		CDATE(){
			getdate(&d);
			dd = d.da_day;
			mm = d.da_mon;
			yy = d.da_year;
			}
		CDATE(int d, int m, int y){
			dd = d;
			mm = m;
			yy = y;
			}
	};

class CMember{
	protected:
		char m_name[20], m_add[30];
		int m_age;
	public:
		CMember(){}
		CMember(char *Mnam, char *Madd, int Mage){
			strcpy(m_name, Mnam);
			strcpy(m_add, Madd);
			m_age = Mage;
			}
	};

class CFaculty : public virtual CMember{
	protected:
		char f_dept[20];
		int f_bk_issue;
	public:
		CFaculty(){}
		CFaculty(char *Fdept, int Fiss){
			strcpy(f_dept, Fdept);
			f_bk_issue = Fiss;
			}
	};

class CStudent : public virtual CMember{
	protected:
		char s_clas[10];
		int s_roll, s_bk_issue;
	public:
		CStudent(){}
		CStudent(char *Sclas, int Sroll, int Siss){
			strcpy(s_clas, Sclas);
			s_roll = Sroll;
			s_bk_issue = Siss;
			}
	};

class CTrans: public CFaculty , public CStudent{
	private:
		CDATE dt;
		int dayStu;
		int dayFac;
		char bk_name[20];
	public:
		CTrans(){
			dayStu = 15;
			dayFac = 45;
			}
		CTrans(char *Tnam, char *Tadd, int Tage, char *Tdept,
			  int Tiss, char *Tbk_nam, CDATE Tdoi)
		: CMember(Tnam, Tadd, Tage), CFaculty(Tdept, Tiss){
			strcpy(bk_name, Tbk_nam);
			dt = Tdoi;
			}
		CTrans(char *Tnam, char *Tadd, int Tage, char *Tclas,
			  int Troll, int Tiss, char *Tbk_nam, CDATE Tdoi)
		: CMember(Tnam, Tadd, Tage), CStudent(Tclas, Troll, 
Tiss){
			strcpy(bk_name, Tbk_nam);
			dt = Tdoi;
			}
		void Fac_Show(){
			cout<<"\n Faculty Details";
			cout<<"\n Name: "<<m_name;
			cout<<"\n Address: "<<m_add;
			cout<<"\n Age: "<<m_age;
			cout<<"\n Department: "<<f_dept;
			cout<<"\n Total Books to Issue: "<<f_bk_issue;
			cout<<"\n Book name: "<<bk_name;
			}
		void Stu_Show(){
			cout<<"\n Student Details";
			cout<<"\n Name: "<<m_name;
			cout<<"\n Address: "<<m_add;
			cout<<"\n Age: "<<m_age;
			cout<<"\n Class: "<<s_clas;
			cout<<"\n Total Books to Issue: "<<s_bk_issue;
			cout<<"\n Book name: "<<bk_name;
			}
	};

void main(){
	int ch;
	char book_name[20];
	CTrans ObjLib;
	while(1){
		clrscr();
		cout<<"\n LIBRARY MANAGEMANT";
		cout<<"\n ~~~~~~~~~~~~~~~~~~";
		cout<<"\n 1 -> Issue Books to Faculty.";
		cout<<"\n 2 -> Issue Books to Student.";
		cout<<"\n 3 -> Show Details of Faculty.";
		cout<<"\n 4 -> Show Details of Student.";
		cout<<"\n 5 -> EXIT.";
		cout<<"\n Enter your choice: ";
		cin>>ch;
		switch(ch){
			case 1:
				cout<<"\n Enter Book Name: ";
				cin>>book_name;
				CDATE dt1(5, 10, 2004);
				CTrans Olib1("Manoj", "Dwarka", 23, 
"Computer", 15, book_name, dt1);
				break;
			case 2:
				cout<<"\n Enter Book Name: ";
				cin>>book_name;
				CDATE dt2(5, 10,2004);
				CTrans Olib2("Nitin", "Dwarka", 24, "MCA", 
   214, 5, book_name, dt2);
				break;

			case 3:
				ObjLib.Fac_Show();
				break;
			case 4:
				ObjLib.Stu_Show();
				break;
			default:
				exit(1);
			} // end of switch.
		getch();
		} // end of while.
	} // end of main.

 

Output:

LIBRARY MANAGEMANT: –
~~~~~~~~~~~~~~~
1 -> Issue Books to Faculty.
2 -> Issue Books to Student.
3 -> Show Details of Faculty.
4 -> Show Details of Student.
5 -> EXIT.
Enter your choice: 2

Name: Manoj
Address: Dwarka
Age: 23
Course: MCA
Enter Book Name: c plus plus

 

LIBRARY MANAGEMANT: –
~~~~~~~~~~~~~~~
1 -> Issue Books to Faculty.
2 -> Issue Books to Student.
3 -> Show Details of Faculty.
4 -> Show Details of Student.
5 -> EXIT.
Enter your choice: 4

Student Details: –
Name: Manoj
Address: Dwarka
Age: 23
Course: MCA
Total Books to Issue: 4
Book name: CPP


Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: