write a to create a of prcatalogueoducts that are sold in the shop. the situation requires that you allow jerri to: 1. add items by entering in real time. 2. add items by importing from plain text file 3. remove a single item 4. remove all items make sure that the items are uniquely identifiable.
#include <iostream>
#include <string>
#include <string.h>
using namespace std;
void mergeArr(string arr1[], int n1, string arr2[], int n2, string result[]) {
result[10000] = {};
for (size_t i = 0; i < n1; i++) {
result[i] = arr1[i];
}
for (size_t i = n1; i < n1 + n2 -1; i++) {
for (size_t k = 0; k < n2; k++) {
result[i] = arr2[k];
}
}
cout << result << endl;
}
int main () {
// product catalog that are sold in the shop
string result[10000] = {};
int choice;
string current_products[] = {"Tv", "Computer", "Car", "Phone", "Book", "Computer", "Phone", "Tv", "Car"};
int numberOfRlements = sizeof(current_products)/sizeof(current_products[0]);
cout << "Current products in the shop: \n";
for (int i = 0; i < numberOfRlements; i++) {
cout << current_products[i] << " ";
}
cout << "\nSelect your choice: \n";
cout << "1. Add items by entering in real time.\n";
cout << "2. Add items by importing from plain text file.\n";
cout << "3. Remove a single item.\n";
cout << "4. Remove all items\n";
cout << "0. Exit the code\n";
while(true) {
cin >> choice;
if (choice == 1) {
int product_number;
cout << "How many elements do you want to add: \n";
cin >> product_number;
string product_add[product_number] = {""};
for (int i = 0; i < product_number; i++) {
string product;
cin >> product;
product_add[i] = product;
}
cout << "Products catalog: ";
mergeArr(current_products, numberOfRlements, product_add, product_number, result);
}
if (choice == 0) {
break;
}
}
}
Comments
Leave a comment