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
|
int findID (char [][5], string, int&);
double buyPhone(int, double, int&);
double updatePrice(double[], int);
void printArray(char [][5], string[], double[], int[], int*);
void query_database(char [][5], string[], double [], int[], int);
void exit();
int main()
{
string name[1000];
char productID[1000][5];
double price[1000];
int quantityonHand[1000];
int n = 0;
string lookID;
bool r = true;
while (r = true)
{
int choice;
cout << "\n \t\t\t ====== PHONE DATABASE ======";
cout <<"\n\n ";
cout << "\n\n";
cout<<" \n\t\t\t ======================";
cout << "\n \t\t\t 1. Start Program";
cout << "\n \t\t\t 2. Find Phone";
cout << "\n \t\t\t 3. Add Phone";
cout << "\n \t\t\t 4. List Phone";
cout << "\n \t\t\t 5. Advanced Search";
cout << "\n \t\t\t 6. Delete Phone";
cout << "\n \t\t\t 7. Exit Program";
cout <<" \n\t\t\t ======================";
cout << "\n\n";
cout << "\t\t\t Select Your Choice ::";
cin >> choice;
switch (choice){
case 1:
{
cout<<"How much info do you need to enter?"<<endl;
cin>>n;
cout<<endl;
while (!cin>> n )
{ cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout<<"Invalid input. Please try again."<<endl;
cout<<endl;
cout<<"How much info do you need to enter?"<<endl;
cin>>n;
cout<<endl;
}
for (int c=0; c<n; c++)
{
cout<< "What is the name of your phone?"<<endl;
cin>> name[c];
cout<< "Please enter the product ID."<<endl;
cin>> productID[c];
for(int b=0; b<4; b++)
{
while (strlen(productID[c])>4 || !((productID[c][b]>='A' && productID[c][b]<='Z')||(productID[c][b]>='a' && productID[c][b]<='z')) )
{
cout<<"It has to be four characters."<<endl;
cin>>productID[b];
}
}
cout<<endl;
cout<<"Please enter the price for the phone."<<endl;
cin>>price[c];
cout<<endl;
while(price[c]<=0)
{
cout<<"Please put in a price larger than 0."<<endl;
cin>>price[c];
cout<<endl;
}
cout<<"How many phones do you have at the moment?"<<endl;
cin>>quantityonHand[c];
if(quantityonHand[c]>0)
{
cout<<"You have "<<quantityonHand[c]<<" copies of this model."<<endl;
}
else if (quantityonHand[c]<0)
{
cout<<"You have no more copies of this model."<<endl;
}
cout<<endl<<endl;
buyPhone(quantityonHand[c], price[c], quantityonHand[c]);
updatePrice(price, c);
}
}
case 2:
{
string point;
cout<<"Would you like to continue?"<<endl;
cin>>point;
if (point == "yes" || point=="y")
{
findID(productID, lookID, n);
}
else
cout<<endl;
break;
}
case 4:
{
printArray (productID, name, price, quantityonHand, &n);
break;
}
case 5:
{
query_database(productID, name, price, quantityonHand, n);
}
case 7:
{
r = false;
exit();
return 0;
}
}
}
}
int findID(char x[][5], string z, int &r)
{
string exit;
while(exit!="yes" || exit!="y")
{
cout<<"Please enter the productID you want to look up."<<endl;
cin>>z;
for(int w=0; w<r; w++)
{
if(x[w]==z)
{
cout<<"Found! Your product ID is found in database " <<(w+1)<<"."<<endl<<endl;
}
else
cout<<"Product not found."<<endl;
}
cout << "Would you like to exit?"<<endl;
cin >> exit;
if (exit == "yes" || exit=="y")
break;
}}
void printArray(char arr[][5], string n, double b[], int c[], int *w)
{
for ( int i = 0; i <*w; i++)
{
cout<< "Name: " << n[i] << ' '<<endl;
cout<<"ProductID: "<< arr[i] << ' '<<endl;
cout <<"Price: " <<"$"<<b[i]<<' '<<endl;
cout <<"Amount: "<<c[i]<<' '<<endl;
cout<<endl<<endl;
}
cout << endl;
}
double updatePrice(double wer[], int e)
{
string s;
cout<<"Would you like to change the price? Please enter y or yes as input."<<endl;
cin>>s;
if(s=="y" || s=="yes")
{
cout<<"Enter new price :";
cin>>wer[e];
cout<<"Price Updated... Successfully "<<endl;
}
else
cout<<"Price change canceled."<<endl<<endl;
}
double buyPhone(int quant, double total, int &lft)
{
int *crt=&lft;
string output;
if(quant!=0)
{
cout<<"Would you like to buy this model?"<<endl;
cin>>output;
if(output=="y" || output=="yes")
{
cout<<"How many would you like to buy?"<<endl;
cin>>quant;
if(quant>=*crt){
cout<<"There are not enough of these models available. Please accept what's left."<<endl;
cin>>quant;}
cout<<"Your total cost is $"<<(total=total*quant)<<". Thank you for shopping with us."<<endl;
cout<<endl;
cout<<"There are now "<<(*crt=lft-quant)<<" version(s) of this model left."<<endl;
}
else
cout<<"Transaction canceled."<<endl<<endl;
}
}
void query_database(char ar[][5], string gt[], double p[], int c[], int amt)
{
string q;
string name;
string id;
string price;
cout<<"Do you want to search by name, product ID, or price?"<<endl;
cin >> q;
if(q == "name")
{
cout<<"Please enter the name you want to look for?"<<endl;
string name;
for(int i=0 ; i<amt; i++)
{
if(name == gt[i])
printArray ();
else
cout<<"Not found."<<endl;
}
}
}
void exit()
{
cout << "\n \t\t\t ******* T H A N K Y O U *******" << endl;
cout << "\n \t\t\t ******* F O R U S I N G *******" << endl;
cout << "\n \t\t\t ******* T H I S P R O G R A M *******" << endl;
}
| |