SaveText.Ru

Без имени
  1. #include<iostream>
  2. #include<iomanip>
  3. #include"student.h"
  4. #include"string.h"
  5. usingnamespacestd;
  6.  
  7. bool correct(intn, intvariant)
  8. {
  9. int counter = 1;
  10. int number = n;
  11. if (variant == 1)
  12.     {
  13. while ((number /= 10) > 0)counter++;
  14. if (counter <= 2 &&n> 0) returnfalse;
  15. elsereturntrue;
  16.     }
  17. if (variant == 2)
  18.     {
  19. while ((number /= 10) > 0)counter++;
  20. if (counter <= 4 &&n> 0) returnfalse;
  21. elsereturntrue;
  22.     }
  23. if (variant == 3)
  24.     {
  25. if (n == 0 || n == 1)returnfalse;
  26. elsereturntrue;
  27.     }
  28. }
  29.  
  30. char gender(boolg)
  31. {
  32. if (g) return'm';
  33. elsereturn'f';
  34. }
  35.  
  36. int main()
  37. {
  38. ios_base::left;
  39. structstudent students[10];
  40. inti, records = 0;
  41. char flag;
  42. cout<<setw(40) <<"Enter students data"<<endl;
  43. do
  44.     {
  45. cout<<"Student "<< records + 1 <<endl;
  46. cout<<"Enter family: ";
  47. cin>> students[records].fam;
  48. cout<<"Enter name: ";
  49. cin>> students[records].name;
  50. cout<<"Enter birthday day (dd): ";
  51. do {
  52. cin>> students[records].birthday.day;
  53.         } while (correct(students[records].birthday.day, 1));
  54. cout<<"Enter birthday month (mm): ";
  55. do {
  56. cin>> students[records].birthday.month;
  57.         } while (correct(students[records].birthday.month, 1));
  58. cout<<"Enter birthday yaer (yyyy): ";
  59. do {
  60. cin>> students[records].birthday.year;
  61.         } while (correct(students[records].birthday.year, 2));
  62. cout<<"Enter gender (1 - m; 0 - f): ";
  63. int gender;
  64. do {
  65. cin>> gender;
  66.         } while (correct(gender, 3));
  67. if (!correct(gender, 3)) students[records].gender = gender;
  68. records++;
  69. cout<<endl<<"Continue enter?(y/n)";
  70. cin>> flag;
  71. cout<<endl;
  72.     } while (flag == 'y');
  73.  
  74.  
  75. time_t now = time(0);
  76. tm* ltm = newtm;
  77. localtime_s(ltm, &now);
  78. boolgodnost;
  79. bool draftees = 0;
  80. intcurrentYear = ltm->tm_year + 1900;
  81. intcurrentMonth = ltm->tm_mon + 1;
  82. intcurrentDay = ltm->tm_mday;
  83. for (i = 0; i< records; i++)
  84.     {
  85. godnost = 0;
  86. if (currentYear> (students[i].birthday.year + 18))
  87. {
  88. godnost = 1;
  89.         }
  90. elseif (currentYear == (students[i].birthday.year + 18))
  91.         {
  92. if (currentMonth> (students[i].birthday.month))
  93.             {
  94. godnost = 1;
  95.             }
  96. elseif (currentMonth == (students[i].birthday.month))
  97. {
  98. if (currentDay> (students[i].birthday.day))
  99.                 {
  100. godnost = 1;
  101.                 }
  102.             }
  103.         }
  104. if (godnost&& students[i].gender)
  105.         {
  106. cout<<endl<<"Draftees:"<<endl;
  107. draftees = 1;
  108. cout<<setw(10) << students[i].fam <<setw(10) << students[i].name <<setw(10) << gender(students[i].gender) <<setw(10) << students[i].birthday.day<<'.'<<students[i].birthday.month<<'.'<<students[i].birthday.year<<endl;
  109.         }
  110.     }
  111. if (!draftees) cout<<"No draftees."<<endl;
  112. deleteltm;
  113. system("pause");
  114. }
  115.  
  116. Файл students.h:
  117. #pragmaonce
  118. #ifndef STUDENT_H
  119. #defineSTUDENT_H
  120. structdate
  121. {
  122.         int day;
  123.         int month;
  124.         int year;
  125. };
  126.  
  127. structstudent
  128. {
  129.         char name[20];
  130.         char fam[30];
  131.         bool gender;
  132.         structdate birthday;
  133. };
  134. #endif
  135.  

Share with your friends:

Print