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
|
#include <iostream>
using namespace std;
const int arraysize = 1000;
double productnum[arraysize];
double price[arraysize];
int quantityonhand[arraysize];
int findproduct (double productnum[], int siz, int found) {
//cout << "Enter product number." << endl;
for (int i = 0; i < siz; i++) {
if (productnum[i] == found)
return i;
}
return -1;
}
void addphone (double productnum[], double price[], int quantityonhand[], int num1) {
int addc = 0;
while (!(cin >> addc)) {
string check;
cin.clear();
getline(cin,check);
cout << "Invalid enter numeric value." << endl;
for (int i = 0;i < num1; i++) {
if ((productnum[i] || price[i] || quantityonhand[i])==0) {
cout << "Stoping entries." << endl;
} else {
cout << "Product Number " << ": ";
cin >> productnum[i];
cout << "Price " << ": ";
cin >> price[i];
cout << "Quantity On Hand " << ": ";
cin >> quantityonhand[i];
}//end else
}//end for
}//end while
}
void updategame (double productnum[], double price[], int quantityonhand[], int prodt) {
//cin >> prodt;
cin >> prodt;
for (int i = 0;i < prodt; i++) {
cin >> price[i] >> quantityonhand[i];
}
}
void displaygame (double productnum[], double price[], int quantityonhand[], int am) {
//cin >> am;
for (int i=0; i < am; i++) {
cout << "Product: " << productnum[i] << endl;
cout << "Price: " << price[i] << endl;
cout << "Quantity on Hand: " << quantityonhand[i] << endl;
}
}
void printdata (double *productnum, double *price, int *quantityonhand, int amp) {
//cin >> am;
for(int i = 0; i < amp; i++) {
cout << "Product Number " << productnum[i] << "\t" << "Price " << price[i] << "\t\t" << "Quanitity on Hand " << quantityonhand[i] << endl;
}
}
int main () {
cout << "Welcome to The SmartPhone Database." << "\n" << "Please select an option." << endl;
cout << "\n" << "***Menu***" << "\n1. Add Item" << "\n2. Update Item" << "\n3. Display Item" << "\n4. Print Database" << "\n5. Exit Program\n" << endl;
int entry;
cin >> entry;
while (entry != 5) {
switch (entry) {
case 1:
int num;
cout << "How many phones would you like to enter?" << " \nEnter product number, price, quantity on hand after amount of phones." << endl;
cin >> num;
addphone(productnum, price, quantityonhand, num);
break;
case 2:
int numup;
cout << "Enter the product number to update the price and quantitiy on hand." << endl;
cin >> numup;
updategame(productnum, price, quantityonhand, numup);
break;
case 3:
int numdis;
cout << "Enter the array value to display the items." << endl;
cin >> numdis;
displaygame(productnum, price, quantityonhand, numdis);
break;
case 4:
int nump;
cout << "How many lines of the database should be printed?" << endl;
cin >> nump;
printdata(productnum, price, quantityonhand, nump);
break;
case 5:
return 0;
}
}
return 0;
}
|