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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
// CStudy_3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <Windows.h>
#include <conio.h>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
struct Customer
{
int id;
char name[20];
int quantity;
float price;
int deleted;
};
void trim();
void loading(void);
void gotoxy (int x, int y);
int main()
{
Customer cust[1];
FILE *fp;
int numChoice;
char choice;
int choice_menu=0;
system ("color 3");
/*loading();*/
system("cls");
//welcoming graphics
fp=fopen("D:\\items.txt", "r");
if (!fp)
{
cout << "Cannot open file.\n";
cout << "Please replace the 'items.txt' file in your Local Disk C:\\.\n";
cout << "Thank you and enter to try again.";
system("pause>0");
goto menu;
}
menu:
system("cls");
gotoxy(28,8);
cout<<"MENU: \n";
gotoxy(28,9);
cout<<"1- BUY ITEM/s";
gotoxy(28,10);
cout<<"2- SEE LIST OF FRUITS";
gotoxy(28,11);
cout<<"3- SEARCH RECORD/s";
gotoxy(28,12);
cout<<"4- EXIT";
gotoxy(28,13);
cout<<"CHOICE: ";
gotoxy(36,13);
cin>>choice_menu;
switch(choice_menu)
{
case 1:
system("cls");
cout << "How many item/s do you want to buy?: ";
cin >> numChoice;
void trim();
for (int i=0; i<numChoice; i++)
{
char itmDel;
cout << "ITEM "<<(i+1)<<endl;
cout << "What item do you want to buy? Enter the item's id no: ";
cin >> itmDel;
/*cust[itmDel].deleted=0;*/
cout << "How many of "<<cust[i].name<<" do you want to buy?";
cin >> cust[i].quantity;
void trim();
}
cout << "Please wait..";
cout << "Gathering all your needed item/s";
/*fp=fopen("D:\\items.txt", "r");
if (!fp)
{
cout << "Cannot open file.\n";
cout << "Please replace the 'items.txt' file in your Local Disk C:\\.\n";
cout << "Thank you and enter to try again.";
system("pause>0");
goto menu;
}*/
for (int i=0; i<numChoice; i++)
{
fscanf(fp, "%d%s%d%f", &cust[i].id, &cust[i].name, &cust[i].quantity, &cust[i].price);
cout << "ITEM "<<(i+1)<<endl<<endl;
cout << "ID: "<< cust[i].id<<endl;
cout << "NAME: "<< cust[i].name<<endl;
cout << "QUANTITY: "<<cust[i].quantity<<endl;
cout << "PRICE: "<<cust[i].price<<endl;
cust[i].deleted=0;
cout << endl;
cout << "Is this the item do you want to buy? (Y/N): ";
cin >> choice;
if (choice=='Y' || choice=='y')
{
system ("cls");
fscanf(fp, "%d%s%d%f", &cust[i].id, &cust[i].name, &cust[i].quantity, &cust[i].price);
cout << "ITEM "<<(i+1)<<endl<<endl;
cout << "ID: "<< cust[i].id<<endl;
cout << "NAME: "<< cust[i].name<<endl;
cout << "QUANTITY: "<<cust[i].quantity<<endl;
cout << "PRICE: "<<cust[i].price<<endl;
cust[i].deleted=1;
cout << "Buying the item/s..";
cout << "Please wait..";
fin.close();
goto buy;
}
else if (choice=='N' || choice=='n')
{
system("cls");
cout << "Okay, going back to the menu..";
cout << "Please type what you want to buy clearly.";
fin.close();
Sleep(1280);
goto menu;
}
}
break;
case 2:
system ("cls");
char buff[1000];
cout<<setw(4)<<"ID"
<<setw(15)<<"NAME"
<<setw(14)<<"QUANTITY"
<<setw(15)<<"PRICE";
for (int i=0; i<44; i++)
{
while (fgets(buff,1000,fp)!=NULL)
cout<<buff;
cout<<endl;
cout<<setw(4)<<i
<<setw(15)<<cust[i].name
<<setw(14)<<cust[i].quantity
<<setw(15)<<cust[i].price;
}
break;
case 3: system("cls");
int itmSrch;
char choice_srch;
again:
fp=fopen("D:\\items.txt", "w");
cout<<"What item do you want to search? :";
cin>>itmSrch;
system ("cls");
cout<<setw(4)<<"ID"
<<setw(15)<<"NAME"
<<setw(14)<<"QUANTITY"
<<setw(15)<<"PRICE";
cout<<"Is this the item? ";
cout<<cust[itmSrch].name;
cout<<"\nAnswer: ";
cin>>choice_srch;
if (choice_srch =='y' || choice_srch=='Y')
{
cout<<endl;
cout<<setw(4)<<itmSrch
<<setw(15)<<cust[itmSrch].name
<<setw(14)<<cust[itmSrch].quantity
<<setw(15)<<cust[itmSrch].price;
}
else
{
system("cls");
goto again;
}
system("pause>0");
goto menu;
break;
case 4: system("cls");
gotoxy(17, 10);
cout<<"THANK YOU FOR BUYING FRUITS, PLEASE BUY AGAIN!";
system ("pause>0");
return 0;
break;
default: system("cls");
gotoxy (15, 10);
cout<<"INVALID INPUT! PLEASE, ENTER 1-4 ONLY. THANK YOU.";
Sleep(1400);
goto menu;
break;
}
buy:
system("cls");
cout<<"\n\n\n\n\n\nBuying the item, please wait..";
cout<<"\n\n\n\n\n\n\n";
for (int i=0; i<80; i++)
{
cout<<(char)221;
for (long j=0; j<16000000; j++)
{}
}
cout << "Done purchasing! Want to buy more or exit the store? (B/E)";
cin >> choice;
if (choice=='e' || choice=='E')
{
system("cls");
exit(1);
}
else if (choice=='B' || choice=='b')
{
system("cls");
goto menu;
}
fclose(fp);
return 0;
}
void trim()
{
char s;
do{
cin.get(s);
}while (s!='\n');
}
void loading(void)
{
gotoxy(32, 10);
cout<<"L O A D I N G \n";
for (int i=0; i<80; i++)
{
cout<<(char)221;
for (long j=0; j<16000000; j++)
{}
}
cout<<endl;
}
void gotoxy (int x, int y)
{
COORD coord;
coord.X = x; coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
|