Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct TDatum {
  6.     int ev;
  7.     int ho;
  8.     int nap;
  9. };
  10.  
  11. const int napDb[] = {31,29,31,30,31,30,31,31,30,31,30,31};
  12.  
  13. bool HelyesHo(int x) {
  14.     bool helyes;
  15.     helyes = !cin.fail();
  16.     if (helyes) {
  17.         helyes = cin.peek()=='\n';
  18.     }
  19.     if (helyes) {
  20.         helyes = x>=1 && x<=12;
  21.     }
  22.     else {
  23.         cin.clear();
  24.         string tmp;
  25.         getline(cin,tmp,'\n');
  26.     }
  27.  
  28.  
  29.     if (!helyes) {
  30.         cerr << "1 es 12 kozott\n";
  31.     }
  32.     return helyes;
  33. }
  34.  
  35. bool HelyesNap(int x) {
  36.     bool helyes;
  37.     helyes = !cin.fail();
  38.     if (helyes) {
  39.         helyes = cin.peek()=='\n';
  40.     }
  41.     if (helyes) {
  42.         helyes = x>=1 && x<=31;
  43.     }
  44.     else {
  45.         cin.clear();
  46.         string tmp;
  47.         getline(cin,tmp,'\n');
  48.     }
  49.  
  50.  
  51.     if (!helyes) {
  52.         cerr << "1 es 31 kozott\n";
  53.     }
  54.     return helyes;
  55. }
  56.  
  57. void beolvasas(TDatum & d) {
  58.     cerr << "Melyik ev:\n";
  59.     cin >> d.ev;
  60.     do {
  61.         cerr << "Melyik honap(1-12):\n";
  62.         cin >> d.ho;
  63.     } while (!HelyesHo(d.ho));
  64.     do {
  65.         cerr << "Melyik nap(1-31):\n";
  66.         cin >> d.nap;
  67.     } while (!HelyesNap(d.nap));
  68. }
  69.  
  70. int feldolgozas(TDatum d) {
  71.     int hanyadik=0;
  72.     for (int i=1; i<=d.ho-1;i++) {
  73.         hanyadik += napDb[i-1];
  74.     }
  75.     hanyadik += d.nap;
  76.     return hanyadik;
  77. }
  78.  
  79. void kiiras(int hanyadik) {
  80.     cerr << "Az ev ennyiedik napja: \n";
  81.     cout << hanyadik << "\n";
  82. }
  83.  
  84. int main() {
  85.     TDatum d;
  86.     int hanyadik;
  87.     beolvasas(d);
  88.     hanyadik = feldolgozas(d);
  89.     kiiras(hanyadik);
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement