1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
//Variables
int choice;
string item;
string line;
int num;
string temp;
string searchitem;
//Functions
int answer();
int main()
{
cout << "Welcome To The Store" << endl;
cout << "Please Choose A Option" << endl;
cout << endl;
cout << "1 - Display All Items In Store" << endl;
cout << "2 - Check Prices" << endl;
cout << "3 - Add New Items" << endl;
cout << "4 - Remove Items" << endl;
cout << endl;
cin >> choice;
answer();
system("pause");
}
int answer()
{
if (choice==1)
{
num = 0;
string item;
ifstream tempfile("temp.txt");
ifstream myfile("newitem.txt");
ofstream secondfile("main.txt",ios::app);
ifstream secondfile2("main.txt");
ifstream ifs( "newitem.txt" );
if (myfile.is_open() )
{
vector<string> text_file;
string temp;
while( getline( secondfile2, temp ) )
{
string name,price;
istringstream liness(temp);
getline(liness, name, ' ');
getline(liness, price, ' ');
cout <<"Item: " << name<< " - "<< "Price: " << price << endl;
//cout << "rar" << temp << endl;
text_file.push_back( temp );
num = 0;
getline(myfile,item);
//cout << "item" << item << " " << "temp" << temp << endl;
}
}
}
if(choice == 2)
{
num = 0;
string item;
ifstream tempfile("temp.txt");
ifstream myfile("newitem.txt");
ofstream secondfile("main.txt",ios::app);
ifstream secondfile2("main.txt");
ifstream ifs( "newitem.txt" );
if (myfile.is_open() )
{
cout << "What is the item?" << endl;
cin >> searchitem;
vector<string> text_file;
string temp;
while( getline( secondfile2, temp ) )
{
string name,price;
istringstream liness(temp);
getline(liness, name, ' ');
getline(liness, price, ' ');
text_file.push_back( temp );
num = 0;
getline(myfile,item);
// cout << "si" << searchitem << " = " << "temp" << temp << endl;
if (searchitem == name)
{
num = 1;
cout << "Item is Found" << endl;
cout << name<< " - " << price << endl;
myfile.close();
//remove("main.txt");
//rename("temp.txt","main.txt");
secondfile2.close();
secondfile.close();
}
}
}
}
if(choice == 3)
{
num = 0;
string item;
ifstream tempfile("temp.txt");
ifstream myfile("newitem.txt");
ofstream secondfile("main.txt",ios::app);
ifstream secondfile2("main.txt");
ifstream ifs( "newitem.txt" );
if (myfile.is_open() )
{
vector<string> text_file;
string temp;
while( getline( secondfile2, temp ) )
{
string name,price;
istringstream liness(temp);
getline(liness, name, ' ');
getline(liness, price, ' ');
//cout <<"Item: " << name<< " - "<< "Price: " << price << endl;
//cout << "rar" << temp << endl;
text_file.push_back( temp );
num = 0;
getline(myfile,item);
//cout << "item" << item << " " << "temp" << temp << endl;
if (item == temp)
{
num = 1;
cout << "The Store Already Has: " << item<<endl;
myfile.close();
//remove("main.txt");
//rename("temp.txt","main.txt");
secondfile2.close();
secondfile.close();
}
}
secondfile2.close();
if(num == 0)
{
secondfile <<item<< endl;
secondfile.close();
cout << "Item Added" << endl;
}
myfile.close();
}
}
if(choice == 4)
{
num = 0;
string item;
ifstream tempfile("temp.txt");
ifstream myfile("removeitem.txt");
ofstream secondfile("main.txt",ios::app);
ifstream secondfile2("main.txt");
ifstream ifs( "removeitem.txt" );
if (myfile.is_open() )
{
vector<string> text_file;
string temp;
while( getline( secondfile2, temp ) )
{
string name,price;
istringstream liness(temp);
getline(liness, name, ' ');
getline(liness, price, ' ');
//cout <<"Item: " << name<< " - "<< "Price: " << price << endl;
//cout << "rar" << temp << endl;
text_file.push_back( temp );
num = 0;
getline(myfile,item);
//cout << "item" << item << " " << "temp" << temp << endl;
if (item == temp)
{
num = 1;
cout << "Item Removed: " << item<<endl;
myfile.close();
remove("main.txt");
rename("temp.txt","main.txt");
cout <<"hehe"<<endl;
}
}
secondfile2.close();
}
}
}
|