Advertisement
AntoniiaG

Person

Jan 25th, 2023 (edited)
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.16 KB | Source Code | 0 0
  1. // ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. class Date
  8. {
  9. private:
  10.     int day;
  11.     int month;
  12.     int year;
  13.  
  14. public:
  15.     Date()
  16.     {
  17.         day = 0;
  18.         month = 0;
  19.         year = 0;
  20.     }
  21.  
  22.     void setDay(int d)
  23.     {
  24.         if (d < 1 && d > 32) {
  25.             cout << "Invalide day!" << endl;
  26.         }
  27.         else {
  28.             d = day;
  29.         }
  30.     }
  31.  
  32.     void setMonth(int m)
  33.     {
  34.         if (m < 1 && m > 12) {
  35.             cout << "Invalide month!" << endl;
  36.         }
  37.         else {
  38.             m = month;
  39.         }
  40.     }
  41.  
  42.     void setYear(int y)
  43.     {
  44.         if (y < 1990 && y > 2023)
  45.         {
  46.             cout << "Invalide year!" << endl;
  47.         }
  48.         else
  49.         {
  50.             y = year;
  51.         }
  52.     }
  53.  
  54.     void showDate()
  55.     {
  56.         string monthName[] = { "January", "February", "March", "April",
  57.             "May", "June", "July", "August", "September", "October",
  58.             "November", "Decenber" };
  59.         if (monthName[month - 1] == "February") {
  60.             if (year % 400 == 0) {
  61.                 // cout << year << " is a leap year.";
  62.                 if (day < 1 && day > 30) {
  63.                     cout << "Invalid day!";
  64.                 }
  65.                 else {
  66.                     cout << day << " " << monthName[month - 1] << " " << year << endl;
  67.                 }
  68.             }
  69.             else {
  70.                 //cout << year << " is not a leap year.";
  71.                 if (day < 1 && day > 29) {
  72.                     cout << "Invalid day!";
  73.                 }
  74.                 else {
  75.                     cout << day << " " << monthName[month - 1] << " " << year << endl;
  76.                 }
  77.             }
  78.         }
  79.     }
  80.  
  81. };
  82.  
  83. class Person
  84. {
  85. private:
  86.     string name;
  87.     string qualification;
  88.     Date date;
  89.  
  90. public:
  91.     Person()
  92.     {
  93.         name = "";
  94.         qualification = "";
  95.     }
  96.     Person(string Name, string Qualification)
  97.     {
  98.         Name = name;
  99.         Qualification = qualification;
  100.     }
  101.  
  102.     void setName(string names)
  103.     {
  104.         names = name;
  105.     }
  106.  
  107.     string getName()
  108.     {
  109.         return name;
  110.     }
  111.  
  112.     void setQualification(string quality)
  113.     {
  114.         quality = qualification;
  115.     }
  116.  
  117.     string getQualificattion()
  118.     {
  119.         return qualification;
  120.     }
  121.  
  122.     void setDate()
  123.     {
  124.         date.showDate();
  125.         cout << endl;
  126.     }
  127. };
  128.  
  129. int main()
  130. {
  131.     string names, quality;
  132.     int persons = 0;
  133.     Person p;
  134.     Date d;
  135.     cout << "Enter how many persons do you want to check:";
  136.     cin >> persons;
  137.     cout << endl;
  138.  
  139.     for (int i = 1; i <= persons; i++)
  140.     {
  141.         cout << "Enter name of person: ";
  142.         cin >> names;
  143.         cout << endl;
  144.         cout << "Enter qualification: ";
  145.         cin >> quality;
  146.         cout << endl;
  147.         cout << "Enter birthday DD/MM/YYYY:";
  148.         int day, month, year;
  149.         cin >> day >> month >> year;
  150.         cout << endl;
  151.         cout << day << "  " << monthName[month - 1] << "  " << year << endl;
  152.         cin.get();
  153.         cout << endl;
  154.     }
  155.  
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement