Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NOTE : CODE IN C++ Your signicant other has had a ash of inspiration - the world

ID: 3753444 • Letter: N

Question

NOTE : CODE IN C++
Your signicant other has had a ash of inspiration - the world needs another inventory management program! You agreed to write it for them because love is indeed blind. Table 1 has the minimum elds you will need as well as the validation rules for Specication A2.

(NOTE : This is a table)
Field Name:Item Description ,| Quantity at Hand ,| Retail Cost    ,| Date Added to Inventory

Validation Rules: 22 characters max ,| Cannot be negative,| Automatically calculate 100% markup, |System should enter this

  
Table 1: Data dictionary for Inventory data structure.

REQUIRMENTS :
• This is a menu driven program. You can decide if it uses a numeric or alphabetic menu. Keep prompting and running until the quit option is selected.

• Make you code as reliable as possible.

• Make your program output easy to read.

• You cannot use anything from the standard template library.

• Use functions whenever possible to modularize your code. Use function prototypes and code the functions under main().

• Style guide elements apply: comments, layout, Program Greeting, Source File Header, and variables etc. etc

"C" SPECIFICATION BUNDLE:

1. // Specication C1 - Dynamic Array Create an array on the heap. Increase it automatically for every item the client adds. That is, this array should be as small as possible - always.

2. // Specication C2 - Add Option Allows you to add records to the inventory data structure you created.

3. // Specication C3 - Display Option Displays all the information in your inventory data structure.

4. // Specication C4 - Main Menu Create a main menu which lists the allowable behaviors. See gure 1 for an example menu.

5. // Specication C5 - Validate Menu Print the letter grade for the gpa right next to it raw number.


"C" Bundle Menu Options. 1. Add Inventory 2. Display Inventory 3. Quit Program Figure 1: Allowable menu options for this bundle.


"B" SPECIFICATION BUNDLE:

1. // Specication B1 - OOP Code this assignment using at least one class. Put this comment above the class declaration.

2. //Specication B2 - Delete Inventory Item Allow the client to delete items in the inventory data structure. See gure 2 for the "B" menu. Don’t forget to update C5 to account for this new menu option.

3. // Specication B3 - Shrink Dynamic Array Resize the dynamic array when you delete inventory.


"B" Bundle Menu Options. 1. Add Inventory 2. Delete Inventory 3. Display Inventory 4. Quit Program Figure 2: Allowable menu options for this bundle.


"A" Bundle Menu Options. 1. Add Inventory 2. Delete Inventory 3. Edit Inventory 4. Display Inventory 5. Quit Program Figure 3: Allowable menu options for this bundle.


"A" SPECIFICATION BUNDLE :

1. // Specication A1 - Edit Inventory Add the capability to edit the contents of any inventory item. Edit is different from delete. See gure 3 for the "A" menu. Don’t forget to update C5 to account for this new menu option.

2. // Specication A2 - Validate Inventory Only allow data which meets the input specications in the inventory data structure

3. // Specication A3 - Logle Log all changes to the inventory data structure to a text le for archival purposes.

4. // Specication A3 - Replace A3 with one feature of your own choosing. You can code A3 as it appears if you wish and skip this.

Thanks in advance

Explanation / Answer

SOURCE CODE IN C++:

#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... ";

}

}

}