Hi everyone,
I am taking coding class and I couldn't figure out a homework question for the life of me (I might just be too dumb for coding Ha!). If you could help me out (as in write out the whole thing for me), I would really appreciate it (meaning I'll pay you). PLEASE PM ME! :)
Finally, let me slip in a little self defense here: I do want to learn how to code but right now is not a good time for me as I am in the process of applying for secondary schools!
To give you a little more information, this chapter focuses on file operation, binary file, random access files. Please focus on these basic concepts even if you know a better/faster way to solve it, thanks!
Here is the homework question:
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:
1. Add new records to the file
2. Display any record in the file
a. User will provide the name of the item or the first n letters of the name of the item
3. Change any record in the file (Note: if this option chosen, then the whole record must be
reentered even if the user wants to change only one or more fields)
4. Display all records
5. Prepare a report containing:
a. The total wholesale value of the inventory
b. The total retail value of the inventory
c. The total quantity of all values in the inventory.
Input validation: The program should not accept quantities or wholesale or retail
costs less than 0.
Here is what I have so far:
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
|
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <fstream>
#include <cctype>
#include <cstring>
using namespace std;
struct data
{
string name;
int quantity;
double wholeCost, retailCost;
};
int main()
{
fstream record ("record.txt", ios::out | ios::binary);
data inventory;
char more;
do
{
cout << "\nitem name: " ;
getline(cin, inventory.name);
cout << "quantity on hand: ";
cin >> inventory.quantity;
cin.ignore();
cout << "wholesale cost: ";
cin >> inventory.wholeCost;
cin.ignore();
cout << "retail cost: ";
cin >> inventory.retailCost;
cin.ignore();
record.write((char*)&inventory, sizeof(inventory));
cout << "\nEnter y if you would like to enter more data: ";
cin >> more;
cin.ignore();
}while (toupper(more)=='Y');
record.close();
}
|