Question
PLEASE ADD THE FOLLOWING SPECIFICATION TO THE PROGRAM I have add some of please check if they are working and please post the output as
PLEASE ADD THE FOLLOWING SPECIFICATION TO THE PROGRAM I have add some of please check if they are working and please post the output as well
// Specification C2 - Dynamic Array Create an array on the heap. Initialize it to 1 element. You will add elements as necessary.
3. // Specification C3 - Resize Array
Allows you to add records to the end of the inventory data structure you created. This is activated with the first menu option Above. Create a pTmp pointer variable for the new data structure. You will also subtract elements from the end as well.
//Specification B2 -RandNo Class
Create a random number class, RandNo. You will use this to re-turn the random number for the Wholesale cost (but you can make it flexible for other stuff too if you want). It should know seed initialization state and randomly set it once if needed.
// Specification B4 - Inventory Entry Input Validation Apply the first three validation rules from Table 1 to Add new item and Edit item (Spec A1) menu selections. Re-prompt if in- correct input. Create an InVal class or function to perform this check.
IMPORTANT ONES A2, A3! I HAVE NO IDEA HOW TO DO THESE TWO PLEASE HELP
// Specification A2 - Overload operator
Overload the stream extraction operator somewhere in your pro- gram. Im guessing the Inventory struct is the easiest place to do this.
// Specification A3 - Overload operator Overload the stream insertion operator for the RandNo class. This will be how you will enter a user specified seed. This method will prompt the user and use the integer value they provide as the random number seed - overwriting the time value if needed.
#include
using namespace std;
class InVal { private: std::string name; // Name of the item std::string description; // Description of the item double price; // Price of the item int quantity; // Quantity of the item public: InVal(const std::string& name, const std::string& description, double price, int quantity) { this->name = name; this->description = description; this->price = price; this->quantity = quantity; } std::string getName() const { return name; } void setName(const std::string& name) { this->name = name; } std::string getDescription() const { return description; } void setDescription(const std::string& description) { this->description = description; } double getPrice() const { return price; } void setPrice(double price) { this->price = price; } int getQuantity() const { return quantity; } void setQuantity(int quantity) { this->quantity = quantity; } void print() const { std::cout << "Name: " << name << std::endl; std::cout << "Description: " << description << std::endl; std::cout << "Price: " << price << std::endl; std::cout << "Quantity: " << quantity << std::endl; } };
class RandNo { private: int minVal; // Minimum value of the random number int maxVal; // Maximum value of the random number public: RandNo(int minVal, int maxVal) { this->minVal = minVal; this->maxVal = maxVal; srand(time(NULL)); // Seed the random number generator with the current time } int get() const { return rand() % (maxVal - minVal + 1) + minVal; } };
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 display_item(string file); void update_item(string file); void delete_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 < 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 search: "; cin>>itn; for(int j=0;j 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>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 "< 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;jtm_year <<" "; } f.close(); } int main(){ invntry inv; int ch; string f; cout<<"Enter file name: "; getline(cin, f); while(1){ cout<<" Enter your choice "; 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 "; cin>>ch; switch(ch){ case 1: inv.add_new(f);break; case 2: inv.display_item(f);break; case 3: inv.update_item(f);break; case 4: inv.delete_item(f);break; case 5: exit(0); default: cout<<"Invalid choice! "; } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started