Advertisement
Guest User

Untitled

a guest
Feb 10th, 2022
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #include <windows.h>
  2. #include <string>
  3. #include <iostream>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. char pred[5][25]= {"Математика", "Физика", "Химия", "Физкультура", "Русский язык"};
  9. int lekc[5]= {15,35,24,6,23};
  10. int prkt[5]= {2,4,8,10,3};
  11. int sem[5]= {1,1,1,2,3};
  12.  
  13. struct tDisc
  14. {
  15. char nameDisc[25]; //название дисциплины
  16. int numLec; //лекционных часов
  17. int numPract; //практических часов
  18. int numbSem; //номер семестра
  19. };
  20.  
  21. void Sort(tDisc *q, int n)
  22. {
  23. struct tDisc TempDisc;
  24.  
  25. for (int i = 0; i < n; i++)
  26. {
  27. for (int j = 0; j < n - i - 1; j++)
  28. {
  29. if (q[j].numPract < q[j + 1].numPract)
  30. {
  31. TempDisc = q[j];
  32. q[j] = q[j + 1];
  33. q[j + 1] = TempDisc;
  34. }
  35. }
  36. }
  37. }
  38. void OutList(tDisc *q, int n)
  39. {
  40. cout << setw(15) << "Предмет" << setw(10) << "Лекции" << setw(10);
  41. cout << "Практика" << setw(10) << "Семестр" << endl << endl;
  42. for (int i = 0; i < n; i++)
  43. {
  44. cout << setw(15) << q[i].nameDisc << setw(10) << q[i].numLec << setw(10);
  45. cout << q[i].numPract << setw(10) << q[i].numbSem << endl;
  46. }
  47. cout <<endl << endl;
  48. }
  49.  
  50. int main(int argc, char **argv)
  51. {
  52. system("chcp 1251 > nul"); // Руссификация сообщений
  53. setlocale(LC_ALL, "Russian");
  54.  
  55. const int n = 5;
  56. tDisc *aray = new tDisc[n*sizeof(tDisc)]; // Проверка на выделение памяти ОБЯЗАТЕЛЬНО
  57.  
  58. for (int i = 0; i < n; i++)
  59. {
  60. strcpy(aray[i].nameDisc, pred[i]) ;
  61. aray[i].numLec = lekc[i];
  62. aray[i].numPract = prkt[i];
  63. aray[i].numbSem = sem[i];
  64. }
  65.  
  66. OutList(aray,n);
  67.  
  68. Sort(aray, n);
  69.  
  70. OutList(aray,n);
  71.  
  72. delete [] aray;
  73.  
  74. system("pause"); // system("pause > nul");
  75. return 0;
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement