Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For some reason, I keep getting an error with my constructor. I have to have a d

ID: 3626830 • Letter: F

Question

For some reason, I keep getting an error with my constructor. I have to have a default constructor with no parameters and one with int size.

Also, I need to output the size as a string in a string() function where (0=small, 1=medium, 2=large). Would I add that in the loop and what suggestion would you give so that I could be able to return the size as a string?

Thanks!

#include <iostream>
#include <string>
using namespace std;

class PizzaOrder
{
private:
int size;

public:

PizzaOrder();
PizzaOrder (int p);
~PizzaOrder();

void SetSize (int initialSize);
int GetSize() {return size;}

};



PizzaOrder::PizzaOrder (int p)
{
size = p;
}

void PizzaOrder::SetSize(int initialSize)
{
size=initialSize;
}


int main ()
{
PizzaOrder order;
string pizza_size;

cout << "Would you like a size [S]small , [M]medium, [L]large pizza or [Q]quit?" <<endl;
cin >> pizza_size;

do
{
if ((pizza_size == "S")||(pizza_size == "s"))
{
order.SetSize(0);
cout << order.GetSize();
}

else if ((pizza_size == "M")||(pizza_size == "m"))
{
order.SetSize(1);
cout << order.GetSize();
}
else if ((pizza_size == "L")||(pizza_size == "L"))
{
order.SetSize(2);
cout << order.GetSize();
}

else
{
cout << "Invalid choice. Choose again." << endl;
}

} while ((pizza_size != "Q") && (pizza_size != "q"));

system("pause");
return 0;
}

Explanation / Answer

You get an error because you have declared a default constructor in the header file, however you have not defined the function. The reason you need this default constructor is because of the line: PizzaOrder p; This line tries to construct a PizzaOrder with the default constructor, which you defined but never made. So if you just add: PizzaOrder::PizzaOrder() { size=1; } Note that i picked a medium pizza as the default, which really doesnt matter as you change it regardless. PLEASE RATE!