Archive

Archive for January 22, 2010

C++ Program to implement Multiple Inheritance – Q22

January 22, 2010 Leave a comment

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


Advertisement