Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <string>
- #include <iostream>
- #include <iomanip>
- using namespace std;
- char pred[5][25]= {"Математика", "Физика", "Химия", "Физкультура", "Русский язык"};
- int lekc[5]= {15,35,24,6,23};
- int prkt[5]= {2,4,8,10,3};
- int sem[5]= {1,1,1,2,3};
- struct tDisc
- {
- char nameDisc[25]; //название дисциплины
- int numLec; //лекционных часов
- int numPract; //практических часов
- int numbSem; //номер семестра
- };
- void Sort(tDisc *q, int n)
- {
- struct tDisc TempDisc;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n - i - 1; j++)
- {
- if (q[j].numPract < q[j + 1].numPract)
- {
- TempDisc = q[j];
- q[j] = q[j + 1];
- q[j + 1] = TempDisc;
- }
- }
- }
- }
- void OutList(tDisc *q, int n)
- {
- cout << setw(15) << "Предмет" << setw(10) << "Лекции" << setw(10);
- cout << "Практика" << setw(10) << "Семестр" << endl << endl;
- for (int i = 0; i < n; i++)
- {
- cout << setw(15) << q[i].nameDisc << setw(10) << q[i].numLec << setw(10);
- cout << q[i].numPract << setw(10) << q[i].numbSem << endl;
- }
- cout <<endl << endl;
- }
- int main(int argc, char **argv)
- {
- system("chcp 1251 > nul"); // Руссификация сообщений
- setlocale(LC_ALL, "Russian");
- const int n = 5;
- tDisc *aray = new tDisc[n*sizeof(tDisc)]; // Проверка на выделение памяти ОБЯЗАТЕЛЬНО
- for (int i = 0; i < n; i++)
- {
- strcpy(aray[i].nameDisc, pred[i]) ;
- aray[i].numLec = lekc[i];
- aray[i].numPract = prkt[i];
- aray[i].numbSem = sem[i];
- }
- OutList(aray,n);
- Sort(aray, n);
- OutList(aray,n);
- delete [] aray;
- system("pause"); // system("pause > nul");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement