Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <exception>
- using namespace std;
- int def_day = 1;
- int def_month = 1;
- int def_year = 2018;
- class simpleDate{
- private:
- int day;
- int month;
- int year;
- public:
- //constructors
- simpleDate();
- explicit simpleDate(int);
- simpleDate(int, int);
- simpleDate(int, int, int);
- simpleDate(const simpleDate& x); // copy constructor
- simpleDate& operator = (const simpleDate&);
- void addDays(int days);
- void print();
- };
- simpleDate::simpleDate() : day(def_day), month(def_month), year(def_year){};
- simpleDate::simpleDate(int user_day) : month(def_month), year(def_year) {
- if(user_day<1 || user_day >31){
- cout<<"zly dzien lol"<<endl;
- }
- day=user_day;
- }
- simpleDate::simpleDate(int user_day, int user_month) : year(def_year) {
- if(user_day<1 || user_day >31){
- cout<<"zly dzien lol"<<endl;
- }
- if(user_month<1 || user_month>12){
- cout<<"zly miesiac lol"<<endl;
- }
- day=user_day;
- month = user_month;
- }
- simpleDate::simpleDate(int user_day, int user_month, int user_year){
- if(user_day<1 || user_day >31){
- cout<<"zly dzien lol"<<endl;
- }
- if(user_month<1 || user_month>12){
- cout<<"zly miesiac lol"<<endl;
- }
- if(user_year <2018 || user_year>2020){
- cout<<"zly rok lol"<<endl;
- }
- day=user_day;
- month=user_month;
- year= user_year;
- };
- simpleDate::simpleDate(const simpleDate& x){
- day=x.day;
- month=x.month;
- year=x.year;
- };
- simpleDate& simpleDate::operator=(const simpleDate& x) = default;
- void simpleDate::addDays(int days) {
- while(!days){
- if(days > 365) {
- year++;
- days -= 365;
- }
- if(days < -365)
- {
- year++;
- days +=365;
- }
- }
- //tu sb sami napiszcie bo nudy xd
- }
- void simpleDate::print(){
- cout<< year << '-' << month << '-' << day << endl;
- }
- int main(){
- simpleDate test(13,3);
- simpleDate copy(test);
- simpleDate kurrr = copy;
- test.print();
- copy.print();
- kurrr.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement