classes or structure

I am new to c++ programming and I am having a bit of difficulty increasing the count each time an order is placed. I would like for the count to increase each time an order is placed. Need Help, can somebody help me?

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
#include <iostream>
#include <string>
using namespace std;
//#include "PIZZA.cpp" // You supply this file

//Class PizzaStore
class PizzaStore
{
	string name;
	string address;
	string topping;
	int counter;    //
	public:
		int PizzasWaiting()
			{ return counter = 0;}	
		string Order(string n, string a, string t)
		{
			name = n;
			address = a;
			topping = t;
		}
		
};



int main()
{
	//Class PizzaStore 
	PizzaStore PS; 
	
	cout << PS.PizzasWaiting() << " pizzas are waiting to be delivered\n";
	
	PS.Order("Rick","1234 Elm Street","Pepperoni");
	cout << PS.PizzasWaiting() << " pizzas are waiting to be delivered\n";
	
	PS.Order("Stewie","31 Spooner Street","Anchovies and Jalapenos");
	cout << PS.PizzasWaiting() << " pizzas are waiting to be delivered\n";

}


This is the output that I want to get ....

0  pizzas are waiting to be delivered 
1  pizzas are waiting to be delivered
2  pizzas are waiting to be delivered
Inside the order method, increment counter. And don't set counter to 0 when you are trying to see what its value is, or it will always be 0.

Also, you might want to have more than one order able to be placed at one time; currently you are only storing the most recent.
Implement a constructor PizzaStore() to initialize the counter to 0.
Add a class PizzaOrder that takes name, address and topping. Maybe you want it to generate an order number you can use for the delivery method later.
Replace name, address and topping in the PizzaStore class by an orders vector of PizzaOrder.
Make the Order method add new orders to the orders vector.
Add a delivery method that decreases the counter and ereases the order from the orders vector. The order number mentioned earlier comes in handy now.
return counter instead of return counter = 0
add counter++ to the Order method

Did I forget anything?
Nice,

This is what I have so far after following some of what you said. The code will not compile still, I am getting an error in the PizzaStore class. My issue is with checking to see if temp is = to NULL, Then taking in the first name and setting it to temp, then taking in the second, the third name and so on.

note: I still have functions that I have not worked on.....
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
98
99
100
#include <iostream>
#include <string>
using namespace std;

// #include "PIZZA.cpp" // You supply this file

class Pizza;
class PizzaStore;
//=============================================================================================
//================Pizza Class==================================================================
class Pizza
{
public:
    string name;
    string address;
    string topping;
    string temp;        //declare variables name,address,topping,temp
    string *next_pizza;
    Pizza(string n, string a, string t)         //Pizza function
        { name = n; address = a; topping = t;}
    string GetName()                            //GetName function
        { return name;}
    string GetAddress()                         //GetAddress function
        { return address;}
    string GetIngredients()                     //GetIngredients function
        { return topping;}
};
//=============================================================================================
//================PizzaStore Class=============================================================
class PizzaStore
{
private:
    struct inqPizza         //declare our structure named inqPizza
    {
        Pizza name;     
        inqPizza *next;
    }*first, *Last;
    
    int counter;
public:
    PizzaStore()            //PizzaStore ***** constructor ******
    {
        counter = 0;
        first = NULL;
        Last = NULL;
    }
    int PizzasWaiting()     //PizzasWating function
        { return counter;}
    
    //=============having trouble here================================
    void Order(string n, string a, string t)  //Order function
    {
        inqPizza *temp;
        temp->name = *new Pizza(n,a,t);
        temp->next=NULL;
        if(first=NULL)
        {
            first=temp;
            Last=temp;
        }
        else
        {
            Last=temp;
        }Last = temp;
    }
    //===============================================================
    
    Pizza GetFirstPizza();      //GetFirstPizza function
    void Deliver();             //Deliver function
};
//=============================================================================================
//================= Main Program ==============================================================
int main()
{
    PizzaStore PS;
    //Pizza P;

    cout << PS.PizzasWaiting() << " pizzas are waiting to be delivered\n";
    //--------------------------------------------------------------------
    PS.Order("Rick","1234 Elm Street","Pepperoni");
    cout << PS.PizzasWaiting() << " pizzas are waiting to be delivered\n";
    
    PS.Order("Stewie","31 Spooner Street","Anchovies and Jalapenos");
    cout << PS.PizzasWaiting() << " pizzas are waiting to be delivered\n";
    
    PS.Order("Brian","31 Spooner Street","Scoobie Snacks");
    cout << PS.PizzasWaiting() << " pizzas are waiting to be delivered\n";
    //--------------------------------------------------------------------
    while (PS.PizzasWaiting() > 0)
    {
        P = PS.GetFirstPizza();
        cout << "\nDelivering a pizza to " << P.GetName()
            << " at " << P.GetAddress()
            << " with " << P.GetIngrediants() << endl;
        PS.Deliver();
        cout << PS.PizzasWaiting() << " pizzas are waiting to be delivered\n";
    }
    cout << endl << endl << endl;
    system("pause"); return 0;
}






/* -------------------------------------------------------------------------
 The code is suppose to output this:
 
 0 pizzas are wating to be delivered
 1 pizzas are wating to be delivered
 2 pizzas are wating to be delivered
 3 pizzas are wating to be delivered
 
 Delivering a pizza to "name" at "address" with "Ingredients".
 2 pizzas are waiting to be delivered.
 Delivering a pizza to "name" at "address" with "Ingredients".
 1 pizzas are waiting to be delivered.
 Delivering a pizza to "name" at "address" with "Ingredients".
 0 pizzas are waiting to be delivered.
 -----------------------------------------------------------------------------*/
Last edited on
Why not replace the linked list by a convenient C++ class (e.g. vector or list) or a C type (array of *Pizza)? As there's no need for superior performance in your application, you can choose the one that seems most comfortable to you. It will make your code more readable and prevent you from frustration.

If you're interested in linked lists, learn it first and then use it. There's plenty of articles on c and c++ linked lists on the internet, and most of them come with working examples you can use for your experiments.

Get an IDE. Here's a Forum contribution on that: http://www.cplusplus.com/forum/articles/7263/
The IDE would have warned you while typing if(first=NULL), because the line comprehends an assignment (=) instead of a comparison (==).
And you can use the debugger of the IDE to get a better understanding of other people's algorithms, e.g. a linked list example.
First of all, drop the pointers. You don't need them so... why use them? Reserve pointers for objects, not simple types.

Maybe you could try a more OOP approach.

For instance,

What does a name, address, topping, temp, next_pizza have to do with an actual pizza?

Why not make the pizza a class that contains a size, and various toppings?

Size can be an enum.

Toppings can also be an enum or a struct/class.

At least this way, it makes logical sense.

As for the rest, that will be the order class. The order will contain the address and a container or pizzas which will in turn contain a size and any number of toppings.

Good Luck!




Topic archived. No new replies allowed.