1. Create a struct named Product with the following public properties to be used by the Store class below a. name, type

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

1. Create a struct named Product with the following public properties to be used by the Store class below a. name, type

Post by answerhappygod »

1 Create A Struct Named Product With The Following Public Properties To Be Used By The Store Class Below A Name Type 1
1 Create A Struct Named Product With The Following Public Properties To Be Used By The Store Class Below A Name Type 1 (42.75 KiB) Viewed 39 times
Solve it with c++ - pointers operator Overloading
Sample code Store.h -
#include <iostream>#include <string>#include "Product.h"using namespace std;#ifndef STORE_H#define STORE_Hstruct Product{ string name; double price; int quantity;};class Store{private: int n; Product* products;public: Store(){ n = 0; products = nullptr; } Store(int p){
}};
#endif
1. Create a struct named Product with the following public properties to be used by the Store class below a. name, type string, b. price, type double c. quantity, type int 2. Develop a class named Store with the following private members. a. n, type integer b. products, dynamically allocated array of Product 3. Add a default constructor that a. Sets n to 0 b. products to nullate 4. Add a defined constructor that a. takes an integer p as its parameter. p should be greater than 0 (validate, if not then set n to 0 and products to nullat). b. If p is greater than 0 then set p to n and ask user to input the details of n products (place each product in the products array) i.e. for each product the following information is to be entered i. name, a non-empty string ii. price, a double value that is 0 or greater, user may input any double value greater than 0 but the value is rounded to 2 decimal places before being placed in the products array iii. iv. quantity, an integer that is greater than 0 If user makes a mistake then they have to reenter the details of that product c. At the end the products array should contain n valid (see above for restrictions) products. 5. Add a copy constructor that a. Creates a deep copy of a store 6. Add a destructor that a. Frees up dynamically allocated memory 7. Overload the following operators for your class a. =: Creates a deep copy of the store on the right hand side of the operator i. For example, suppose that there are two stores s1 and s2, then s2 = s1; will create a deep copy of s1 and set it to s2 b. <<: Outputs n, then all n products (including all information for each product). You decide on formatting, all information must be clearly visible, two consecutive products must be separated clearly c. >>: Asks user to input a non-zero integer k (must repeatedly validate until a non- zero value is received) then user inputs k product's information and these are added to the products array, n increases by k, for each product user inputs i. name, a non-empty string
ii. price, a double value that is 0 or greater, user may input any double value greater than 0 but the value is rounded to 2 decimal places before being placed in the products array iii. quantity, an integer that is greater than 0 iv. If user makes a mistake then they have to reenter the details of that product d. +: Can be used in two ways i. e. Union of two stores, s1+ s2 returns a new store that contains products from stores s1 and s2 (products with same name (case-insensitive matching) and price must have their quantities added together rather than creating separate products) ii. when used like s1 + t where s1 is a store and t is an integer then user has to add t products to the store. for each product user inputs 1. name, a non-empty string 2. price, a double value that is 0 or greater, user may input any double value greater than 0 but the value is rounded to 2 decimal places before being placed in the products array 3. quantity, an integer that is greater than 0 4. If user makes a mistake then they have to reenter the details of that product -: Can be used in two ways i. Unique elements between two stores, s1 - s2 returns a new store that contains only the unique items from stores s1 and s2, uniqueness is determined based on product name (case-insensitive matching) and price. ii. When used like s1 - t where s1 is a store and t is an integer, this operation removes t products from the store. If store has less than or equal to t products then all products are removed. Otherwise, User inputs names of products to remove one at a time (if product does not exist then ignore that input, if multiple products match that name then remove them all). 8. Write a main method and test all features of the class. 9. You are welcome to add more data members and/or method members to the class as you deem necessary.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply