Question
do part 2 in c++ #include #include #include using namespace std; class Ingredient { private: string name; float unitPrice; int amount; public: Ingredient() { }
do part 2 in c++
#include
#include
#include
using namespace std;
class Ingredient {
private:
string name;
float unitPrice;
int amount;
public:
Ingredient() {
}
Ingredient(string name, float unitPrice, int amount) {
this->name = name;
this->unitPrice = unitPrice;
this->amount = amount;
}
string getName() {
return this->name;
}
float getUnitPrice() {
return this->unitPrice;
}
int getAmount() {
return this->amount;
}
void setUnitPrice(int unitPrice) {
this->unitPrice = unitPrice;
}
void print() {
cout name
unitPrice
amount
}
};
float calculateCost(Ingredient*, int);
Ingredient* applyDiscount(Ingredient*, float, int);
bool canCook(vector, vector);
int main() {
return 0;
}
// Calculate the cost of the shopping list corresponding to each ingredient's
// -- unitPrice and amount
float calculateCost(Ingredient *shoppingList, int size) {
// *** FILL THIS FUNCTION FOR PART 1 ***
float cost = 0.0;
// iterate regards to size
for(int i = 0; i
cost += (shoppingList[i].getUnitPrice() * shoppingList[i].getAmount());
}
return cost;
}
// Apply the discount for the ingredient's in the shopping list
// -- The discount rate is in 0
Ingredient* applyDiscount(Ingredient *shoppingList, float discount, int size) {
// *** FILL THIS FUNCTION FOR PART 2 **
}
// Check whether the cook recipe is given can be cooked by the ingredients
// -- in the fridge
bool canCook(vector recipe, vector fridge) {
// *** FILL THIS FUNCTION FOR PART 3 ***
}
Part II (40 point) a Write a function that applies discount on the shopping list given by pointers. Assume that 0Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started