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
|
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
void displayMenu();
int getChoice();
void add_codes(int products[], int size, int& number_codes_entered);
void remove_codes(int products[], int& number_codes_entered);
void display_codes(int products[], int& number_codes_entered);
/*
*/
int main()
{
const int SIZE = 1000;
int products[SIZE];
int choice,
number_codes_entered;
//char answer;
do
{
displayMenu();
choice = getChoice();
switch (choice)
{
case 1: add_codes(products, SIZE, number_codes_entered); //function call to function add_codes
break;
case 2: remove_codes(products, number_codes_entered);
break;
case 3: display_codes(products, number_codes_entered);
break;
default:
break;
}
} while (choice != 4);
return 0;
}
void displayMenu()
{
// Display menu of choices
cout << "\n\t\tThe X, Y & Zilch Company Product Codes Menu Selection" << endl;
cout << "\n\tPlease make your selection<<endl";
cout << "\n\t1. Add Codes";
cout << "\n\t2. Remove Codes";
cout << "\n\t3. Display Product Codes";
cout << "\n\tEnter your choice(1-3) or 4 to quit: ";
}
int getChoice()
{
int choice;
// Get and validate user's choice
cin >> choice;
while (choice < 1 || choice > 4)
{
cout << "Choice must be between 1 and 3. Please re-enter: ";
cin >> choice;
}
//Return the choice
return choice;
}
void add_codes(int products[], int size, int& number_codes_entered) {
char answer;
int counter = 0,
index = 0;
cout << "\n\t===========================================\n";
cout << "\n\tAdding Product Codes to X, Y & Zilch Company Database : \n";
cout << "\n\n\tEnter \" Y \" to add product codes to Database or \" N \" to quit: ";
cin >> answer;
while (answer == 'y' || answer == 'Y') {
counter++;
cout << "\tEnter Product " << (counter) << " Code: ";
cin >> products[index];
index++;
number_codes_entered = index;
cout << "\n\tEnter \" Y \" to add more product codes to Database or \"N \" to quit adding codes : ";
cin >> answer;
}
cout << "\n\t===========================================\n";
}
void remove_codes(int products[], int & number_codes_entered) {
int product_code_number;
int index;
cout << "What product code number do you want to remove?" << endl;
cout << "Enter the product code number: ";
cin >> product_code_number;
for (int index = 0; index < number_codes_entered; index++)
{
if (products[index] == product_code_number)
{
products[index] = products[index + 1];
number_codes_entered--;
break;
}
else
{
cout << "Invalid Product Code Entered." << endl;
cout << "Re-Enter Valid Product code to be removed: ";
cin >> product_code_number;
}
}
}
void display_codes(int products[], int& number_codes_entered) {
cout << "\n\t===========================================\n";
cout << "\n\tList of X, Y & Zilch Company Product Codes: \n";
for (int index = 0; index < number_codes_entered; index++)
{
cout << "\t Product Code: " << products[index] << endl;
}
cout << "\n\t===========================================\n";
}
| |