Advertisement
Guest User

CodePizza123

a guest
Dec 13th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. Topping Repo:
  2. #include "ToppingRepository.h"
  3.  
  4. ToppingRepository::ToppingRepository()
  5. {
  6.     //ctor
  7. }
  8.  
  9. ToppingRepository::~ToppingRepository()
  10. {
  11.     //dtor
  12. }
  13. void ToppingRepository::CreateTopping(Topping& t)
  14. {
  15.     ofstream fout;
  16.  
  17.         fout.open("TextFiles/Topping.txt", ios::app);
  18.  
  19.         if(fout.is_open())
  20.         {
  21.             fout << "Topping name: " << t.getName() << endl
  22.                  << "Type: " << t.getType() << endl
  23.                  << "Price: " << t.getPrice() << endl << endl;
  24.  
  25.             fout.close();
  26.         }
  27.         else{
  28.  
  29.             cout << "Some error occurred...Did you delete the file?" << endl;
  30.         }
  31. }
  32. void ToppingRepository::AccessToppings()
  33. {
  34.     //make a proper table
  35.     cout << "---Available Toppings---" << endl;
  36.     string line;
  37.  
  38.     ifstream fin;
  39.     fin.open("TextFiles/Topping.txt");
  40.     if(fin.is_open())
  41.     {
  42.         while(!fin.eof())
  43.         {
  44.             getline(fin, line);
  45.             cout << line << endl;
  46.         }
  47.         fin.close();
  48.     }else
  49.     {
  50.         cout << "File could not be opened!" << endl;
  51.     }
  52. }
  53. bool ToppingRepository::ToppingCheck(string s)
  54. {
  55.     string line;
  56.     string topping = "";
  57.     int index;
  58.     ifstream fin;
  59.     fin.open("TextFiles/Topping.txt");
  60.     if(fin.is_open())
  61.     {
  62.         while(!fin.eof())
  63.         {
  64.             topping = "";
  65.             getline(fin, line);
  66.             index = line.find("Topping Name:");
  67.             if(index){
  68.                 int j = 14;
  69.                 while(line[j] != '\0'){
  70.                     topping += line[j];
  71.                     j++;
  72.                 }
  73.                 if(topping == s)
  74.                     return true;
  75.             }
  76.         }
  77.         fin.close();
  78.     }
  79.     else
  80.     {
  81.         cout << "File could not be opened!" << endl;
  82.     }
  83.     return false;
  84. }
  85.  
  86. ToppingServices:
  87. #include "ToppingServices.h"
  88.  
  89. bool ToppingServices::ToppingCheck(string temp)
  90. {
  91.     //check if toping exists by going into the repository but first does a check on the name and its validation
  92.     ToppingRepository tr;
  93.     return tr.ToppingCheck(temp);
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement