Добавил:
wso_studf
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
struct student
{
string name;
int kurs;
float rating;
};
void make_arr(student students[], int n);
void print_struct(student students[], int n);
void search_n(vector <string> search_names, int n);
void rating_s(student students[], int n);
int main(){
setlocale(LC_ALL, "Russian");
setlocale(LC_NUMERIC, "POSIX");
cout << "Вариант №3" << endl;
cout << "Лабораторная работа №14" << endl;
int n = 15; // количество записей в файле
student students[n];
vector <string> search_names;
make_arr(students, n);
print_struct(students, n);
search_n(search_names, n);
rating_s(students, n);
return 0;
}
void make_arr(student students[], int n){
vector <string> str;
vector <string> split_strings;
string tmp;
ifstream in("Input_14_lab.txt");
for (int i = 0; i < n; i++){
getline(in, tmp);
str.push_back(tmp);
}
in.close();
string s, temp;
for (int k = 0; k < n; k++){
s = str[k];
// cout << s << endl;
int i = 0;
int begin = 0, end;
for (i = s.find(", ", i++); i != string::npos; i = s.find(", ", i + 1)){
end = i;
temp = s.substr(begin, end);
begin = i + 2;
split_strings.push_back(temp);
}
temp = s.substr(begin, -1);
split_strings.push_back(temp);
}
int l = 0;
for (int i = 0; i < split_strings.size(); i += 3){
students[l].name = split_strings[i];
students[l].kurs = 1;
students[l].rating = stof(split_strings[i + 2]);
l++;
}
}
void search_n(vector <string> search_names, int n){
string temp;
vector <string> s_name {"Бейкер", "Канижа"};
cout << endl;
ifstream in("Input_14_lab.txt");
for (int i = 0; i < n; i++){
getline(in, temp);
int k = 0;
while (k < s_name.size()){
if (temp.find(s_name[k]) == 0){
cout << "Выполнен поиск по фамилии: " << s_name[k] << endl;
cout << "Найдено: " << temp << endl;
search_names.push_back(temp);
}
k++;
}
}
in.close();
ofstream fout;
fout.open("Search.txt", std::ios::trunc);
for (int i = 0; i < search_names.size(); i++){
fout << search_names[i] << "\n";
}
fout.close();
}
void print_struct(student students[], int n){
cout << endl;
for (int i = 0; i < n; i++){
cout << "Студент: " << students[i].name << ", курс - " << students[i].kurs << ", рейтинг - " << students[i].rating << endl;
}
cout << endl;
}
void rating_s(student students[], int n){
float rating = 7.5;
ofstream fout;
fout.open("rating.txt", std::ios::trunc);
for(int i = 0; i < n; i++){
if (!(students[i].rating < rating)){
fout << students[i].name << "," << students[i].rating << "\n";
}
}
fout.close();
}
Соседние файлы в папке 2 курс - Основы алгоритмизации _ вариант 3