1. in this programe i want add some products to be shown after choosing choise ( show all products ) before i add any products. let say 10 products have added to the program then when the user choose (show all products ) all the 10 products appear and the user going to choose one and that one must has its own name, price,and quantity after that the quantity will be reduce.
2. allow the user to buy products.
===========================================================
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct product
{
string name;
int quantity;
float price;
};
void show_products(product products[])
{
if (products[0].name.empty())
{
cout << "\nYou have not added any product yet." << endl;
return;
}
cout << "\n\nAll Products";
cout << "\n--------------------------------------------------------------------------------\n";
cout << left << setw(18) << "Product Number"
<< left << setw(30) << "Name"
<< left << setw(15) << "Quantity"
<< left << setw(15) << "Unit Price";
cout << "\n--------------------------------------------------------------------------------\n";
for (int i = 0; i < 30; i++)
{
if (products[i].name.empty())
break;
cout << left << setw(18) << i + 1
<< left << setw(30) << products[i].name
<< left << setw(15) << products[i].quantity
<< left << setw(15) << products[i].price << "\n";
}
cout << "--------------------------------------------------------------------------------\n";
}
int main()
{
int x, choice, i = 0;
product products[30];
do
{
cout << "\n1. Add products" << endl
<< "2. Show all products" << endl
<< "3. Update a product" << endl
<< "4. Delete a product" << endl
<< "5. Exit" << endl
<< "Enter your choice: ";
cin >> choice;
switch (choice)
{
case 1:
cout << "Enter product name: ";
cin >> ws; // Clean whitespaces
getline(cin, products[i].name);
cout << "Enter product quantity: ";
cin >> products[i].quantity;
cout << "Enter unit price: ";
cin >> products[i].price;
i++;
break;
case 2:
show_products(products);
break;
case 3:
cout << "Enter product number: ";
cin >> x;
cout << "Enter product name: ";
cin >> ws; // Clean whitespaces
getline(cin, products[x - 1].name);
cout << "Enter product quantity: ";
cin >> products[x - 1].quantity;
cout << "Enter unit price: ";
cin >> products[x - 1].price;
break;
case 4:
cout << "Enter product number: ";
cin >> x;
for (int y = x; y < 30; y++)
{
cout << "Product Name: " << products[y - 1].name << endl;
if (products[y].name.empty())
{
products[y - 1].name = "";
break;
}
products[y - 1] = products[y];
}
break;
case 5:
break;
default:
cout << "-----------------------------------------"<<endl;
cout << "You have not chosen any choice yet"<< endl;
cout << "Enter any key to return to the main menu "<<endl;
cin >> ws;
break;
}
} while (choice != 5);
return 0;
}
/* C++ Language Used */
/* Product Management Program */
/* Update Functionality Added */
//File Inclusion
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//struture to to store product details
struct product
{
string name;
int quantity;
float price;
};
//Function to show prduct details
void show_products(product products[])
{
//Checking is product is not empty
if (products[0].name.empty())
{
cout << "\nYou have not added any product yet." << endl;
return;
}
//Displaying Formated Messages
cout << "\n\nAll Products";
cout << "\n--------------------------------------------------------------------------------\n";
cout << left << setw(18) << "Product Number"
<< left << setw(30) << "Name"
<< left << setw(15) << "Quantity"
<< left << setw(15) << "Unit Price";
cout << "\n--------------------------------------------------------------------------------\n";
//Displaying Product Description
for (int i = 0; i < 30; i++)
{
if (products[i].name.empty())
break;
cout << left << setw(18) << i + 1
<< left << setw(30) << products[i].name
<< left << setw(15) << products[i].quantity
<< left << setw(15) << products[i].price << "\n";
}
cout << "--------------------------------------------------------------------------------\n";
}
//Driver Function
int main()
{
//Data Variable
int x, choice, i = 0;
//Initialising First few object as hardcode
product products[30] = {
{"Laptop", 10, 2200},
{"HandPhone", 10, 1200},
{"Desktop", 10, 4000},
{"StudyTable", 10, 250},
{"SmartTv", 10, 800}
};
/* Do-While Loop
Iterate until user press 6
*/
do
{
//Displaying Menu
cout << "\n1. Add products" << endl
<< "2. Show all products" << endl
<< "3. Update a product" << endl
<< "4. Delete a product" << endl
<< "5. Purchase a product" << endl
<< "6. Exit" << endl
<< "Enter your choice: ";
//Taking choice
cin >> choice;
//Switching for choice
switch (choice)
{
case 1: //Case for adding products
cout<<"\n";
cout<<"Current Stock";
show_products(products);
cout << "\nEnter product name: ";
cin >> ws; // Clean whitespaces
getline(cin, products[i].name);
cout << "Enter product quantity: ";
cin >> products[i].quantity;
cout << "Enter unit price: ";
cin >> products[i].price;
i++;
break;
case 2: //Case for displaying products details
show_products(products);
break;
case 3: //Case for update a product
cout << "Enter product number: ";
cin >> x;
cout << "Enter product name: ";
cin >> ws; // Clean whitespaces
getline(cin, products[x - 1].name);
cout << "Enter product quantity: ";
cin >> products[x - 1].quantity;
cout << "Enter unit price: ";
cin >> products[x - 1].price;
break;
case 4: //Case for delete a product
cout << "Enter product number: ";
cin >> x;
for (int y = x; y < 30; y++)
{
cout << "Product Name: " << products[y - 1].name << endl;
if (products[y].name.empty())
{
products[y - 1].name = "";
break;
}
products[y - 1] = products[y];
}
break;
case 5: //Case for purchase a product
cout<<"\n";
cout << "Enter product number: ";
cin >> x;
x = x - 1;
//traversing in product array
for(int y = 0; y<30; y++)
{
//checking if entered number is same as prduct number
if(x == y)
{
//Displaying matched product details
cout<<"Product Found!";
cout<<"\nProduct Name : "<<products[x].name;
cout<<"\nProduct Price : "<<products[x].price;
cout<<"\nProduct Quantity : "<<products[x].quantity;
//Procedure to purchase
int quan;
mark:
//Taking input of quantity
cout<<"\n\nEnter Quantity to purchased : ";
cin>>quan;
//Checking if quantity available
if(quan < products[x].quantity)
{
cout<<"Product Purchased";
products[x].quantity = products[x].quantity - quan;
}
else
{
cout<<"Quantity Not Available";
goto mark;
}
}
}
break;
case 6:
break;
default: //Deafault Message
cout << "-----------------------------------------"<<endl;
cout << "You have not chosen any choice yet"<< endl;
cout << "Enter any key to return to the main menu "<<endl;
cin >> ws;
break;
}
} while (choice != 6);
return 0;
}
/* Main Function Ends */
Output:

1. in this programe i want add some products to be shown after choosing choise (...
The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...
C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...
Can I get help with adding the following to this code please? 1. When buying multiple tickets, if one of the seats selected is already taken, give a message like "Sorry, one or more of the seats selected is already taken." and prompt the user to select the seats all over. (Or if possible to make it suggest a location where the seats are together that the user can select instead) 2. Print the total cost after all of the...
The project I have is a link list that asks for a name and phone number and it allows the user to insert ,delete ,modify ,and find an element in the structure. The program has a menu in which the user can choose which function they want to use I need to use switch case to do this but it has not worked I need help with this. Thank you! #include <iostream> #include <string> #include <iomanip> using namespace std; const int...
using the source code at the bottom of this page, use the following instructions to make the appropriate modifications to the source code. Serendipity Booksellers Software Development Project— Part 7: A Problem-Solving Exercise For this chapter’s assignment, you are to add a series of arrays to the program. For the time being, these arrays will be used to hold the data in the inventory database. The functions that allow the user to add, change, and delete books in the store’s...
fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str; while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title); getline(inFile, books[size].Author); getline(inFile, books[size].publisher); getline(inFile,...
i have two issues that i need help. 1- that in case three and two only one line is being read from the file 2- my case 4 is not working correctly as it should as the output is only " Enter 1 for Trump, 2 for Warren:" #include <iostream> #include <cctype> // For the letter checking functions #include <fstream> // For file input #include <iomanip> // For setw #include <ctime> #include <cstdlib> // For exit and abs #include <errno.h>...
How can I make this compatible with older C++ compilers that DO NOT make use of stoi and to_string? //Booking system #include <iostream> #include <iomanip> #include <string> using namespace std; string welcome(); void print_seats(string flight[]); void populate_seats(); bool validate_flight(string a); bool validate_seat(string a, int b); bool validate_book(string a); void print_ticket(string passenger[], int i); string flights [5][52]; string passengers [4][250]; int main(){ string seat, flight, book = "y"; int int_flight, p = 0, j = 0; int seat_number,...
I need help in my C++ code regarding outputting the enums in string chars. I created a switch statement for the enums in order to output words instead of their respective enumerated values, but an error came up regarding a "cout" operator on my "Type of Item" line in my ranged-based for loop near the bottom of the code. I tried casting "i.type" to both "i.GroceryItem::Section::type" and "i.Section::type", but neither worked. Simply put, if a user inputs 1 as their...
Right now, program pushes all data to screen in three loops need to prompt user for three text files, and need to push data from each loop into those three text files. #include #include #include #include #include #include #include #include using namespace std; double random(double minprice, double maxprice); string printRandomString(int n); bool coinToss(); int clicks(); int runme(); int createfiles(); struct things{ //things(); int id; string name; string category; double price; bool two_day_shipping; int...