72 lines
1.7 KiB
C++
72 lines
1.7 KiB
C++
//
|
|
// Created by Franc on 04.05.2026.
|
|
//
|
|
|
|
#include "Pizza.h"
|
|
|
|
Pizza::Pizza() : MenuItem("pizza", 249.99) {
|
|
this->diameter = 20;
|
|
this->hasExtraCheese = false;
|
|
this->maxIngredients = 3;
|
|
this->ingredients = new Ingredient *[3](nullptr);
|
|
}
|
|
|
|
Pizza::Pizza(string n, double b, int d, bool e, int m) : MenuItem(n, b) {
|
|
this->diameter = d;
|
|
this->hasExtraCheese = e;
|
|
this->maxIngredients = m;
|
|
this->ingredients = new Ingredient *[m](nullptr);
|
|
}
|
|
|
|
Pizza::~Pizza() {
|
|
for (int i = 0; i < currentIngredients; i++) {
|
|
delete ingredients[i];
|
|
}
|
|
delete[] ingredients;
|
|
println("Pizza destroyed");
|
|
}
|
|
|
|
double Pizza::getPrice() const {
|
|
double temp=0;
|
|
for (int i = 0; i < currentIngredients; i++) {
|
|
temp +=ingredients[i]->getCost();
|
|
}
|
|
return basePrice+temp;
|
|
}
|
|
|
|
string Pizza::printInfo() {
|
|
return MenuItem::printInfo() + ", with diameter of: " + to_string(diameter) + ", and extra cheese: " + (
|
|
hasExtraCheese ? "yes" : "no");
|
|
}
|
|
|
|
int Pizza::getDiameter() {
|
|
return diameter;
|
|
}
|
|
|
|
bool Pizza::addIngredient(Ingredient *i) {
|
|
if (currentIngredients > maxIngredients) {
|
|
return false;
|
|
}
|
|
|
|
ingredients[currentIngredients] = i;
|
|
currentIngredients++;
|
|
return true;
|
|
}
|
|
|
|
bool Pizza::removeIngredient(string name) {
|
|
if (currentIngredients == 0) {
|
|
return false;
|
|
}
|
|
for (int j = 0; j < currentIngredients; j++) {
|
|
if (ingredients[j]->getName() == name) {
|
|
delete ingredients[j];
|
|
for (int k = j; k < currentIngredients - 1; k++) {
|
|
ingredients[k] = ingredients[k + 1];
|
|
}
|
|
currentIngredients--;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|