THIS IS A C++ CODE. Your significant other has had a flash of inspiration - the
ID: 3870758 • Letter: T
Question
THIS IS A C++ CODE.
Your significant other has had a flash of inspiration - the world needs
another inventory management program! You agreed to write it for
them because love is indeed blind. Create a class with at least the
following fields:
• Item Description
• Quantity at Hand (Cannot be negative)
• Wholesale Cost (Cannot be negative, nor less then 5 dollars)
• Retail Cost (automatically calculate 100% markup)
• Date Added to Inventory (System should enter this)
Create a numeric style menubar which allows the following tasks:
• Add new records to inventory.
• Display any record in inventory.
• Change any record in inventory.
• Delete any record in inventory.
• Exit the program.
• Validate the menu selection (Do not allow other choices)
Constraints.
• Use input validation for the data.
• You should be able to store an unlimited number of items. Create
a dynamic memory structure to do this.
• Use file I/O to save and recall your data.
• Load the data file when the program starts and save the data file
when you quit.
• Use OOP methods and the standard style issues from earlier
homework
• Calculate and display the wholesale value of the inventory.
• Add a menu item to dump the entire inventory to screen.
• Display output as a webpage.
Explanation / Answer
#include<iostream>
#include<fstream>
#include<sstream>
#include<time.h>
#include<ctime>
#include<iomanip>
#include<stdlib.h>
using namespace std;
class invntry{
public:
int qty_in_hand, whlsl_cost, rtl_cost;
time_t theTime;
struct tm *aTime;
string it_name ;
invntry(){
theTime = time(NULL);
aTime = localtime(&theTime);
whlsl_cost = 5;
qty_in_hand = 0;
}
void add_new(string file);
void disp_item(string file);
void update_item(string file);
void del_item(string file);
};
void invntry::add_new(string file){
int c=1,i=0;
string data;
ifstream in;
in.open(file.c_str());
cout<<"Enter item name:-";
cin>>it_name;
cout<<"Enter Wholesale cost:-";
cin>>whlsl_cost;
cout<<"Enter quantity:-";
cin>>qty_in_hand;
rtl_cost = whlsl_cost * 2;
ofstream f;
f.open(file.c_str(),ios::app);
f <<it_name <<" "<<whlsl_cost<<" "<<qty_in_hand<<" "<<rtl_cost<<" "<< aTime->tm_year <<" ";
f.close();
cout<<"Item "<<it_name<<" added successfully... ";
}
void invntry::disp_item(string file){
int c=0,i=0,flag=0;
string data;
ifstream in,inn;
in.open(file.c_str());
while(getline(in, data))
c++;
string *items = new string[c];
int *qtys = new int[c];
int *wsc = new int[c];
int *rtc = new int[c];
string itn;
int qt,wc,rc;
inn.open(file.c_str());
while(getline(inn, data)){
istringstream ss(data);
ss>>itn>>qt>>wc>>rc;
items[i] = itn;
qtys[i] = qt;
wsc[i] = wc;
rtc[i] = rc;
i++;
}
cout<<"Enter the item name to seach:-";
cin>>itn;
for(int j=0;j<i;j++){
if(itn == items[j]){p
flag++;
cout<<" Here is what you searching for... ";
cout<<items[j]<<" "<<qtys[j]<<" "<<wsc[j]<<" "<<rtc[j]<<" ";
}
}
if(flag==0)
cout<<"Name not found... ";
}
void invntry::update_item(string file){
int c=0,i=0,flag=0;
string data;
ifstream in,inn;
in.open(file.c_str());
while(getline(in, data))
c++;
string *items = new string[c];
int *qtys = new int[c];
int *wsc = new int[c];
int *rtc = new int[c];
string itn;
int qt,wc,rc;
inn.open(file.c_str());
while(getline(inn, data)){
istringstream ss(data);
ss>>itn>>qt>>wc>>rc;
items[i] = itn;
qtys[i] = qt;
wsc[i] = wc;
rtc[i] = rc;
i++;
}
cout<<"Enter the item name to change:-";
cin>>itn;
char ch;
for(int j=0;j<i;j++){
if(items[j]==itn){
flag =1;
cout<<"Enter n, q, w, r for changing name, quantity, wholesale_price, retail_price respectively:-";
cin>>ch;
if(ch == 'n'){
cout<<"Enter new name:-";
cin>>itn;
items[j]= itn;
break;
}
if(ch == 'q'){
cout<<"Enter new quantity:-";
cin>>qt;
qtys[j]= qt;
break;
}
if(ch == 'w'){
cout<<"Enter new whole sale price:-";
cin>>wc;
wsc[j]= wc;
break;
}
if(ch == 'r'){
cout<<"Enter new retail price:-";
cin>>rc;
rtc[j]= rc;
break;
}
cout<<"The item "<<itn<<" is updated successfully... ";
}
}
if(flag==0)
cout<<"Name not found... ";
ofstream f;
f.open(file.c_str());
for(int j =0;j<i;j++)
f <<items[j] <<" "<<wsc[j]<<" "<<qtys[j]<<" "<<rtc[j]<<" "<< aTime->tm_year <<" ";
f.close();
}
void invntry::del_item(string file){
int c=0,i=0,flag=0;
string data;
ifstream in,inn;
in.open(file.c_str());
while(getline(in, data))
c++;
string *items = new string[c];
int *qtys = new int[c];
int *wsc = new int[c];
int *rtc = new int[c];
string itn;
int qt,wc,rc;
inn.open(file.c_str());
while(getline(inn, data)){
istringstream ss(data);
ss>>itn>>qt>>wc>>rc;
items[i] = itn;
qtys[i] = qt;
wsc[i] = wc;
rtc[i] = rc;
i++;
}
cout<<"Enter the item name to delete:-";
cin>>itn;
for(int j=0;j<i;j++){
if(itn == items[j]){
flag = 1;
items[j] = "00";
cout<<"The item "<<itn<<" is deleted successfully... ";
}
}
if(flag==1){
cout<"Name not found... ";
}
ofstream f;
f.open(file.c_str());
for(int j =0;j<i;j++){
if(items[j]=="00")
continue;
f <<items[j] <<" "<<wsc[j]<<" "<<qtys[j]<<" "<<rtc[j]<<" "<< aTime->tm_year <<" ";
}
f.close();
}
int main(){
invntry inv;
int ch;
string f;
cout<<"Enter file name:=";
getline(cin, f);
while(1){
cout<<" 1.Add new record ";
cout<<"2.Display any record ";
cout<<"3.Change any record ";
cout<<"4.Delete any record ";
cout<<"5.Exit the program ";
cout<<"Enter your choice ";
cin>>ch;
switch(ch){
case 1: inv.add_new(f);break;
case 2: inv.disp_item(f);break;
case 3: inv.update_item(f);break;
case 4: inv.del_item(f);break;
case 5: exit(0);
default: cout<<"Invalid choice... ";
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.