Hello experts, im having some trouble with a c++ assignment. I have already writ
ID: 3572439 • Letter: H
Question
Hello experts, im having some trouble with a c++ assignment. I have already written the class cartItem in a previous assignment, with the UML shown in the images below. My issues begin with the LoadArray function, and I reckon if I can get that down I could finish the other functions myself. Ill cut to the chase- how am I supposed to load a file with 3 different data types (string, int, double) into a single array? Thank you.
Here is the assignment, and the file I am reading from is the text file on the left which reads "eggs 3.06...."
I hope this is enough info
D Programming Assignmel C Chegg stud Reading Grades: View erence Wiki X Guided ss item load ama C D igri Programming Assignment 10 (2) pdf and call them from main to make sure they work. +setPrice(price double): void LoadArray this function will take in an array of CartItems. It setQuantity(qty:int) :void will open a file called shoppingList.txt" and makes set Item( item string. price double, qty int) void sure it opened correctly. If it doesn't open correctly it will exit the program). The function will hen read in the item, price, and quantity for eac display CortItem0: void item in the cartand put it into the array. If the array runs out of room, do not put the item in. There are spaces between each field in the file, so you do not need to parse it. The function will return the count of how many items are in the array addToCart this function takes in the array of CartItems and the number of items in the array. It then asks the user to type in the item, price, and the quantity of the new item. It will put the new item into the array at the last position. (Make sure there is room in the array before putting the item in, if no room, do not put it in)The function updates the rumber of items. removeltem this function takes in the array of CartItems and the number of items in the array. It asks the user to enter the name of the item that is being removed. It then searches through the array. When the item is found it removes the item (actually, it shifts the other items down f the item is not in the array, it prints a message stating that the item is not in the cart. The function updates the number of items. printshoppingcart This prints the information how it is shown on the output cart Total this function takes the array of CartItems and the number of items in the array. It then computes the total cost of the cart and returns it. This is called when the user chooses to check out Test each function and make sure each one works before putting the main together. ou might want to make a sample main and test the functions as you implement them.) When the functions are complete, the main function will display a menu to the user asking what they dit Fomm View Help ggs 3.06 2 Apples 3./9 6 k 3.29 Mount Dew 1 59 2 M&Ms.; 9 5 1 9 3 d 2 Brea 9 2 Cookies 3.29 2 Ice Cre an 3.06 1. Orang es .896 tos A 59 3 &15 PM 2W2016Explanation / Answer
We can define a structure to represent one item like below:
struct item
{
string name;
double cost;
int quantity;
};
When loading the data from a file, create a item, and initialize item.name, item.cost, item.quantity and put into an array of item type like below:
ifstream myfile;
item arr[20];
item it;
myfile>>it.name;
myfile>>it.cost;
myfile>>it.quantity;
arr[i] = it;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.