Advertisement
DasShelmer

10.2.19

Dec 12th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. struct Student {
  8.     string Imya, Faliliya, Otchestvo;
  9.     int Kurs, Gruppa;
  10.     double Time;
  11.     void initialize(ifstream &in);
  12.  
  13.     string toString();
  14. };
  15.  
  16. void Student::initialize(ifstream &in){
  17.         string temp;
  18.         in >> this->Faliliya >> this->Imya >> this->Otchestvo >> temp;
  19.         this->Kurs = stoi(temp);
  20.         in >> temp;
  21.         this->Gruppa = stoi(temp);
  22.         in >> temp;
  23.         this->Time = stod(temp);
  24.  
  25. }
  26.  
  27. string Student::toString() {
  28.     string res = this->Faliliya + " "
  29.         + this->Imya + " "
  30.         + this->Otchestvo + " "
  31.         + to_string(this->Kurs) + " "
  32.         + to_string(this->Gruppa) + " "
  33.         + to_string(this->Time);
  34.     return res;
  35. }
  36.  
  37. bool isKeySame (Student *s, int keyValue){
  38.     return s->Gruppa == keyValue;
  39. }
  40.  
  41. int main() {
  42.     setlocale(LC_ALL, "Russian");
  43.     long studCount; string temp; int gruppa;
  44.     ifstream in("input.txt");
  45.     ofstream out("output.txt");
  46.     if (!in) return 0; // Файл пуст
  47.     in >> temp;
  48.     studCount = stol(temp);
  49.  
  50.     cout << "Введите запрашиваемую группу: ";
  51.     cin >> gruppa;
  52.  
  53.     auto students = new Student[studCount];
  54.  
  55.     for (auto s = students; s < students + studCount; s++) {
  56.         s->initialize(in);
  57.  
  58.         if (isKeySame(s, gruppa)) {
  59.             temp = s->toString();
  60.             out << temp << endl;
  61.             cout << temp << endl;
  62.         }
  63.     }
  64.     in.close();
  65.     out.close();
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement