SHARE
TWEET

Untitled

a guest Sep 13th, 2017 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // Created by nazar on 13.09.17.
  3. //
  4.  
  5. #include "Brigade.h"
  6.  
  7.  
  8. Brigade::Brigade(int NumberOfBrigade, string LeaderOfBrigade, Materials &materials) {
  9.     NumberOfBrigade = m_NumberOfBrigade;
  10.     LeaderOfBrigade = m_LeaderOfBrigade;
  11.     ListOfMaterials.push_back(materials);
  12.  
  13. }
  14.  
  15. int Brigade::getNumberOfBrigade() {
  16.     return this->m_NumberOfBrigade;
  17. }
  18.  
  19. void Brigade::setNumberOfBrigade(int number) {
  20.     this->m_NumberOfBrigade = number;
  21. }
  22.  
  23. string Brigade::getLeaderOfBrigade() {
  24.     return m_LeaderOfBrigade;
  25. }
  26.  
  27. void Brigade::setLeaderOfBrigade(string leader) {
  28.     this->m_LeaderOfBrigade = leader;
  29. }
  30.  
  31. void Brigade::setListOfMaterials(Materials &materials) {
  32.     this->ListOfMaterials.push_back(materials);
  33. }
  34.  
  35. //vector<Materials> Brigade::getListOfBrigade() {
  36. //    return this->ListOfMaterials;
  37. //}
  38.  
  39. void print(vector<Brigade> brigades) {
  40.     sort(brigades.begin(), brigades.end(), []( Brigade& lhs, Brigade& rhs){ return lhs.getNumberOfBrigade() < rhs.getNumberOfBrigade(); });
  41.     cout << "Number#\t\t" << "Name of Leader\t\t\t" <<"Date of materials\t\t\t" << "List name of materials\t\t" << "Capacity of materials\t\t" << "Price of materials\t\t" << endl;
  42.     for(int i = 0; i < brigades.size(); i++){
  43.         cout << brigades[i].getNumberOfBrigade() <<"\t\t\t" << brigades[i].getLeaderOfBrigade()<<"\t\t\t\t\t\t";
  44.         for (int j = 0; j < brigades[i].ListOfMaterials.size(); ++j) {
  45.             cout << brigades[i].ListOfMaterials[j].getDateOfMaterials()<<"\t\t\t\t\t\t"
  46.             <<brigades[i].ListOfMaterials[j].getNameOfMaterials()<<"\t\t\t\t\t\t\t"
  47.             << brigades[i].ListOfMaterials[j].getCapacityOfMaterials()<<"\t\t\t\t\t\t\t\t"
  48.             << brigades[i].ListOfMaterials[j].getPriceOfMaterials()<<"\t\t" << endl << "\t\t\t\t\t\t\t\t\t\t";
  49.         }
  50.         cout << "-----------------------------------------------------------------------------------------------------------" << endl;
  51.     }
  52. }
  53.  
  54. unsigned long Brigade::getSizeOfMaterials() {
  55.     return this->ListOfMaterials.size();
  56. }
  57.  
  58.  
  59. Materials::Materials(int DateOfMaterials, string NameOfMaterials, int CapacityOfMaterials, int PriceOfMaterials) {
  60.     DateOfMaterials = m_DateOfMaterials;
  61.     NameOfMaterials = m_NameOfMaterials;
  62.     CapacityOfMaterials = m_CapacityOfMaterials;
  63.     PriceOfMaterials = m_PriceOfMaterials;
  64. }
  65.  
  66. int Materials::getDateOfMaterials() {
  67.     return this->m_DateOfMaterials;
  68. }
  69.  
  70. void Materials::setDateOfMaterials(int date) {
  71.     m_DateOfMaterials = date;
  72. }
  73.  
  74. string Materials::getNameOfMaterials() {
  75.     return m_NameOfMaterials;
  76. }
  77.  
  78. void Materials::setNameOfMaterials(string name) {
  79.     m_NameOfMaterials = name;
  80. }
  81.  
  82. int Materials::getCapacityOfMaterials() {
  83.     return m_CapacityOfMaterials;
  84. }
  85.  
  86. void Materials::setCapacityOfMaterials(int capacity) {
  87.     m_CapacityOfMaterials = capacity;
  88. }
  89.  
  90. int Materials::getPriceOfMaterials() {
  91.     return m_PriceOfMaterials;
  92. }
  93.  
  94. void Materials::setPriceOfMaterials(int price) {
  95.     m_PriceOfMaterials = price;
  96. }
  97.  
  98. vector<Brigade> DTOTask::write_from_file() {
  99.     ifstream file("../Brigade");
  100.     vector<Brigade> brigades;
  101.     if (file.is_open())
  102.     {
  103.         while (!file.eof())
  104.         {
  105.             Brigade brigade;
  106.             Materials material;
  107.  
  108.             int HelperCapacity;
  109.             file >> HelperCapacity;
  110.             brigade.setNumberOfBrigade(HelperCapacity);
  111.  
  112.             string HelperLine;
  113.             file >> HelperLine;
  114.             brigade.setLeaderOfBrigade(HelperLine);
  115.  
  116.             unsigned int counter = 0;
  117.             file >> counter;
  118.  
  119.             while(counter > 0){
  120.                 file >> HelperCapacity;
  121.                 material.setDateOfMaterials(HelperCapacity);
  122.                 file >> HelperLine;
  123.                 material.setNameOfMaterials(HelperLine);
  124.                 file >> HelperCapacity;
  125.                 material.setCapacityOfMaterials(HelperCapacity);
  126.                 file >> HelperCapacity;
  127.                 material.setPriceOfMaterials(HelperCapacity);
  128.                 brigade.setListOfMaterials(material);
  129.                 counter--;
  130.             }
  131.             brigades.push_back(brigade);
  132.         }
  133.         file.close();
  134.         return brigades;
  135.     }
  136.     else
  137.     {
  138.         cout << "File not found!" <<endl;
  139.     }
  140.     return brigades;
  141. }
  142.  
  143.  
  144.  
  145. void DTOTask::write_to_file(vector<Brigade> &brigades) {
  146.     ofstream file("/Task.csv", ios::app);
  147.     if (file)
  148.     {
  149.         for (int i = 0; i < 4; ++i) {
  150.             file << brigades[i];
  151.             file << ",";
  152.             file << brigades[i];
  153.             os << ",";
  154.             for (int j = 0; j < brigades[i].getSizeOfMaterials(); ++j) {
  155.                 os << brigades[i].ListOfMaterials[j].getPriceOfMaterials();
  156.                 os << ",";
  157.                 os << brigades[i].get_assignment();
  158.                 os <<"\n";
  159.             }
  160.         }
  161.     }
  162.     else
  163.     {
  164.         cout << "File not found!" << endl;
  165.     }
  166.     file.close();
  167. }
  168.  
  169.  
  170. ostream &operator<<(ostream &os, vector<Brigade> &brigades) {
  171.     return <#initializer#>;
  172. }
  173.  
  174. ostream &operator<<(ostream &os, Brigade &brigade) {
  175.         os << brigade.getNumberOfBrigade();
  176.         os << ",";
  177.         os << brigade.getLeaderOfBrigade();
  178.         os << ",";
  179.  
  180.     return os;
  181. }
RAW Paste Data
Top