Inventory Program (C++)
Write a program that uses a structure to store the following inventory data in a file:
- Item Description
-Quantity on Hand
-Wholesale cost
-Retail cost
-Date Added to Inventory
The program should have a menu that allows the user to perform the following tasks:
-Add new records to file
-Display any record in the file
-Change any record in the file
Input Validation: The program should not accept quantities, or wholesale or retail costs, less than 0. The program should not accept dates that the programmer determines are unreasonable.
Solution
#include <iostream> #include <fstream> #include <cctype> using namespace std; const int DESCRIPTIONSIZE = 50, DATASIZE = 10; struct strinventory { char description[DESCRIPTIONSIZE]; int qty; int wholesaleCost; int retailCost; char dateAdded[DATASIZE]; }; // function declaration void createstrinventory(strinventory &, fstream &, int &); int displaymenu(); void newRecord(strinventory &, fstream &, int &); void displayRecord(strinventory &, fstream &, int ); void changeRecord(strinventory &, fstream &, int ); //main function int main() { int totRecords = 0; int chocice = 0; // creating the file if the file already exists fstream inventoryFile("Inventory.dat", ios::in | ios::out | ios::binary | ios::trunc); strinventory product; if (!inventoryFile) { cout << "Error opening the file"<<endl; } createstrinventory(product, inventoryFile, totRecords); while (chocice != 4) { chocice = displaymenu(); switch (chocice) { case 1: newRecord(product,inventoryFile,totRecords); break; case 2: displayRecord(product,inventoryFile,totRecords); break; case 3: changeRecord(product, inventoryFile, totRecords); break; case 4: break; default: cout << "Invalid choice\n"; } } cout << "Program end\n"; // close the file inventoryFile.close(); return 0; } // *=== END MAIN FUNCTION ===* // function definitions ================================================== // ====== FUNCTION DEFINITION ====== // let user fill in info for a product // user can create as many records as necessary void createstrinventory(strinventory &product, fstream &fileName, int &records) { char choiceaddrec; int totRecords = 0; do { cout << "Enter the details of the product:\n"; cout << "Item Description: "; cin.getline(product.description, DESCRIPTIONSIZE); do { cout << "Quantity on hand: "; cin >> product.qty; cin.ignore(); } while (product.qty < 0); do { cout << "Wholesale cost: "; cin >> product.wholesaleCost; cin.ignore(); } while (product.wholesaleCost < 0); do { cout << "Retail cost: "; cin >> product.retailCost; cin.ignore(); } while (product.retailCost < 0); do{ cout << "Date added to inventory (MM/DD/YYYY): "; cin.getline(product.dateAdded, DATASIZE); } while (!(ispunct(product.dateAdded[2])) || !(ispunct(product.dateAdded[5]))); fileName.write(reinterpret_cast<char *>(&product), sizeof(product)); cout << "Do you want to write another record? (y for yes)\n"; cin >> choiceaddrec; cin.ignore(); ++totRecords; } while (choiceaddrec == 'Y' || choiceaddrec == 'y'); records += totRecords; } int displaymenu() { int choice; cout << "\n\n =================================\n"; cout << "\tMenu\n"; cout << "Choose a chocice:\n"; cout << "1) add new records to the file\n"; cout << "2) display any record in the file\n"; cout << "3) change any record in the file\n"; cout << "4) Quit\n"; cout << "\n =================================\n\n"; cin >> choice; cin.ignore(); return choice; } void newRecord(strinventory &product,fstream &fileName, int &records) { fileName.clear(); // clear flags int numRecordAdded = 0; // number of new records added char choiceaddrec; // To hold Y or N // go to the end of the file to append the new record fileName.seekg(0L, ios::end); cout << "\n\tAdd new records\n"; do { cout << "Enter the following data about a product:\n"; cout << "Item Description: "; cin.getline(product.description, DESCRIPTIONSIZE); do { cout << "Quantity on hand: "; cin >> product.qty; cin.ignore(); } while (product.qty < 0); do { cout << "Wholesale cost: $"; cin >> product.wholesaleCost; cin.ignore(); } while (product.wholesaleCost < 0); do { cout << "Retail cost: $"; cin >> product.retailCost; cin.ignore(); } while (product.retailCost < 0); do{ cout << "Date added to strinventory (MM/DD/YYYY): "; cin.getline(product.dateAdded, DATASIZE); } while (!(ispunct(product.dateAdded[2])) || !(ispunct(product.dateAdded[5]))); fileName.write(reinterpret_cast<char *>(&product), sizeof(product)); cout << "Do you want to write another record? (y for yes)\n"; cin >> choiceaddrec; cin.ignore(); ++numRecordAdded; } while (choiceaddrec == 'Y' || choiceaddrec == 'y'); records += numRecordAdded; } void displayRecord(strinventory &product, fstream &fileName, int records) { fileName.clear(); // clear flags cout << "\n\tDisplay a record\n"; int recNum; // seek the file to the beginning fileName.seekg(0L, ios::beg); cout << "You have " << records << " records" << endl; cout << "Which record would you like to display? "; cin >> recNum; cin.ignore(); --recNum; // minus 1 to seek properly // seek to the record, store(read it), and display it fileName.seekg(sizeof(product) * recNum, ios::beg); fileName.read(reinterpret_cast<char *>(&product), sizeof(product)); cout << "Displaying record #" << (recNum + 1) << endl << endl; cout << "Item description: " << product.description << endl; cout << "Quantity on hand: " << product.qty << endl; cout << "Wholesale cost: " << product.wholesaleCost << endl; cout << "Retail cost: " << product.retailCost << endl; cout << "Date added to strinventory (MM/DD/YYYY): " << product.dateAdded << endl; // seek the file back to the beginning fileName.seekg(0L, ios::beg); } void changeRecord(strinventory &product, fstream &fileName, int records) { fileName.clear(); // clear flags int recCh; // record to change cout << "\n\tChange a record\n"; cout << "You have " << records << " records" << endl; cout << "Which record would you like to change? "; cin >> recCh; cin.ignore(); --recCh; // minus 1 to seek properly // seek to the record fileName.seekg(sizeof(product) * recCh, ios::beg); // let the user change the record cout << "Changing record #" << (recCh + 1) << endl << endl; cout << "Enter the following data about a product:\n"; cout << "Item Description: "; cin.getline(product.description, DESCRIPTIONSIZE); do { cout << "Quantity on hand: "; cin >> product.qty; cin.ignore(); } while (product.qty < 0); do { cout << "Wholesale cost: $"; cin >> product.wholesaleCost; cin.ignore(); } while (product.wholesaleCost < 0); do { cout << "Retail cost: $"; cin >> product.retailCost; cin.ignore(); } while (product.retailCost < 0); do{ cout << "Date added to strinventory (MM/DD/YYYY): "; cin.getline(product.dateAdded, DATASIZE); } while (!(ispunct(product.dateAdded[2])) || !(ispunct(product.dateAdded[5]))); // rewrite over record in the file fileName.write(reinterpret_cast<char *>(&product), sizeof(product)); // seek the file back to the beginning fileName.seekg(0L, ios::end); cout << "The file has been rewritten\n"; }
Screenshot
Inventory Program (C++) Write a program that uses a structure to store the following inventory data...
please write in C++ Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or the keyboard Item name (string) Quantity on hand(int) Wholesale cost(double) Retail Cost(double) The program should have a menu that allows the user to perform the following tasks: Add new records to the file Display any record in the file User will provide the name of the item or the...
Write a C++ program that uses a structure to store the following inventory information in a file: ⦁ Item description, Quantity on hand, Wholesale cost, Retail cost, and Date added to inventory. ⦁ Use a char array for item description and date. ⦁ The program should have a menu that allows the user to perform the following tasks: i. Add a new record at the end of the file. ii. Display any record in the file. iii. Change any record...
Write a program that uses a structure to store the following data about a customer account: Name Address City, state, and ZIP Telephone number Account Balance Date of last payment The program should use an vector of at least 20 structures. It should let the user enter data into the vector, change the contents of any element, and display all the data stored in the array. The program should have a menu-driven user interface. Input Validation: When the data for...
C++ program
Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....
Write a C program that takes inventory data from a file and
loads a structure of up to 100 items
defined as:
struct item
{
int item_number;
char item_name[20];
char item_desc[30];
float item_price;
}
I called mine: struct item inventory[100]; (you may use any name
you wish)
I will let you decide the appropriate prompts and edit messages.
You will read the data
from the data file and store the info in an array. Assume no
more than 100 records...
Customer Accounts This program should be designed and written by a team of students. Here are some suggestions: Write a program that uses a structure to store the following information about a customer account: • Name • Address • City, state, and ZIP • Telephone number • Account balance • Date of last payment The structure should be used to store customer account records in a file. The program should have a menu that lets the user perform the following...
You are to write a program IN C++ that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: if the an item's wholesale cost is 5.00 and its markup percentage is 100%, then the item's retail price is 10.00 If an item's wholesale cost is 5.00 and its markup percentage is 50%, then the item's retail price is 7.50 Program design specs. You should have 5...
Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses the following menu and can perform all menu items: Enter a payroll record for one person Display all paycheck stubs Display total gross payroll from all pay records. Quit program The program will reuse the DATE struct from the previous assignment. You should also copy in the functions relating to a DATE. The program will create a PAYRECORD struct with the following fields: typedef struct...
I need help with my homework please. I should write this program
in C++ language and use Inventory.h file (header file),
Inventory.cpp file (implementation file), and main.cpp file (main
program).
This is the program:
Demonstrate the class in a driver program. Input validation,
don’t accept negative values for item number, quantity, or
cost.
6. Inventory Class Design an Inventory class that can hold information and calculate data for items ma retail store's inventory. The class should have the following private...
Write a program that keeps track of a speakers’ bureau. The program should use a structure to store the following data about a speaker: (this is in C++) Name Telephone Number Speaking Topic Fee Required The program should use a vector of structures. It should let the user enter data into the vector, change the contents of any element, and display all the data stored in the vector. The program should have a menu-driven user interface. Input Validation: When the...