help please

can some one help with the addtoppings functions please. Its suppose to loop the what are the toppings useing the vector.

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
95
96
97
  #include<iostream>
#include<string>
#include<vector>
using namespace std;

class MyPizza
{
    private: 
    string name;
    string size;
    vector<string> toppings;
    
    
    public:
    void setSize(string);
    string getSize();
    void setName(string);
    string getName();
    string addTopping();
    
    MyPizza()
    {
        name="";
        size="";
        toppings.push_back("");
    }//default constructor
    MyPizza(string Cname, string PizzaSize,vector<string> P_toppings) //parametized constructor
    {
        name=Cname;
        size=PizzaSize;
        toppings=P_toppings;
    }
    
};
void MyPizza::setSize(string Psize)
{
    size=Psize;
}

string MyPizza::getSize()
{
    return size;
}


void MyPizza::setName(string Pname)
{
    name=Pname;
}


string MyPizza::getName()
{
    return name;
}

string MyPizza::addTopping()
{   
    string t;

    for(int i=0;i<t.size();i++)
   {
   cout<<"What are the topping would you like";
   cin>>t;
   toppings.push_back(t);
   cout<<t[i]<<endl;
   }
    
    return t;
   // addTopping – this function receives a string representing a single topping, and adds it to
//to the vector of toppings in the class
 }
 
int main()
{
    MyPizza ob;
    ob.addTopping();
}
/*Create a class called Pizza that represents a single pizza order. Required class attributes and
functions are as follows:
Class attributes:
 Customer name (you can make it a single name if you want, no spaces)
 Size of pizza (you decide whether to use string or char)
 A VECTOR of strings that represents the toppings
Class Functions:
 Default constructor (choose appropriate values)
 set/get for size (validate that size is only S, M, L – upper or case)
 set/get for customer name
 addTopping – this function receives a string representing a single topping, and adds it to
to the vector of toppings in the class
 clearTopping – this function resets the topping vector to empty (use .clear() function)
 getPrice – this function calculates are returns the price of the pizza
 display – this function displays the pizza order in the format shown below:
*/


http://www.cplusplus.com/forum/beginner/243678/
Please do not duplicate posts.
Topic archived. No new replies allowed.