Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Data.h
- #pragma once
- using namespace std;
- class Data
- {
- public:
- Data();
- ~Data();
- private:
- int m_nDzien;
- int m_nMiesiac;
- int m_nRok;
- public:
- void Ustaw(int d, int m, int r);
- int Dzien() const;
- int Miesiac() const;
- int Rok() const;
- // wypisuje date w postaci dzien-miesiac-rok
- void Wypisz() const;
- // wprowadza dane skladowe ze standardwoego strumienia wejsciowego
- void Wpisz();
- // poprawia date na najblizsza wlasciwa
- void Koryguj();
- bool Porownaj(const Data & wzor) const;
- };
- //Data.cpp
- #include "Data.h"
- #include <iostream>
- using namespace std;
- Data::Data()
- : m_nDzien(0)
- , m_nMiesiac(0)
- , m_nRok(0)
- {
- }
- Data::~Data()
- {
- }
- void Data::Ustaw(int d, int m, int r)
- {
- //if (d > 0 && d < 32 || m > 0 && m < 13 ||
- // r > 1900 && r < 2100)
- //{
- m_nDzien = d;
- m_nMiesiac = m;
- m_nRok = r;
- //}
- //else
- //cout << "BLAD, NIEPOPRAWNE DANE" << endl;
- void Koryguj();
- }
- int Data::Dzien() const
- {
- return m_nDzien;
- }
- int Data::Miesiac() const
- {
- return m_nMiesiac;
- }
- int Data::Rok() const
- {
- return m_nRok;
- }
- // wypisuje date w postaci dzien-miesiac-rok
- void Data::Wypisz() const
- {
- cout << m_nDzien << "-" << m_nMiesiac << "-" << m_nRok << endl;
- }
- // wprowadza dane skladowe ze standardwoego strumienia wejsciowego
- void Data::Wpisz()
- {
- cout << "PODAJ DZIEN" << endl;
- cin >> m_nDzien;
- cout << "PODAJ MIESIAC" << endl;
- cin >> m_nMiesiac;
- cout << "PODAJ ROK" << endl;
- cin >> m_nRok;
- }
- // poprawia date na najblizsza wlasciwa
- void Data::Koryguj()
- {
- if ((m_nRok % 4) == 0 || (m_nRok % 100) != 0) //rok przestepny
- {
- if (m_nMiesiac == 2)
- {
- if (m_nDzien < 1)
- m_nDzien = 1;
- if (m_nDzien > 29)
- m_nDzien = 29;
- }
- else if ((m_nMiesiac % 2) == 0)
- {
- if (m_nDzien < 1)
- m_nDzien = 1;
- if (m_nDzien > 30)
- m_nDzien = 30;
- }
- else if ((m_nMiesiac % 2) != 0)
- {
- if (m_nDzien < 1)
- m_nDzien = 1;
- if (m_nDzien > 31)
- m_nDzien = 31;
- }
- }
- //rok nieprzestepny
- else
- {
- if (m_nMiesiac == 2)
- {
- if (m_nDzien < 1)
- m_nDzien = 1;
- if (m_nDzien > 28)
- m_nDzien = 28;
- }
- else if ((m_nMiesiac % 2) == 0)
- {
- if (m_nDzien < 1)
- m_nDzien = 1;
- if (m_nDzien > 30)
- m_nDzien = 30;
- }
- else if ((m_nMiesiac % 2) != 0)
- {
- if (m_nDzien < 1)
- m_nDzien = 1;
- if (m_nDzien > 31)
- m_nDzien = 31;
- }
- }
- }
- bool Data::Porownaj(const Data & wzor) const
- {
- if (m_nDzien == wzor.m_nDzien && m_nMiesiac == wzor.m_nMiesiac
- && m_nRok == wzor.m_nRok)
- return true;
- else
- return false;
- }
- //main
- #include <iostream>
- #include "Data.h"
- using namespace std;
- void main()
- {
- Data d1, wzor;
- d1.Ustaw(13, 07, 1992);
- d1.Wypisz();
- wzor.Ustaw(13, 07, 1999);
- cout << d1.Porownaj(wzor);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement