Starting from:

$35

First C++ project Solution

You are to implement an e-commerce site for selling household appliances, such as dishwashers, laundry machines, and clothes dryers. Your client is Ms. Rosey Sowpe, who owns an appliance shop. Your task for this project is to implement a proof-of-concept prototype in C++11. Your prototype will manage the appliances for sale in Ms. Sowpe’s site. Each appliance contains the following elds:




ID|This is a unique (integer) identi er for each appliance.



Type|The type of an appliance is an enumeration with possible values of LAUNDRY MACHINE, DISH WASHER, and DRYER.



Manufacturer|This is a string denoting the company making the appliance (e.g., \Whirpool").



Price|This is the price of the product in US dollars and cents.



Pictures|An array of le paths containing a list of pictures for each appliance in an appropriate format (e.g., PNG, JPEG, etc.)






The last item above is an array of strings denoting le paths. Each le path identi es a le containing a byte sequence meant to display a picture of an appliance on the user’s display. For the time being, you do not have to worry about creating, storing or displaying the images; you may assume that this functionality will be implemented by someone else. However, you must make provisions for the fact that images will be relatively large, making each appliance instance expensive to store in memory.




To avoid cluttering the primary memory of your computer with images, you must store your appliance instances in les most of the time. Each such le will contain information a single appliance instance including its ID, Type, Manufacturer, etc. Also, you should implement a smart pointer class called AppliancePtr that dynamically loads instances of class Appliance when they are needed and stores them back on le when done with an appliance.




You are to code a test version of the program that contains just 10 appliances denoted by unique IDs 0 through 9. Each of the ten instances is stored in a separate le. At any point in time, only three of the appliance instances can be stored in memory; the remaining instances exist only in the ten les associated with your project.




When the program is started, the program creates a linked list of 10 appliance pointers; however, none of the appliance instances are loaded in memory. Next, appliances are loaded from memory and stored back to les (possibly after being modi ed) as needed while executing the commands described next. However, you should never hold more than 3 appliance instances in memory at all times.




Your project should support the command line interface below; no GUI is needed for this project. Your command line interface will prompt the user for a command, and then execute the command. Here is a list of commands. Make sure not to cause any memory leaks or dangling pointers in the implementation of these commands.




l|List all appliances. Each appliance is loaded from disk and its information (ID, Type, etc.) is displayed in the user’s screen, including the list of le paths, but with no images of the appliance. Appliance instances are stored back on disk and deleted as needed to keep a maximum of three total appliances in memory at all times.









1












0 : : : 9|Edit a appliance. This command sets the numbered appliance to be the current appliance. If the appliance is not already in memory, it is loaded from disk and assigned to the corresponding appliance pointer. In this case, an appliance instance currently in memory may have to be stored back into its corresponding le and deleted from memory not to exceed the limit of 3 appliances.



c|Create an appliance. The user is prompted for the various elds in the appliance instance. The appliance is then stored to a le and associated smart pointer instance. The appliance’s ID must be between 0 and 9. If an appliance with the same ID existed before this appliance is created, the older appliance is deleted from both memory and the associated le.



p|This command changes the price of the current appliance. The user is prompted for a new number, which becomes the new price of the appliance. The current appliance is not saved to le as part of this command. The new content of current appliance is displayed in the user’s screen. The new price will be saved when the appliance instance is stored to its le.



s|Save all appliances. This command save the appliance(s) currently in memory to the correspond-ing le(s). First, the les are deleted (e.g., using the remove() function). Next, an ofstream instance is opened on the named le, and the appliance’s information is saved to the new le. Finally, the stream is closed.



q|Quits the appliance manager.



Implementation notes. Your appliance manager must meet the following requirements. First, each appliance pointer should handle exactly one appliance. Second, clients (i.e., your project code) should not be allowed to create or delete appliance instances directly; these functions are handled by the smart pointer. Third, clients should not be allowed to duplicate (copy) smart pointers, or to switch the appliance instance associated with a a given smart pointer instance. Fourth, the API of the AppliancePtr class should include both operator*() and operator-(). Finally, you must code the linked list yourself, without relying on classes de ned, e.g., in the Standard Template Library (STL) or other libraries.




You must work alone on this project. Save all your code in a collection of header and code les and submit a zip archive with a (short) readme le containing instructions on how to use your Appliance Manager. The archive should also contain sample text les describing your initial appliances. Submit the archive by clicking on the link provided with this assignment. Your code should compile under the GNU C++11 compiler. No late submissions will be accepted.












































































2

More products