complete what is missing in the blew code and display it in c++ class pizza { st
ID: 3868529 • Letter: C
Question
complete what is missing in the blew code and display it in c++
class pizza
{
string name;
string base;
string topping;
unsigned diameter;
double price;
public:
pizza(string n = "Margherita", string b = "Classic", string t = "None", unsigned d = 6)
{
name = n;
base = b;
topping = t;
diameter = d;
price = 0.0;
}
string get_name()
{
return name;
}
string get_base()
{
return base;
}
string get_topping()
{
return topping;
}
unsigned get_diameter()
{
return diameter;
}
double get_price()
{
return price;
}
double set_price(string, string, unsigned);
void display_info();
};
void pizza::set_price(string base, string topping, unsigned diameter)
{
if (base == "Thick")
{
if (topping == "None")
price = diameter * 1000;
else
price = diameter * 1000 + 600;
}
else if (base == "Classic")
{
if (topping == "None")
price = diameter * 500;
else
price = diameter * 500 + 300;
}
else
{
if (topping == "None")
price = diameter * 250;
else
price = diameter * 250 + 150;
}
}
void pizza::display_info()
{
cout << endl;
cout << "Pizza Name: " << get_name() << endl;
cout << "Base: " << get_base() << endl;
cout << "Extra Topping: " << get_topping() << endl;
cout << "Diameter: " << get_diameter() << """ << endl;
cout << "Price: " << get_price() / 1000 << " KWD" << endl;
cout << endl;
}
class pizza_e : public pizza
{
string service = "Dine In";
double total_charge = 0.0;
public:
using pizza::pizza;
double set_price(string service_type)
{
if (service_type == "Dine In")
return (total_charge = pizza::get_price() / 1000);
else
return (total_charge = pizza::get_price() / 1000 + 1.5);
}
void display_info(string service_info = "Dine In")
{
pizza::display_info();
cout << "Total Price = " << set_price(service_info) << endl;
}
};
int main()
{
pizza_e p1("Sicilian", "Thin", "Mushrooms", 24);
p1.display_info();
pizza_e p2("Margherita", "Thick", "Olives", 12);
p2.display_info();
pizza_e p3("Romana", "Classic", "Pepperoni", 6);
p3.display_info();
pizza_e p4;
p4.display_info("Home Delivery");
return 0;
}
Explanation / Answer
Answer:-
Here is a code:-
#include<iostream>
#include<string.h>
using namespace std;
class pizza
{
string name;
string base;
string topping;
unsigned diameter;
double price;
public:
pizza(string n = "Margherita", string b = "Classic", string t = "None", unsigned d = 6)
{
name = n;
base = b;
topping = t;
diameter = d;
price = set_price(b,t,d); // Here In set the price
}
string get_name()
{
return name;
}
string get_base()
{
return base;
}
string get_topping()
{
return topping;
}
unsigned get_diameter()
{
return diameter;
}
double get_price()
{
return price;
}
double set_price(string, string, unsigned);
void display_info();
};
double pizza::set_price(string base, string topping, unsigned diameter)// Here I use double instead of void
{
if (base == "Thick")
{
if (topping == "None")
price = diameter * 1000;
else
price = diameter * 1000 + 600;
}
else if (base == "Classic")
{
if (topping == "None")
price = diameter * 500;
else
price = diameter * 500 + 300;
}
else
{
if (topping == "None")
price = diameter * 250;
else
price = diameter * 250 + 150;
return price;
}
}
void pizza::display_info()
{
cout << endl;
cout << "Pizza Name: " << get_name() << endl;
cout << "Base: " << get_base() << endl;
cout << "Extra Topping: " << get_topping() << endl;
cout << "Diameter: " << get_diameter() << """ << endl;
cout << "Price: " << get_price() / 1000 << " KWD" << endl;
cout << endl;
}
class pizza_e : public pizza
{
string service = "Dine In";
double total_charge = 0.0;
public:
using pizza::pizza;
double set_price(string service_type)
{
if (service_type == "Dine In")
return (total_charge = pizza::get_price() / 1000);
else
return (total_charge = pizza::get_price() / 1000 + 1.5);
}
void display_info(string service_info = "Dine In")
{
pizza::display_info();
cout << "Total Price = " << set_price(service_info) << endl;
}
};
int main()
{
pizza_e p1("Sicilian", "Thin", "Mushrooms", 24);
p1.display_info();
pizza_e p2("Margherita", "Thick", "Olives", 12);
p2.display_info();
pizza_e p3("Romana", "Classic", "Pepperoni", 6);
p3.display_info();
pizza_e p4;
p4.display_info("Home Delivery");
return 0;
}
These are the few changes. The code is running in C++
Thank you Kindly rate My answer.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.