Advertisement
fferum

Untitled

Nov 6th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 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.seekg(0);
  31.     fin >> current_year;
  32.     int current_comp = 0;
  33.     int current_desk = 0;
  34.     int current_laptop = 0;
  35.     while (!fin.eof()) {
  36.         char n;
  37.         string  firm, mark;
  38.         int year, more_info;
  39.         fin >> n >> firm >> mark >> year >> more_info;
  40.         computer_array[current_comp].changeF(firm);
  41.         computer_array[current_comp].changeM(mark);
  42.         computer_array[current_comp].changeY(year);
  43.         current_comp++;
  44.  
  45.         if (n == 'C') {
  46.             desktop_array[current_desk].changeF(firm);
  47.             desktop_array[current_desk].changeM(mark);
  48.             desktop_array[current_desk].changeY(year);
  49.             desktop_array[current_desk].changeP(more_info);
  50.             current_desk++;
  51.         }
  52.         if (n == 'H') {
  53.             laptop_array[current_laptop].changeF(firm);
  54.             laptop_array[current_laptop].changeM(mark);
  55.             laptop_array[current_laptop].changeY(year);
  56.             laptop_array[current_laptop].changeC(more_info);
  57.             current_laptop++;
  58.         }
  59.  
  60.     }
  61.     ofstream desktop_fout("../Desktop.txt");
  62.     ofstream laptop_fout("../Laptop.txt");
  63.     ofstream computer_fout("../Computer.txt");
  64.     for (int i = 0; i < current_desk; i++) {
  65.         desktop_fout << desktop_array[i].print(current_year);
  66.     }
  67.  
  68.     for (int i = 0; i < current_laptop; i++) {
  69.         laptop_fout << laptop_array[i].print(current_year);
  70.     }
  71.  
  72.     for (int i = 0; i < current_comp; i++) {
  73.         computer_fout << computer_array[i].print();
  74.     }
  75.     delete[] computer_array;
  76.     delete[] desktop_array;
  77.     delete[] laptop_array;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement