Advertisements
Home > Cpp > C++ Program to implement Multiple Inheritance – Q22

C++ Program to implement Multiple Inheritance – Q22


Q22. Program to implement Multiple Inheritance:

Display the digital clock using multiple inheritance. Using a time and date class, for deriving the class digiclock. Use appropriate functions to increment date and time.

… from College notes (BCA/MCA assignments):

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

class CDate{
	protected:
		int dd, mm, yy;
		struct date d;
	public:
		void initDate(){
			getdate(&d);
			dd = d.da_day;
			mm = d.da_mon;
			yy = d.da_year;
			}
		void showDate(){
			initDate();
			cout<<dd<<" / "<<mm<<" / "<<yy;
			}
	};

class CTime{
	protected:
		int hrs, min, sec;
		struct time t;
	public:
		void initTime(){
			gettime(&t);
			hrs = t.ti_hour;
			min = t.ti_min;
			sec = t.ti_sec;
			}
		void showTime(){
			initTime();
			cout<<hrs<<" : "<<min<<" : "<<sec;
			}
	};

class CDigiClock : public CDate, public CTime{
	public:
		CDigiClock(){
			showDate();
			cout<<"\t";
			showTime();
			}
	};

void main(){
	clrscr();
	cout<<" Current Date and Time is : - \n";
	while(!kbhit()){
		gotoxy(5, 5);
		CDigiClock();
		}
	}

 

Output:

Current Date and Time is : –

18 / 11 / 2004 21 : 55 : 51


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: