Combine the three parts (above) and add a menu to:
1) initialize,
2) output all records,
3) edit a record,
4) exit program.
i can not do initialize . can somebody explain to me ? thank you.
this is my code.
#include <iostream>
#include <fstream>
using namespace std;
const int DESC_SIZE = 31,NUM_RECORDS = 5;
struct inventory
{
char desc[DESC_SIZE];
int qty;
double price;
};
int menu();
int initialize(inventory record);
void displayAll(inventory record, fstream &, int NUM_RECORDS);
void modify(inventory record, fstream &, int NUM_RECORDS);
cout<<"Please make a menu choice for the task you which to accomplish"<<"\n";
cout<<"\n";
cout<<" 0: initialize records to the file"<<"\n";
cout<<" 1: Display all records in the file"<<"\n";
cout<<" 2: Change any record in the file"<<"\n";
cout<<" 3: Quit this program"<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"Enter menu choice now ";
cin>>choice;
cout<<"\n";
if (choice <0 || choice > 3)
cout<<"You must select a numeric choice from the menu (0, 1, 2, 3)"<<"\n";
void modify(inventory record, fstream &inventory, int NUM_RECORDS)
{
int recNum;
cout<<"Which record do you want to edit? ";
cin>>recNum;
if ( (recNum > (NUM_RECORDS-1) ) || (recNum < 0 ))
{
cout<<"That record does not exist and can't be edited! "<<"\n";
}
else
{
inventory.seekg(recNum *sizeof(record), ios::beg);
inventory.read(reinterpret_cast<char*>(&record), sizeof(record));
cout<<"The current item description: "<<record.desc<<"\n";
cout<<"The current qty: "<<record.qty<<"\n";
cout<<"The current Price: "<<record.price<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"The new description for item: ";
cin.ignore();
cin.getline( record.desc,31);
cout<<"\n";
cout<<"The new qty is: ";
cin>>record.qty;
cout<<"\n";
cout<<"The new Price is: ";
cin>>record.price;
cout<<"\n";