Advertisement
AndreyKlipikov

Prog. Lab 8. N21

Feb 13th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.28 KB | None | 0 0
  1. #include "iostream"
  2. #include "conio.h"
  3.  
  4. using namespace std;
  5. const int people = 3;
  6. const int subjects = 3;
  7.  
  8. struct T_date
  9. {
  10.     unsigned day;      
  11.     unsigned month;    
  12.     unsigned year;
  13. };
  14.  
  15. struct T_subject
  16. {
  17.     char name[40];
  18.     int unsigned mark;
  19. };
  20.  
  21. struct T_student
  22. {
  23.     char fio[40];
  24.     T_date birthday;
  25.     T_subject certificate[subjects];
  26. };
  27.  
  28. T_student add_struct(int i)
  29. {
  30.     T_student a;
  31.     char c;
  32.     cout << endl << "Enter data " << i+1 << " person\n";
  33.     cout << " fio ";
  34.     cin.getline(a.fio,40);
  35.     cout << endl << "Enter date of birthday: \n";
  36.     cout <<" day (1-31) ";
  37.     cin >> a.birthday.day;
  38.     cin.get(c);
  39.     cout << " month (1-12) ";
  40.     cin >> a.birthday.month;
  41.     cin.get(c);
  42.     cout << " year (YYYY) ";
  43.     cin >> a.birthday.year;
  44.     cin.get(c);
  45.     cout << endl << "List of subjects: Math, Phys, Rus, etc" << endl;
  46.     for(int i = 0; i < subjects; i++)
  47.     {
  48.         cout << "\nEnter " << i+1 << " subject name: ";
  49.         cin.getline(a.certificate[i].name,40);
  50.         cout << "   subject mark: ";
  51.         cin >> a.certificate[i].mark;
  52.         cin.get(c);
  53.     }
  54.     return a;
  55. };
  56.  
  57. void write_table(T_student a)
  58. {
  59.     printf("%15s ! %2d %2d %4d ", a.fio, a.birthday.day, a.birthday.month, a.birthday.year);
  60.     for(int i = 0; i < subjects; i++)
  61.         printf("! %4s ! %1d    ", a.certificate[i].name, a.certificate[i].mark);
  62.     printf("\n");
  63. }
  64.  
  65. void write_result_table(T_student a)
  66. {
  67.     bool math_true = false, phys_true = false;
  68.  
  69.     for(int i = 0; i < subjects; i++)
  70.     {
  71.         if (strcmp(a.certificate[i].name, "Math") == 0 && a.certificate[i].mark > 3)
  72.             math_true = true;
  73.        
  74.         if (strcmp(a.certificate[i].name, "Phys") == 0 && a.certificate[i].mark > 3)
  75.             phys_true = true;
  76.     }
  77.  
  78.     if(phys_true && math_true)
  79.         printf("%15s ! %1d        ! %1d\n", a.fio, a.certificate[0].mark, a.certificate[1].mark);
  80. }
  81.  
  82. int main()
  83. {
  84.     cout << "       Avtor – Klipikov A. V., student gr. PIbd-11" << endl;
  85.     cout << "       Variant N 21" << endl;
  86.     cout << "       Programma sozdaet massiv structur, zapolnaet ego dannimi i vivodit na ekran etot massiv v vide tablici"  << endl;
  87.     cout << "       Programma vivodit massiv abiturientov, imeuschih po matematike i fizike ne nizhe 4, v vide tablici"  << endl << endl;
  88.  
  89.     T_student list[people] = {"Klipikov A. V.", 29, 5, 1995, "Math", 4, "Phys", 5, "Rus", 5,
  90.                                 "Ivanov I.I.", 1, 1, 1995, "Math", 3, "Phys", 3, "Rus", 3};
  91.     for(int i = 2; i < people; i++)
  92.     {  
  93.         list[i] = add_struct(i);
  94.     }
  95.  
  96.     cout << "-----------------------------";
  97.     for(int i = 0; i < subjects; i++)
  98.         cout << "--------------";
  99.     cout << endl << "                !            !         certificate";
  100.     cout << endl << "      fio       !  birthday  ";
  101.     for(int i = 0; i < subjects; i++)
  102.         cout << "--------------";
  103.     cout << endl << "                !            ";
  104.     for(int i = 0; i < subjects; i++)
  105.         cout << "! name ! mark ";
  106.     cout << endl << "-----------------------------";
  107.     for(int i = 0; i < subjects; i++)
  108.         cout << "--------------";
  109.     cout << endl;
  110.  
  111.     for(int i = 0; i < people; i++)
  112.     {  
  113.         write_table(list[i]);
  114.     }
  115.  
  116.     cout << endl << endl;
  117.  
  118.     cout << "---------------------------------------" << endl;
  119.     cout << "      fio       !   Math   !   Phys   !" << endl;
  120.     cout << "---------------------------------------" << endl;
  121.  
  122.     for(int i = 0; i < people; i++)
  123.     {  
  124.         write_result_table(list[i]);
  125.     }
  126.  
  127.     _getch();
  128.     return 0;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement