Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Topping Repo:
- #include "ToppingRepository.h"
- ToppingRepository::ToppingRepository()
- {
- //ctor
- }
- ToppingRepository::~ToppingRepository()
- {
- //dtor
- }
- void ToppingRepository::CreateTopping(Topping& t)
- {
- ofstream fout;
- fout.open("TextFiles/Topping.txt", ios::app);
- if(fout.is_open())
- {
- fout << "Topping name: " << t.getName() << endl
- << "Type: " << t.getType() << endl
- << "Price: " << t.getPrice() << endl << endl;
- fout.close();
- }
- else{
- cout << "Some error occurred...Did you delete the file?" << endl;
- }
- }
- void ToppingRepository::AccessToppings()
- {
- //make a proper table
- cout << "---Available Toppings---" << endl;
- string line;
- ifstream fin;
- fin.open("TextFiles/Topping.txt");
- if(fin.is_open())
- {
- while(!fin.eof())
- {
- getline(fin, line);
- cout << line << endl;
- }
- fin.close();
- }else
- {
- cout << "File could not be opened!" << endl;
- }
- }
- bool ToppingRepository::ToppingCheck(string s)
- {
- string line;
- string topping = "";
- int index;
- ifstream fin;
- fin.open("TextFiles/Topping.txt");
- if(fin.is_open())
- {
- while(!fin.eof())
- {
- topping = "";
- getline(fin, line);
- index = line.find("Topping Name:");
- if(index){
- int j = 14;
- while(line[j] != '\0'){
- topping += line[j];
- j++;
- }
- if(topping == s)
- return true;
- }
- }
- fin.close();
- }
- else
- {
- cout << "File could not be opened!" << endl;
- }
- return false;
- }
- ToppingServices:
- #include "ToppingServices.h"
- bool ToppingServices::ToppingCheck(string temp)
- {
- //check if toping exists by going into the repository but first does a check on the name and its validation
- ToppingRepository tr;
- return tr.ToppingCheck(temp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement