Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use clion to do the code! ItemInfo # int: itemId # char [40]: description # double: manCost # double: sellPrice void setItemId(char *) void

Please use clion to do the code!

ItemInfo

# int: itemId # char [40]: description # double: manCost # double: sellPrice

void setItemId(char *) void setDescription(char *) void setManCost(char*) void setSellPrice(char *) int getItemId() char *getDescription() double getManCost() double getSellPrice() void toAmazonJSON(ostream &) void displayItemInfo(ostream &) double calcProfit()

We are going to make our fortunes selling items on Amazon. We have a Product Service of drop ship items that sends us a text file each day with the best deals for tomorrow. With potentially 1000s of entries each day, we have grown weary of reading these text files every day then manually entering our top selections into our Amazon storefront. Fortunately, a discussion with a former classmate at Baylor Homecoming lead to our discovery of the existence of an interface provided by Amazon for stores just like ours. The format is known as JSON (JavaScript Object Notation). Apparently, Amazon has just added the functionality recently, and we are more willing to invest the time to produce files that follow the format required by Amazon. Our current selling strategy has been to only sell the top 5 products form the products sent by the Product Service. The top products are selected based off the most profit strategy. We have been calculating the profit of a particular item by taking the difference between the manufacturing cost (our cost) and the predicted sell price which is provided to us by the Product Service text file. In a later class we will learn that we can set up something that allows us to execute the program we just wrote automatically. So, eventually we will be able to post our items of the day without any direct interaction from us. In fact, we could be playing golf when the items of the day are selected and submitted to Amazon. Our boss will never know that we came into work 2 hours late. Shhhh. Our program will need to parse the text file provided by the Product Service . The file is stored in a common file format know as comma delimited files or comma separated values (.csv) with the following format. itemId,decription,manufacturingCost,sellingPrice itemId,decription,manufacturingCost,sellingPrice itemId,decription,manufacturingCost,sellingPrice ... itemId,decription,manufacturingCost,sellingPrice Our program will store each item from the file into an array of objects.

The class we will write for this will be named ItemInfo. Here is a quick view of the ItemInfo class. ItemInfo # int: itemId # char [40]: description # double: manCost # double: sellPrice void setItemId(char *) void setDescription(char *) void setManCost(char*) void setSellPrice(char *) int getItemId() char *getDescription() double getManCost() double getSellPrice() void toAmazonJSON(ostream &) void displayItemInfo(ostream &) double calcProfit()

Here is an example JSON format required by Amazon generated from the following Product Service items. 54321,Womens S Tank,2.14,19.99 12345,Mens L Graphic Tee,5.35,12.99 AarsStore: [ firstItem: { itemId: 54321, description: Womens S Tank, manPrice: 2.14, sellPrice: 19.99 }, secondItem: { itemId: 12345, description: Mens L Graphic Tee, manPrice: 5.35, sellPrice: 12.99 } ]

Here is an example of the displayItemInfo output generated from the sample Product Service items described above. This example shows the output generated for the first ItemInfo in the list. itemId: 54321 description: Womens S Tank manCost: 2.14 sellPrice: 12.99 calculatedProfit: 10.85 General Algorithm with Constraints and other Requirements: So the program should open the csv file from our product service with the current list of items.

Since we need to learn how to parse files like a computer, you will need to read in the file a character at a time instead of using the >> operator. This will help you get into the habit of reading files looking for things, in this case a comma. Features that do automatic conversion during reading from file are off limits in your implementation for this project. Usage of such features will result in 0 on the assignment. You will put what your read from the file into a large character buffer called buffer with a capacity of 500. char buffer[500]; Once your read in a value you will send that to the appropriate function in the InfoItem class (setItemId(), setManCost(), etc). Since we spent all that time talking about the implementation of strcpy(), strcat(), strlen() in class for Chapter 12, the use of the STL String, all the cstring functions, and all cstring to number conversions will also be off limits in this implementation, ie. Implementation of setItemId(), setManCost(), etc. Usage of such functions will result in 0 on the assignment Since we dont know how many items will be found in the file, we wont know a priori how large to make our array of InfoItem objects. Therefore, we will need to manage an array so that it can grow as needed on the heap. To make this work, you will need to keep separate values for capacity of the array and used to track how much of the array is currently being used. Your initial capacity of this array should start at 2. Your array should automatically grow whenever you realize that the used value equals capacity value (array is full), but you need to add one more. You should write a function in your main.cpp file that resizes the array by adding 2 more spots to your array to remedy this issue. Resizing arrays is very important to know how to do safely. Hence the overboard practice of only adding 2 each time here. Once the csv file is completely read and all ItemInfos are happy in the array, you will need to order the array as to have the most profitable items at the top. Sort array by profit. Once your appropriate sorting is complete, you will need to make a function that knows how to print the first 5 ItemInfo objects in the array to the screen in required JSON format. In another iteration of this program, we will write the top 5 JSON objects to a file; but not right now. These 5 ItemInfo objects should represent the most profitable items in the feed we received from our product service.

Dont forget to return all memory back in an organized way. A memory leak will cost 20 points. You will need to create your own mock version of proj2-productServices.csv for testing your solution locally. I recommend that you create your version of the file using Microsoft Excel or Apple Numbers. You will then need to save the file you created as a .csv file. Heres an example of what the Excel or Numbers file will look like. Deliverables: proj2-ItemInfo.cpp (Implement each of the function prototypes in proj2-ItemInfo.hpp) proj2-main.cpp (Solve the problem presented earlier in this document) proj2-testmain.cpp (Fully test each function you wrote as independently as possible) proj2-productServices.csv (One of your mock data files) Provided: proj2-ItemInfo.hpp

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions