Having trouble getting my program to run correctly. Would like to see where I\'m
ID: 3569392 • Letter: H
Question
Having trouble getting my program to run correctly. Would like to see where I'm going wrong from an example. Specifically having troubles with getting it to work with a class as a seperate file (.h file).
Problem:
You are the owner of a hardware store and need to keep an inventory that can tell you what different tools you have, how many of each you have on hand and the cost of each one. Write a program with menu to process Random-Access File. The menu has several options. First option is to open a random-access file. The program should prompt the user to enter the name of the file. If the file does not exist, the program should create the file with 100 empty records. The second option is to display all the valid records in the random-access file. The third option is to ask user to enter data for a new record. If the record already exists in the same record number, the new record will overwrite the old record. The fourth option is to exit the program.
The Random-Access Data File keeps the inventory of a hardware store. The file stores the part number (or record number between 1 to100), the tool name, the quantity on hand, and the cost of each tool.
Requirements:
a) Your program must produce the prompt and the output the same as given.
b) Your program should create a class named HardwareData containing the record data. Make sure you create get and set functions for each class member data.
Sample Run:
Enter 1 for opening data file.
Enter 2 for listing all the records.
Enter 3 for entering new records.
Enter 4 to exit the program.
------------------------------------
Choice: 1
Enter File name: Hardware.dat
File does not exist. Creating the data file.
Choice: 2
Record # Hardware data name Quantity Cost
Choice: 3
Enter the part number (0-99, -1 to end input): 5
Enter tool name: Hammer
Enter part number: (0-99, -1 to end): 9
Enter tool name: Nails
Enter Quantity and Price: 1000 5.50
Enter part number: -1
Choice: 2
Record # Hardwaredata name Quantity Price
5 Hammer 5 7.99
9 Nails 1000 5.50
Any assistance is appreciated. I cannot seem to get the class as a seperate file to work which is a requirement (it cannot all be one file).
Explanation / Answer
#include <iostream.h>
#include <math.h>
int main ()
{
int a, b, c, d, e, f, g, h, i, j;
int a1, b1, c1, d1, e1, f1, g1, h1, i1, j1;
int go, ia, ia1, ib, ib1, ic, ic1, id, id1, ie, ie1, fi, if1, ig, ig1, ih, ih1, ii, ii1, ij, ij1;
int na, nb, nc, nd, ne, nf, ng, nh, ni, nj;
int dec1a, dec2a, dec3a, dec4a, dec5a, dec6a, dec7a, dec8a, dec9a, dec0a;
char deca, decb, decc, decd, dece, decf, decg, dech, deci, decj;
char dec1, dec2, dec3, dec4, dec5, dec6, dec7, dec8, dec9, dec0;
char name[25];
cout<<"Good day! Your name is?"<<" ";
cout<<"[please key-in your first name]"<<" ";
cin>>name;
cout<<" ";
cout<<"Hello,"<<" "<<name<<"!"<<" "<<"Shall we start the day with keying-in"<<" ";
cout<<"our initial item count with the corresponding cost of each item?"<<" ";
cout<<"Please enter the needed data correctly as follows:"<<" ";
cout<<" ";
cout<<"Enter the initial quantity/number of SANDERS:"<<" ";
cin>>a;
cout<<" "<<"How much will each SANDER cost?"<<" ";
cout<<" "<<"$";
cin>>a1;
cout<<" "<<"Is this final and correct? [Y/N]";
cin>>deca;
if(deca=='N'||deca=='n')
{
cout<<"Enter the initial quantity/number of SANDER/S:"<<" ";
cin>>ia;
cout<<" "<<"How much will each SANDER cost?"<<" ";
cout<<" "<<"$";
cin>>ia1;
}
else if(deca=='Y'||deca=='y')
ia=a;
ia1=a1;
cout<<" ";
cout<<"Enter the initial quantity/number of HAMMER/S:"<<" ";
cin>>b;
cout<<" "<<"How much will each HAMMER cost?"<<" ";
cout<<" "<<"$";
cin>>b1;
cout<<" "<<"Is this final and correct? [Y/N]";
cin>>decb;
if(decb=='N'||decb=='n')
{
cout<<"Enter the initial quantity/number of HAMMER/S:"<<" ";
cin>>ib;
cout<<" "<<"How much will each HAMMER cost?"<<" ";
cout<<" "<<"$";
cin>>ib1;
}
else if(decb=='Y'||decb=='y')
ib=b;
ib1=b1;
cout<<" ";
cout<<"Enter the initial quantity/number of JIGSAW/S:"<<" ";
cin>>c;
cout<<" "<<"How much will each JIGSAW cost?"<<" ";
cout<<" "<<"$";
cin>>c1;
cout<<" "<<"Is this final and correct? [Y/N]";
cin>>decc;
if(decc=='N'||decc=='n')
{
cout<<"Enter the initial quantity/number of JIGSAW/S:"<<" ";
cin>>ic;
cout<<" "<<"How much will each JIGSAW cost?"<<" ";
cout<<" "<<"$";
cin>>ic1;
}
else if(decc=='Y'||decc=='y')
ic=c;
ic1=c1;
cout<<" ";
cout<<"Enter the initial quantity/number of MOWER/S:"<<" ";
cin>>d;
cout<<" "<<"How much will each MOWER cost?"<<" ";
cout<<" "<<"$";
cin>>d1;
cout<<" "<<"Is this final and correct? [Y/N]";
cin>>decd;
if(decd=='N'||decd=='n')
{
cout<<"Enter the initial quantity/number of MOWER/S:"<<" ";
cin>>id;
cout<<" "<<"How much will each MOWER cost?"<<" ";
cout<<" "<<"$";
cin>>id1;
}
else if(decd=='Y'||decd=='y')
id=d;
id1=d1;
cout<<" ";
cout<<"Enter the initial quantity/number of SAW/S:"<<" ";
cin>>e;
cout<<" "<<"How much will each SAW cost?"<<" ";
cout<<" "<<"$";
cin>>e1;
cout<<" "<<"Is this final and correct? [Y/N]";
cin>>dece;
if(dece=='N'||dece=='n')
{
cout<<"Enter the initial quantity/number of SAW/S:"<<" ";
cin>>ie;
cout<<" "<<"How much will each SAW cost?"<<" ";
cout<<" "<<"$";
cin>>ie1;
}
else if(dece=='Y'||dece=='y')
ie=e;
ie1=e1;
cout<<" ";
cout<<"Enter the initial quantity/number of SCREWDRIVER/S"<<" ";
cin>>f;
cout<<" "<<"How much will each SCREWDRIVER cost?"<<" ";
cout<<" "<<"$";
cin>>f1;
cout<<" "<<"Is this final and correct? [Y/N]";
cin>>decf;
if(decf=='N'||decf=='n')
{
cout<<"Enter the initial quantity/number of SCREWDRIVER/S:"<<" ";
cin>>ia;
cout<<" "<<"How much will each SCREWDRIVER cost?"<<" ";
cout<<" "<<"$";
cin>>ia1;
}
else if(decf=='Y'||decf=='y')
fi=f;
if1=f1;
cout<<" ";
cout<<"Enter the initial quantity/number of SLEDGEHAMMER/S:"<<" ";
cin>>g;
cout<<" "<<"How much will each SLEDGEHAMMER cost?"<<" ";
cout<<" "<<"$";
cin>>g1;
cout<<" "<<"Is this final and correct? [Y/N]";
cin>>decg;
if(decg=='N'||decg=='n')
{
cout<<"Enter the initial quantity/number of SLEDGEHAMMER/S:"<<" ";
cin>>ig;
cout<<" "<<"How much will each SLEDGEHAMMER cost?"<<" ";
cout<<" "<<"$";
cin>>ig1;
}
else if(decg=='Y'||decg=='y')
ig=g;
ig1=g1;
cout<<" ";
cout<<"Enter the initial quantity/number of WRENCH/ES:"<<" ";
cin>>h;
cout<<" "<<"How much will each WRENCH cost?"<<" ";
cout<<" "<<"$";
cin>>h1;
cout<<" "<<"Is this final and correct? [Y/N]";
cin>>dech;
if(dech=='N'||dech=='n')
{
cout<<"Enter the initial quantity/number of WRENCH/ES:"<<" ";
cin>>ih;
cout<<" "<<"How much will each WRENCH cost?"<<" ";
cout<<" "<<"$";
cin>>ih1;
}
else if(dech=='Y'||dech=='y')
ih=h;
ih1=h1;
cout<<" ";
cout<<"Enter the initial quantity/number of MALLET/S:"<<" ";
cin>>i;
cout<<" "<<"How much will each MALLET cost?"<<" ";
cout<<" "<<"$";
cin>>i1;
cout<<" "<<"Is this final and correct? [Y/N]";
cin>>deci;
if(deci=='N'||deci=='n')
{
cout<<"Enter the initial quantity/number of MALLET/S:"<<" ";
cin>>ii;
cout<<" "<<"How much will each MALLET cost?"<<" ";
cout<<" "<<"$";
cin>>ii1;
}
else if(deci=='Y'||deci=='y')
ii=i;
ii1=i1;
cout<<" ";
cout<<"Enter the initial quantity/number of SHOVEL/S:"<<" ";
cin>>j;
cout<<" "<<"How much will each SHOVEL cost?"<<" ";
cout<<" "<<"$";
cin>>j1;
cout<<" "<<"Is this final and correct? [Y/N]";
cin>>decj;
if(decj=='N'||decj=='n')
{
cout<<"Enter the initial quantity/number of SHOVEL/S:"<<" ";
cin>>ij;
cout<<" "<<"How much will each SHOVEL cost?"<<" ";
cout<<" "<<"$";
cin>>ij1;
}
else if(decj=='Y'||decj=='y')
ij=j;
ij1=j1;
cout<<" ";
cout<<" ";
cout<<"*******************SUMMARY INITIAL COUNTING*******************"<<" ";
cout<<" ";
cout<<"SANDER/S:"<<" "<<ia<<"piece/s sold at $"<<ia1<<" ";
cout<<" ";
cout<<"HAMMER/S:"<<" "<<ib<<"piece/s sold at $"<<ib1<<" ";
cout<<" ";
cout<<"JIGSAW/S:"<<" "<<ic<<"piece/s sold at $"<<ic1<<" ";
cout<<" ";
cout<<"MOWER/S:"<<" "<<id<<"piece/s sold at $"<<id1<<" ";
cout<<" ";
cout<<"SAW/S:"<<" "<<ie<<"piece/s sold at $"<<ie1<<" ";
cout<<" ";
cout<<"SCREWDRIVER/S:"<<" "<<fi<<"piece/s sold at $"<<if1<<" ";
cout<<" ";
cout<<"SLEDGEHAMMER/S:"<<""<<ig<<"piece/s sold at $"<<ig1<<" ";
cout<<" ";
cout<<"WRENCH/ES:"<<" "<<ih<<"piece/s sold at $"<<ih1<<" ";
cout<<" ";
cout<<"MALLET/S:"<<" "<<ii<<"piece/s sold at $"<<ii1<<" ";
cout<<" ";
cout<<"SHOVEL/S:"<<" "<<ij<<"piece/s sold at $"<<ij1<<" ";
cout<<" ";
cout<<"**************************************************************"<<" ";
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.