Answer the question
In order to leave comments, you need to log in
What needs to be done in order to first check the elements of the struct by condition and then throw them into one array?
#include <iostream>
#include <string>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
struct str
{
char fam[12];
char im[12];
char ot[12];
char country[12];
char city[12];
int ocenka[4];
double so;
}mstud[100];
int nst, i, j;
cout << "Введите количество абитуриентов поступивших в университет: " << endl;
cin >> nst;
for (i = 0; i < nst; i++)
{
cout << "Введите фамилию: ";
cin >> mstud[i].fam;
cout << "Введите имя: ";
cin >> mstud[i].im;
cout << "Введите отчество: ";
cin >> mstud[i].ot;
cout << "Введите страну: ";
cin >> mstud[i].country;
cout << "Введите город: ";
cin >> mstud[i].city;
cout << "Введите оценки: ";
mstud[i].so = 0; // Средний балл
for (j = 0; j < 4; j++)
{
cin >> mstud[i].ocenka[j];
mstud[i].so += mstud[i].ocenka[j] / 4;
}
cout << endl;
}
char* a = new char[nst];
int k = 0;
char g;
for (i = 0; i < nst; i++) // Проверка условия и сбор элементов структуры в массив
{
if (strcmp(mstud[i].city,"Минск") == 0 && mstud[i].so >= 4.5)
{
a[k] = mstud[i].fam;
k++;
}
}
for (i = 0; i < k; i++) // Алфавитный порядок
{
for (j = 0; j < k; j++)
{
if (a[i] < a[j])
{
g = a[j];
a[j] = a[i];
a[i] = g;
}
}
}
cout << "Колличество абитуриентов из Минска: " << k;
for (i = 0; i < k; i++)
{
cout << a[i];
}
return 0;
}
Answer the question
In order to leave comments, you need to log in
I would advise you to remake the structure, instead of char arrays, make string. And instead of an array, make a vector. Oh, you have an error because you want to assign an array of chars to one char.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question