Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <stdlib.h>
- #include <stdio.h>
- using namespace std;
- struct students {
- string ime;
- string nomer;
- float srusp;
- int vuzrast;
- int pol;
- }per[30],M[30],F[30],temp[30],tempj[30];
- int broi;
- const int N = 30;
- int p;
- void create(struct students per[]);
- void sort(struct students per[],struct students M[],struct students F[]);
- void mladi(struct students per[],struct students F[], struct students temp[], struct students tempj[]);
- fstream fp;
- void main()
- {
- setlocale(LC_ALL, "bulgarian");
- struct students per[N];
- int menu;
- do{
- cout <<endl<<"1.Запис на студенти" << endl;
- cout << "2.Справка за мъже и жени!" << endl;
- cout << "3.Най-млада студентка и подреждане на данните във възходящ ред по възраст!" << endl;
- cout << "4.Изход!" << endl;
- cout << "Избери:" << endl;
- cin >> menu;
- switch (menu)
- {
- case 1:create(per); break;
- case 2:sort(per,M,F); break;
- case 3:mladi(per, F, temp, tempj); break;
- }
- } while (menu != 4);
- system("pause");
- }
- void create(struct students per[])
- {
- fp.open("file.txt", ios::out);
- cout << endl << "Въведете брой студенти(0-30)!" << endl;
- do{
- cin >> broi;
- } while (broi < 1 || broi>30);
- for (int i = 0; i < broi; i++)
- {
- cout << "Въведете данни за студент " << i + 1 << endl;
- cout << "Име:" << endl;
- getline(cin >> ws, per[i].ime);
- fp << "Име: " << per[i].ime << endl;
- cout << "Факултетен номер: " << endl;
- cin >> per[i].nomer;
- fp << "Факултетен номер: " << per[i].nomer << endl;
- do
- {
- cout << "Среден успех(2-6): " << endl;
- cin >> per[i].srusp;
- } while (per[i].srusp > 6 || per[i].srusp < 2);
- fp << "Среден успех: " << per[i].srusp << endl;
- cout << "Възраст: " << endl;
- cin >> per[i].vuzrast;
- fp << "Възраст: " << per[i].vuzrast << endl;
- cout << "Въведете пол(1-мъж/0-жена): " << endl;
- cin >> per[i].pol;
- fp << "Пол(1-muj/0-jena): " << per[i].pol << endl;
- }
- for (int i = 0; i < broi; i++)
- {
- cout << endl << "Име: " << per[i].ime;
- cout << endl << "Факултетен номер: " << per[i].nomer;
- cout << endl << "Среден успех: " << per[i].srusp;
- cout << endl << "Възраст: " << per[i].vuzrast;
- if (per[i].pol == 1)
- {
- cout << endl << "Пол: Мъж" << endl;
- }
- else
- {
- cout << endl << "Пол: Жена" << endl;
- }
- }
- fp.close();
- }
- void sort(struct students per[],struct students M[],struct students F[])
- {
- int br = 0;
- int num = 0;
- float sr = 0;
- float srj = 0;
- for (int i = 0; i < broi; i++)
- {
- if (per[i].pol == 1)
- {
- M[br] = per[i]; br++;
- }
- else
- {
- F[num] = per[i]; num++;
- }
- }
- cout << "Мъже: " << endl << endl;
- for (int i = 0; i < br; i++)
- {
- cout << "Име: " << M[i].ime << endl;
- cout << "Факултетен номер: " << M[i].nomer << endl;
- cout << "Среден успех: " << M[i].srusp << endl;
- cout << "Възраст: " << M[i].vuzrast << endl;
- cout << "Пол: Мъж " << endl << endl;
- sr += M[i].vuzrast;
- }
- cout << "Средна възраст на мъжете: " << sr / br << endl<<endl;
- cout << "Жени: " << endl;
- cout << "Брой на жените: " << num << endl;
- for (int i = 0; i < num; i++)
- {
- cout << "Име:" << F[i].ime << endl;
- cout << "Факултетен номер: " << F[i].nomer << endl;
- cout << "Среден успех: " << F[i].srusp << endl;
- cout << "Възраст: " << F[i].vuzrast << endl;
- cout << "Пол: Жена" << endl<<endl;
- srj += F[i].vuzrast;
- }
- cout << "Средна възраст на жените е: " << srj / num << endl;
- fp.close();
- }
- void mladi(struct students per[],struct students F[],struct students temp[], struct students tempj[])
- {
- int i;
- int x=0;
- int j;
- for (int i = 0; i < broi-1; i++)
- for (j = i + 1; j < broi;j++)
- if (per[i].vuzrast>per[j].vuzrast)
- {
- temp[x] = per[i];
- per[i] = per[j];
- per[j] = temp[x];
- }
- for (i = 0; i < p - 1; i++)
- for (j = i + 1; j < p;j++)
- if (F[i].vuzrast>F[j].vuzrast)
- {
- tempj[x] = F[i];
- F[i] = F[j];
- F[j] = tempj[x];
- }
- cout << "Най-млада студентка: " << endl;
- cout << "Име: " << F[0].ime << endl;
- cout << "Факултетен номер: " << F[0].nomer << endl;
- cout << "Среден успех: " << F[0].srusp << endl;
- cout << "Възраст: " << F[0].vuzrast << endl;
- cout << "Пол: Жена" << endl;
- cout <<endl<< "Възходящ ред по години:" << endl;
- for (int i = 0; i<broi; i++)
- {
- cout << "Име: " << per[i].ime << endl;
- cout << "Факултетен номер: " << per[i].nomer << endl;
- cout << "Среден успех: " << per[i].srusp << endl;
- cout << "Възраст: " << per[i].vuzrast << endl;
- if (per[i].pol == 1)
- {
- cout << "Пол: Мъж" << endl;
- }
- else
- {
- cout << "Пол: Жена" << endl<<endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement