fferum

source.cpp

Nov 7th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include "computer_info.h"
  4. using namespace std;
  5.  
  6. int main() {
  7.     ifstream fin("../input.txt");
  8.     if (!fin.is_open()) {
  9.         return 1;
  10.     }
  11.     int current_year;
  12.     fin >> current_year;
  13.     int desktop_count = 0;
  14.     int laptop_count = 0;
  15.     while (!fin.eof()) {
  16.         char n;
  17.         string  firm, mark;
  18.         int year, more_info;
  19.         fin >> n >> firm >> mark >> year >> more_info;
  20.         if (n == 'C') {
  21.             desktop_count++;
  22.         }
  23.         if (n == 'H') {
  24.             laptop_count++;
  25.         }
  26.     }
  27.     Computer* computer_array = new Computer[desktop_count + laptop_count];
  28.     Desktop* desktop_array = new Desktop[desktop_count];
  29.     Laptop* laptop_array = new Laptop[laptop_count];
  30.     fin.close();
  31.     fin.open("../input.txt");
  32.     if (!fin.is_open()) {
  33.         return 1;
  34.     }
  35.     fin >> current_year;
  36.     int current_comp = 0;
  37.     int current_desk = 0;
  38.     int current_laptop = 0;
  39.     while (!fin.eof()) {
  40.         char n;
  41.         string  firm, mark;
  42.         int year, more_info;
  43.         fin >> n >> firm >> mark >> year >> more_info;
  44.         computer_array[current_comp].changeF(firm);
  45.         computer_array[current_comp].changeM(mark);
  46.         computer_array[current_comp].changeY(year);
  47.         current_comp++;
  48.  
  49.         if (n == 'C') {
  50.             desktop_array[current_desk].changeF(firm);
  51.             desktop_array[current_desk].changeM(mark);
  52.             desktop_array[current_desk].changeY(year);
  53.             desktop_array[current_desk].changeP(more_info);
  54.             current_desk++;
  55.         }
  56.         if (n == 'H') {
  57.             laptop_array[current_laptop].changeF(firm);
  58.             laptop_array[current_laptop].changeM(mark);
  59.             laptop_array[current_laptop].changeY(year);
  60.             laptop_array[current_laptop].changeC(more_info);
  61.             current_laptop++;
  62.         }
  63.  
  64.     }
  65.     ofstream desktop_fout("../Desktop.txt");
  66.     ofstream laptop_fout("../Laptop.txt");
  67.     ofstream computer_fout("../Computer.txt");
  68.     for (int i = 0; i < current_desk; i++) {
  69.         desktop_fout << desktop_array[i].print(current_year);
  70.     }
  71.  
  72.     for (int i = 0; i < current_laptop; i++) {
  73.         laptop_fout << laptop_array[i].print(current_year);
  74.     }
  75.  
  76.     for (int i = 0; i < current_comp; i++) {
  77.         computer_fout << computer_array[i].print();
  78.     }
  79.     computer_fout.close();
  80.     desktop_fout.close();
  81.     laptop_fout.close();
  82.     fin.close();
  83.     delete[] computer_array;
  84.     delete[] desktop_array;
  85.     delete[] laptop_array;
  86. }
  87.  
Add Comment
Please, Sign In to add comment