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
|
#include <iostream>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;
const int SIZE = 1000;
void addphone(char [][5], string *, int *, double *, int &);
//int nextIndex(char **, int);
//int find(char **, int , string);
//void update(char **, int *, double *, int);
//void display(char **, int *, double *, int);
void print(char [][5], string *, int *, double *, int);
int main()
{
string productName[SIZE];
char id[SIZE][5];
double price[SIZE] = {0};
int quantity[SIZE] = {0};
int total = 0;
int choice;
bool exit = true;
while(exit)
{
cout << "1. Add Item" << endl
<< "2. Update Item" << endl
<< "3. Display Item" << endl
<< "4. Print Database" << endl
<< "5. Exit Program" << endl;
cout << "Select an option from the menu:" << endl;
cin >> choice;
switch(choice)
{
case 1:
addphone(id, productName, quantity, price, total);
break;
case 2:
case 3:
case 4:
print(id, productName, quantity, price, total);
break;
case 5:
exit = false;
break;
default:
cout << "Invalid Choice" << endl;
}
}
}
void addphone(char id[][5], string *productName, int *quantity, double *price, int &total)
{
char tempID[5];
cout << "Enter the Product ID: ";
cin >> tempID;
// int x = find(id,total,tempID);
int x = -1;
if (x == -1)
{
int i = total;
total++;
strcpy(id[i], tempID);
cout << "Enter the name of the product: ";
cin >> productName[i];
cout << "Enter the price of the phone: ";
cin >> price[i];
cout<< "Enter the quantity on hand: ";
cin >> quantity[i];
cout << endl << endl;
}
else
cout << "This ID is already in the Database" << endl ;
}
void print(char id[][5], string *productName, int *quantity, double *price, int total)
{
cout << fixed << setprecision(2);
for (int i=0; i<total; ++i)
{
cout << setw(6) << id[i]
<< setw(20) << productName[i]
<< setw(6) << quantity[i]
<< setw(10) << price[i]
<< endl;
}
}
|