Question
Please use C++ (clion) Our program will need to parse the text file provided by the Product Service . The file is stored in a
Please use C++ (clion)
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.
#ifndef ITEMINFO_H
#define ITEMINFO_H
#include
#include
using namespace std;
class ItemInfo {
private:
int itemId;
char description[40];
double manCost;
double sellPrice;
public:
ItemInfo() {
itemId = 0;
*description = '\0';
manCost = 0.0;
sellPrice = 0.0;
}
/**
* setItemId
*
* This function stores an integer representation of a cstring into the itemId data
* member of the ItemInfo class.
*
* Parameters:
* num: a cstring representation of an integer value
*
* Output:
* return: none
* reference parameters: none
* stream: none
*/
void setItemId(const char *num);
/**
* setDescription
*
* This function stores a copy of the passed cstring into the description data member
* of the ItemInfo class
*
* Parameters:
* cstr: a cstring containing the description of the product
*
* Output:
* return: none
* reference parameters: none
* stream: none
*/
void setDescription(const char *cstr);
/**
* setManCost
*
* This function stores an double representation of a cstring into the manCost data
* member of the ItemInfo class.
*
* Parameters:
* num: a cstring representation of an double value
*
* Output:
* return: none
* reference parameters: none
* stream: none
*/
void setManCost(const char *num);
/**
* setSellPrice
*
* This function stores an double representation of a cstring into the sellPrice data
* member of the ItemInfo class.
*
* Parameters:
* num: a cstring representation of an double value
*
* Output:
* return: none
* reference parameters: none
* stream: none
*/
void setSellPrice(const char *num);
/**
* getItemId
*
* This function returns a copy of the value stored in the itemId data memeber of the
* ItemInfo class.
*
* Parameters: none
*
* Output:
* return: a copy of itemId
* reference parameters: none
* stream: none
*/
int getItemId();
/**
* getDescription
*
* This function returns a const reference to the description data member of the
* ItemInfo class.
*
* Parameters: none
*
* Output:
* return: a const reference to description
* reference parameters: none
* stream: none
*/
const char *getDescription();
/**
* getManCost
*
* This function returns a copy of the value stored in the manCost data memeber of the
* ItemInfo class.
*
* Parameters: none
*
* Output:
* return: a copy of manCost
* reference parameters: none
* stream: none
*/
double getManCost();
/**
* getSellPrice
*
* This function returns a copy of the value stored in the sellPrice data memeber of
* the ItemInfo class.
*
* Parameters: none
*
* Output:
* return: a copy of sellPrice
* reference parameters: none
* stream: none
*/
double getSellPrice();
/**
* toAmazonJSON
*
* This function outputs the data members of the ItemInfo class in a JSON formate
* specified by Amazon.
*
* Parameters:
* out: the ouput stream for the JSON format
*
* Output:
* return: none
* reference parameters: the updated ostream
* stream: none
*/
void toAmazonJSON(ostream &out);
/**
* displayItemInfo
*
* This function outputs the data members of the ItemInfo class in a formate specified
* by Prof. Aars.
*
* Parameters:
* out: the ouput stream for the specified format
*
* Output:
* return: none
* reference parameters: the updated ostream
* stream: none
*/
void displayItemInfo(ostream &out);
/**
* calcProfit
*
* This function computes the difference beteween an ItemInfo's manCost and sellPrice
* data memebers.
*
* Parameters: none
*
* Output:
* return: the difference between manCost and sellPrice
* reference parameters: none
* stream: none
*/
double calcProfit();
};
/**
* stuCstrToDbl
*
* This function converts a cstring representation of a double into a double value
*
* Parameters:
* num: the cstring holding a ascii representation of a double
*
* Output:
* return: a double value that reflects the ascii representation found in num
* reference parameters: none
* stream: none
*/
double stuCstrToDbl(const char *num);
/**
* stuDblToCstr
*
* This function converts a double value into a cstring representation of a double
*
* Parameters:
* cstr: the char array holding enough space to store a ascii representation of num
* num: the double value that is converted into an ascii representation
*
* Output:
* return: none
* reference parameters: str should hold the ascii representatiton of num
* stream: none
*/
void stuDblToCstr(char *cstr, double num);
/**
* stuCstrCpy
*
* This function copies the cstring src into dest
*
* Parameters:
* dest: the char array that hold a copy of the contents of src. dest must have
* enough space to store the copy
* src: the cstring to be copied
*
* Output:
* return: none
* reference parameters: dest should hold a copy of src
* stream: none
*/
void stuCstrCpy(char *dest, const char *src);
/**
* stuCstrLen
*
* This function caculates the length of a cstring
*
* Parameters:
* src: the cstring for which the length is calculated
*
* Output:
* return: an integer storing the length of the cstring
* reference parameters: none
* stream: none
*/
int stuCstrLen(const char *src);
#endif
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
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