Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct TDatum {
- int ev;
- int ho;
- int nap;
- };
- const int napDb[] = {31,29,31,30,31,30,31,31,30,31,30,31};
- bool HelyesHo(int x) {
- bool helyes;
- helyes = !cin.fail();
- if (helyes) {
- helyes = cin.peek()=='\n';
- }
- if (helyes) {
- helyes = x>=1 && x<=12;
- }
- else {
- cin.clear();
- string tmp;
- getline(cin,tmp,'\n');
- }
- if (!helyes) {
- cerr << "1 es 12 kozott\n";
- }
- return helyes;
- }
- bool HelyesNap(int x) {
- bool helyes;
- helyes = !cin.fail();
- if (helyes) {
- helyes = cin.peek()=='\n';
- }
- if (helyes) {
- helyes = x>=1 && x<=31;
- }
- else {
- cin.clear();
- string tmp;
- getline(cin,tmp,'\n');
- }
- if (!helyes) {
- cerr << "1 es 31 kozott\n";
- }
- return helyes;
- }
- void beolvasas(TDatum & d) {
- cerr << "Melyik ev:\n";
- cin >> d.ev;
- do {
- cerr << "Melyik honap(1-12):\n";
- cin >> d.ho;
- } while (!HelyesHo(d.ho));
- do {
- cerr << "Melyik nap(1-31):\n";
- cin >> d.nap;
- } while (!HelyesNap(d.nap));
- }
- int feldolgozas(TDatum d) {
- int hanyadik=0;
- for (int i=1; i<=d.ho-1;i++) {
- hanyadik += napDb[i-1];
- }
- hanyadik += d.nap;
- return hanyadik;
- }
- void kiiras(int hanyadik) {
- cerr << "Az ev ennyiedik napja: \n";
- cout << hanyadik << "\n";
- }
- int main() {
- TDatum d;
- int hanyadik;
- beolvasas(d);
- hanyadik = feldolgozas(d);
- kiiras(hanyadik);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement