Question: use C + + Struct Definitions: Define a struct, Date, which contains two integers representing the month and the year. Define a struct, Item, which
use C Struct Definitions:
Define a struct, Date, which contains two integers representing the month and the year.
Define a struct, Item, which contains:
a string, name, representing the name of the item.
a double, price, representing the price of the item.
an int, quantity, representing the quantity of the item.
a Date, expirationDate, representing the expiration date of the item.
Functions:
double calculateTotalValueconst std::vector& items: This function takes a vector of items and returns the total value of the items, calculated by multiplying the price of each item by its quantity.
double findMostExpensiveItemconst std::vector& items: This function returns the price of the most expensive item in the array.
std::vector filterOutOfStockItemsconst std::vector& items: This function returns a vector containing outofstock quantity is items.
double calculateNonExpiredValueconst std::vector& items, const Date& currentDate: This function calculates and returns the total value of the items in the array that are not expired expiration date is after the provided date
std::vector filterItemsByPriceconst std::vector& items, double priceThreshold: This function returns a vector containing all items whose price is less than the priceThreshold parameter.
Example:
Suppose we have an array of items where:
Item :
name: "Apple"
price:
quantity:
expirationDate:
Item :
name: "Banana"
price:
quantity:
expirationDate:
Item :
name: "Cherry"
price:
quantity:
expirationDate:
For the given example:
The calculateTotalValue function should return
The findMostExpensiveItem function should return
The filterOutOfStockItems function should return Banana
The calculateNonExpiredValue function, if provided with the current date as should return
The filterItemsByPrice function, with a threshold of should return items "Apple" and "Cherry".
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
