Skip to main content

C++ 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).

#include
#include
#include
#include
#include

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: "<            cout<<"\n Address: "<            cout<<"\n Age: "<            cout<<"\n Department: "<            cout<<"\n Total Books to Issue: "<            cout<<"\n Book name: "<            }
        void Stu_Show(){
            cout<<"\n Student Details";
            cout<<"\n Name: "<            cout<<"\n Address: "<            cout<<"\n Age: "<            cout<<"\n Class: "<            cout<<"\n Total Books to Issue: "<            cout<<"\n Book 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

Comments

Popular posts from this blog

13 websites to register your free domain

Register your Free Domain Now!! 1)  .tk Dot TK is a FREE domain registry for websites on the Internet. It has exactly the same power as other domain extensions, but it’s free! Because it’s free, millions of others have been using .TK domains since 2001 – which makes .TK powerful and very recognizable.  Your website will be like www.yourdomainname.tk . It is free for 1 year. It’s a ccTLD domain whixh having the abbreviation  Tokelau. To create a .tk domain, Visit   www.dot.tk 2) co.cc Co.cc is completely free domain which is mostly used by blogspot bloggers because of it’s easy to use DNS system. Creating a co.cc for blogger is simple ( for instructions- “click here”). Your website will be like www.yourdomainname.co.cc . To create a .co.cc domain, visit www.co.cc 3)   co.nr co.nr is too like co.cc. Your website will be like  www.yourdomainname.co.nr . You can add it for blogger also.. To create a .co.cc domain, vi...

How to Put Google Adsense Below Post Title in Blogger?

Adsense is used by majority of expert bloggers for their website monetization because it is a cookie based contextual advertising system that shows targeted ads relevant to the content and reader. As bloggers are paid on per click basis, they try various ad placements on the blog to  increase the revenue  and get maximum clicks on the ad units. Well, on some blogs, you might have seen Adsense ad units placed below the post title. Do you know why? It is because the area just below the post title gets the most exposure and is the best place to put AdSense ad units to increase  Click Through Rate (CTR). Even though ads below post title work like a charm but this doesn’t mean that it will work for you as well. If you want to find out the best AdSense ads placement for your blog, try experimenting by placing ads at various locations such as header, sidebar, footer, etc. You can try other  blog monetization methods  as well to effectively monetize y...

12 Tips to Maintain a Virus Free Computer

1. Email is one of the common ways by which your computer can catch a virus . So it is always recommended to stay away from SPAM. Open only those emails that has it’s origin from a trusted source such as those which comes from your contact list. If you are using your own private email host (other than gmail, yahoo, hotmail etc.) " then it is highly recommended that you use a good anti-spam software. And finally NEVER click on any links in the emails that comes from untrusted sources. 2. USB thumb/pen drives is another common way by which viruses spread rapidly." So it is always a good habit to perform a virus scan before copying any data onto your computer. NEVER double-click the pen drive to open it. Instead right-click on it and select the option “open”. This is a safe way to open a pen drive. 3. Be careful about using MS Outlook. Outlook is more susceptible to worms than other e-mail programs, unless you have efficient Anti-Virus programs running. Use Pegasus ...