Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 calculateTotalValue(const 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 findMostExpensiveItem(const std::vector& items): This function returns the price of the most expensive item in the array.
std::vector filterOutOfStockItems(const std::vector& items): This function returns a vector containing out-of-stock (quantity is 0) items.
double calculateNonExpiredValue(const 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 filterItemsByPrice(const 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 1:
name: "Apple"
price: 5.00
quantity: 10
expirationDate: 12/2023
Item 2:
name: "Banana"
price: 12.00
quantity: 0
expirationDate: 11/2023
Item 3:
name: "Cherry"
price: 8.00
quantity: 15
expirationDate: 10/2023
For the given example:
The calculateTotalValue function should return 170.
The findMostExpensiveItem function should return 12.00.
The filterOutOfStockItems function should return {"Banana",12.0,0,{11,2023}}.
The calculateNonExpiredValue function, if provided with the current date as 09/2023, should return 170.
The filterItemsByPrice function, with a threshold of 10, should return items "Apple" and "Cherry".

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago