Facebook
From Asad, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 291
  1. #include <iostream>
  2. using namespace std;
  3. class Date
  4. {
  5.     int day;
  6.     int month;
  7.     int year;
  8. public:
  9.     Date() : day(0), month(0), year(0) {}
  10.     void input()
  11.     {
  12.         cout << "Enter day: ";
  13.         cin >> day;
  14.         cout << "Enter month: ";
  15.         cin >> month;
  16.         cout << "Enter year: ";
  17.         cin >> year;
  18.     }
  19.     bool isValid()
  20.     {
  21.         if (month < 1 || month > 12)
  22.             return 0;
  23.         if (day < 1 || day > 31)
  24.             return 0;
  25.         if ((month == 4 || month == 6 || month == 9 || month == 11) && day > 30)
  26.             return 0;
  27.         if (month == 2)
  28.         {
  29.             if (year % 4 == 0)
  30.             {
  31.                 if (day > 29)
  32.                     return 0;
  33.             }
  34.             else
  35.             {
  36.                 if (day > 28)
  37.                     return 0;
  38.             }
  39.         }
  40.  
  41.         return 1;
  42.     }
  43. };
  44. int main()
  45. {
  46.     Date date;
  47.     date.input();
  48.     if (date.isValid())
  49.         cout << "Valid date." << endl;
  50.     else
  51.         cout << "Invalid date." << endl;
  52.     return 0;
  53. }#include <iostream>
  54. using namespace std;
  55. class Date
  56. {
  57.     int day;
  58.     int month;
  59.     int year;
  60. public:
  61.     Date() : day(0), month(0), year(0) {}
  62.     void input()
  63.     {
  64.         cout << "Enter day: ";
  65.         cin >> day;
  66.         cout << "Enter month: ";
  67.         cin >> month;
  68.         cout << "Enter year: ";
  69.         cin >> year;
  70.     }
  71.     bool isValid()
  72.     {
  73.         if (month < 1 || month > 12)
  74.             return 0;
  75.         if (day < 1 || day > 31)
  76.             return 0;
  77.         if ((month == 4 || month == 6 || month == 9 || month == 11) && day > 30)
  78.             return 0;
  79.         if (month == 2)
  80.         {
  81.             if (year % 4 == 0)
  82.             {
  83.                 if (day > 29)
  84.                     return 0;
  85.             }
  86.             else
  87.             {
  88.                 if (day > 28)
  89.                     return 0;
  90.             }
  91.         }
  92.  
  93.         return 1;
  94.     }
  95. };
  96. int main()
  97. {
  98.     Date date;
  99.     date.input();
  100.     if (date.isValid())
  101.         cout << "Valid date." << endl;
  102.     else
  103.         cout << "Invalid date." << endl;
  104.     return 0;
  105. }
  106. #include<iostream>
  107. using namespace std;
  108. class Student
  109. {
  110.     static int rollNo;
  111.     string name;
  112.     int age;
  113.     string studentClass;
  114. public:
  115.     Student() : name(""), age(0), studentClass("") {}
  116.     void input()
  117.     {
  118.         cout << "Enter name: ";
  119.         cin >> name;
  120.         cout << "Enter age: ";
  121.         cin >> age;
  122.         cout << "Enter class: ";
  123.         cin >> studentClass;
  124.         rollNo++;
  125.     }
  126.     void output()
  127.     {
  128.         cout << "Name: " << name << endl;
  129.         cout << "Age: " << age << endl;
  130.         cout << "Class: " << studentClass << endl;
  131.     }
  132.     static void printTotalStrength()
  133.     {
  134.         cout << "Total Strength: " << rollNo << endl;
  135.     }
  136. };
  137. int Student::rollNo = 0;
  138. int main()
  139. {
  140.     Student s1, s2, s3;
  141.     s1.input();
  142.     s2.input();
  143.     s3.input();
  144.     cout << "\nStudent 1 Details:" << endl;
  145.     s1.output();
  146.     cout << "\nStudent 2 Details:" << endl;
  147.     s2.output();
  148.     cout << "\nStudent 3 Details:" << endl;
  149.     s3.output();
  150.     Student::printTotalStrength();
  151.     return 0;
  152. }