Code:
cPizza* add_pizza(int diameter, double cost)
{
cPizza *new_pizza;
new_pizza = new cPizza(diameter, cost);
return new_pizza;
}
Could better be written as....
Code:
cPizza* add_pizza(int diameter, double cost)
{
return new cPizza(diameter, cost);
}
area should be initialised in the constructor. Always make sure you initialise all members.
get out of the c habit of declaring at top of block. in c++ the preferred method is to give each item its minimal possible scope. i.e.
Code:
double cPizza::value()
{
float cost_per_inch;
area = (radius * radius) * PIE;
cost_per_inch = area / cost;
return cost_per_inch;
}
should be
Code:
double cPizza::value()
{
area = (radius * radius) * PIE; // this should be in constructor
double cost_per_inch = area / cost;
return cost_per_inch;
}
you could even get rid of the named variable too and just return area/cost. minimal scopes and riddance of unnecessary variables makes bug hunting easier.
You could halve that code, have same result and you will find its much more readable too.