Guest User

Untitled

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