Professional Documents
Culture Documents
#include<iostream>
#include<string>
struct BDate
int m, d, y;
};
class SDate
private:
BDate BD;
public:
void getData()
getline(cin, name);
getline(cin, address);
char Check()
if (BD.d > 0 && BD.d < 32 && BD.m < 13 && BD.m>0 && BD.y>1899 && BD.y < 2020)
return 'y';
else
return 'n';
}
void ifNotValidDate()
void print()
cout << "BirthDate : " << BD.d << '/' << BD.m << '/' << BD.y << endl;
};
int main()
SDate S;
S.getData();
S.Check();
S.ifNotValidDate();
S.print();
system("pause");
return 0;
}
Q2
#include<iostream>
class Time
private:
public:
Time()
hours = 0;
minutes = 0;
seconds = 0;
hours = h;
minutes = m;
seconds = s;
Time(Time& T1)
hours = T1.hours;
minutes = T1.minutes;
seconds = T1.seconds;
cout << hours << ':' << minutes << ':' << seconds << endl;
}
void showTime2()
cout << hours++ << ':' << minutes++ << ':' << seconds-- << endl;
};
int main()
Time T1,T2(T1);
T1.showTime();
T2.showTime();
T3.showTime();
T4.showTime();
T1.showTime2();
T2.showTime2();
//T3.showTime2(); not valid because it's const obj and the fn does change the value of var
//T4.showTime2();
system("pause");
return 0;
}
Q3
#include<iostream>
#include<string>
class item
string name;
char ws;
public:
item()
code = serial;
serial += 1000;
void setData()
getline(cin,name);
ws = cin.get();
void showSerial()
}
void showData()
};
int main()
item I[5];
I[i].setData();
I[i].showSerial();
I[i].showData();
system("pause");
return 0;