1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
#include<conio.h>
#include<iostream>
#include<cstdlib>
#include<vector>
using namespace std;
// Base class
class appointment
{
public:
char*description;
// Declare structure date
struct date
{
int y,m,d;
};
// Create an object of the structure date
date dt;
int time;
public:
appointment()
{
}
appointment(int d, int m, int y)
{
// three argument construct for setting the appointment date
dt.y=y;
dt.m=m;
dt.d=d;
}
// declare a virtual function using three variable of integers as an argument
virtual char*occurs_on(int yr, int month, int day){};
};
// Class publicly derived from appointment
class OneTime:public appointment
{
public:
// Declares a default constructor to initialize the object of the class
OneTime(){}
OneTime(int d, int m, int y)
{
dt.y=y;
dt.m=m;
dt.d=d;
}
// defines the virtual function
char*occurs_on(int yr, int month, int day)
{
// check the condition if the day, month and yr is the same value of day
// month and year enter by user.
// Then stores the check value in the description.
if(dt.d==day&&dt.m==month&&dt.y==yr)
{
description="one Time check up";
}
else
{
description="\0";
}
// return the description
return description;
}
};
// Implements a class Daily for showing the daily appointments
// that's publically derived from the base class appointment
class Daily:public appointment
{
// declares a default constructor to initialize the value of class objects
Daily(){}
// Declares a parameter constructor using three variables of integer arguments
Daily(int d, int m, int y)
{
// sets the appointment
dt.y=y;
dt.m=m;
dt.d=d;
}
// Define the virtual function for the derived class
char*occurs_on(int yr, int month, int day)
{
// check the condition if the day, month and yr is the same value of day
// month and year enter by user.
// Then stores the check value in the description.
if(dt.d==day&&dt.m==month&&dt.y==yr)
{
description="daily appointment";
}
else
{
description="\0";
}
// returns the value of the description
return description;
}
};
// Implements class Weekly for showing the weekly appointments
// Class is derived from base class appointment
class Weekly:public appointment
{
public:
// Declares the default constructor to initialize teh objects of the class
Weekly(){}
// Declares parameters of constructo taking three variables of integers for arguments
Weekly(int d, int m, int y)
{
dt.y=y;
dt.m=m;
dt.d=d;
}
// checks the type of appointment by comparing the date
char*occurs_on(int yr, int month, int day)
{
// declares a variable of integer data type
int b;
// check the condition if the day, month and yr is the same value of day
// month and year enter by user.
// Then stores the check value in the description.
if(dt.d==day&&dt.m==month&&dt.y==yr)
{
description="weekly appointment";
}
else
{
description="\0";
}
return description;
}
};
// Implement a class monthly for showing the monthly appointmnet which is
// publically derived from the base class appointment
class Monthly:public appointment
{
public:
// Declares a default constructor to initialize the objects of the class
Monthly(){}
Monthly(int d, int m, int y)
{
// constructor set the appointment date
dt.y=y;
dt.m=m;
dt.d=d;
}
// checks the type of appointment
char*occurs_on(int yr,int month,int day)
{
// check the condition if the day, month and yr is the same value of day
// month and year enter by user.
// Then stores the check value in the description.
if(dt.d==day&&dt.m==month&&dt.y==yr)
{
description="monthly appointment";
}
else
{
description="\0";
}
return description;
}
};
// main function of the program
int main()
{
// declares four variable integer data types to display day, month and year
int x;
int dy,mn,ye;
char*ar[4];
// vector of base class appointment
vector<app> app(6);
// creates object of derived class OneTime and assigns the value
app[0]=new OneTime(8,28,2013);
// creates object of derived class daily and show daily appointments and assigns value in it
app[1]=new Daily(8,29,2013);
// creates object of the derived class weekly and shows appointments and assigns value in it
app[2]=new Weekly(9,1,2013);
// creates object of derived class monthly and show monthly appointments and assigns value in it
app[3]=new Monthly(p,2,2013);
// creates object of derived class OneTime and assigns the value in it
app[4]=new OneTime(9,2,2013);
// creates an object of the derived class Monthly it show the monthly appointments and assigns value in it
app[5]=new Monthly(9,2,2013);
// Enters the value of day, month and year from the user
cout<<"enter day\t";
cin>>dy;
cout<<"enter month\t";
cin>>mn;
cout<<"enter year\t";
cin>>ye;
for(int i-0;i<6;i++)
{
// calls the virtual function and stores values of day, month and year in the array
ar[i]=app[i]->occurs_on(ye,mn,dy);
}
// declares a variable of integer data type intialized at 0
int i=0;
while(i<4)
{
if(ar[i]!="\0")
{
cout<<"ar["<<i<<"]="<<ar[i];
}
i++;
}
getch();
return 0;
}
|