Hi everybody,
I'm working on an ice cream shop application to simulate purchasing ice cream, and then customizing it (type-cup/cone, size-small/large, & toppings). I've read in items and descriptions of those items from an inventory file, then storing it into a local array, and passing it into a class setter function in my header file. My header file consists of three classes, one being a class called Extras which stores the type (cone or cup), and toppings. I've created an array of size 5 for toppings, locally first--I'm using a do while loop to ask the user how many toppings they want (1-5), and then a for loop for the number of toppings. The program runs, no errors at all, but the problem I'm running into is either when I call the setToppings function, or call the getToppings function, I can't figure it out though. I've tested the program and the information is being stored into the local array, so I believe the problem is in the header file, but I'm not sure. It's setup how I've setup the items and descriptions set and get functions in the header file. I've tried to run through every possible scenario and can't figure it out, am I missing something? Any help would be greatly appreciated.
Full code can be found here:
https://pastebin.com/dwDyLaKL (main.cpp) lines 129-189, toppings lines 169-182
https://pastebin.com/32W3PrDC (data.h) lines 36-46, set toppings 97-101, get toppings 107-109.
I'm not sure if the code format worked or not so I included pastebin links.
Any help would be greatly appreciated. Thank you in advance!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
MAIN.CPP
|
void customizeItems(IceCreamData data, Volume details, Extras customize) {
double treatCost;
int selectionType;
int selectionSize;
int toppingQty;
string type;
string typeSize;
string toppings[5];
cout<<"Would you like a cone or a cup?\n";
cout<<"1) Cone\n";
cout<<"2) Cup\n";
cin>>selectionType;
if(selectionType==1){
type = "Cone";
customize.setType(type);
} else if(selectionType==2){
type = "Cup";
customize.setType(type);
}
string treatType = customize.getType();
cout<<"Which size would you like?\n";
cout<<"1) Small (3 scoops)\n";
cout<<"2) Large (5 scoops)\n";
cin>>selectionSize;
if(selectionSize==1){
typeSize = "Small (3 scoops)";
details.setSize(typeSize);
} else if(selectionSize==2) {
typeSize = "Large (5 scoops)";
details.setSize(typeSize);
}
string sizeOfTreat = details.getSize();
do{
cout<<"How many toppings would you like? (up to 5)? ";
cin>>toppingQty;
cin.ignore();
} while(toppingQty<1||toppingQty>5);
for(int i=0;i<toppingQty;i++){
cout<<"Topping #"<<i+1<<": ";
getline(cin, toppings[i]);
customize.setToppings(toppings, i); //set toppings
}
string* allToppings = customize.getToppings(); //get toppings, returns address
cout<<allToppings;
for(int i=0;i<5;i++){
cout<<toppings[i];
}
menu(data, details, customize);
}
------------
DATA.H
------------
class Extras {
private:
string type;
string itemToppings[5];
public:
void setType(string treatType);
void setToppings(string toppings[], int i);
string getType();
string* getToppings();
};
void Extras::setType(string treatType){
type = treatType;
}
void Extras::setToppings(string toppings[], int i){ //set the toppings
for (int i = 0; i < 5; i++) {
itemToppings[i] = toppings[i];
}
}
string Extras::getType() {
return type;
}
string* Extras::getToppings() { //get the toppings
return itemToppings;
} |