Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include "computer_info.h"
- using namespace std;
- int main() {
- ifstream fin("../input.txt");
- if (!fin.is_open()) {
- return 1;
- }
- int current_year;
- fin >> current_year;
- int desktop_count = 0;
- int laptop_count = 0;
- while (!fin.eof()) {
- char n;
- string firm, mark;
- int year, more_info;
- fin >> n >> firm >> mark >> year >> more_info;
- if (n == 'C') {
- desktop_count++;
- }
- if (n == 'H') {
- laptop_count++;
- }
- }
- Computer* computer_array = new Computer[desktop_count + laptop_count];
- Desktop* desktop_array = new Desktop[desktop_count];
- Laptop* laptop_array = new Laptop[laptop_count];
- fin.close();
- fin.open("../input.txt");
- if (!fin.is_open()) {
- return 1;
- }
- fin >> current_year;
- int current_comp = 0;
- int current_desk = 0;
- int current_laptop = 0;
- while (!fin.eof()) {
- char n;
- string firm, mark;
- int year, more_info;
- fin >> n >> firm >> mark >> year >> more_info;
- computer_array[current_comp].changeF(firm);
- computer_array[current_comp].changeM(mark);
- computer_array[current_comp].changeY(year);
- current_comp++;
- if (n == 'C') {
- desktop_array[current_desk].changeF(firm);
- desktop_array[current_desk].changeM(mark);
- desktop_array[current_desk].changeY(year);
- desktop_array[current_desk].changeP(more_info);
- current_desk++;
- }
- if (n == 'H') {
- laptop_array[current_laptop].changeF(firm);
- laptop_array[current_laptop].changeM(mark);
- laptop_array[current_laptop].changeY(year);
- laptop_array[current_laptop].changeC(more_info);
- current_laptop++;
- }
- }
- ofstream desktop_fout("../Desktop.txt");
- ofstream laptop_fout("../Laptop.txt");
- ofstream computer_fout("../Computer.txt");
- for (int i = 0; i < current_desk; i++) {
- desktop_fout << desktop_array[i].print(current_year);
- }
- for (int i = 0; i < current_laptop; i++) {
- laptop_fout << laptop_array[i].print(current_year);
- }
- for (int i = 0; i < current_comp; i++) {
- computer_fout << computer_array[i].print();
- }
- computer_fout.close();
- desktop_fout.close();
- laptop_fout.close();
- fin.close();
- delete[] computer_array;
- delete[] desktop_array;
- delete[] laptop_array;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement