Complete the following program by coding a class namedCoffeeRoasterand a global function named roastCoffee. Your roastCoffee function receives in its parameters iterators to the beginning and end of a...


Complete the following program by coding a class namedCoffeeRoasterand a global function named roastCoffee.


Your roastCoffee function receives in its parameters iterators to the beginning and end of a range of Coffees.



  • for each Coffee in that range, this function 'roasts' the Coffee based on the flavor attribute

    • A "Sharp" flavored Coffee should have its roast be set to "Dark"

    • A "Neutral" flavored Coffee should have its roast be set to "Medium"

    • A "Delicate" flavored Coffee should have its roast be set to "Light"




Your CoffeeRoaster class includes the following members:


an STL container that holds Coffee objects


a pointer to a function that receives a reference to an unmodifiable STL container of Coffee objects and returns nothing


a boolean flag that incidcates whether or not all the Coffees in the container have been roasted


an overloaded += operator that adds a Coffee object to the container, sets the boolean flag to false and returns a reference to the current object only if the Coffee being added has an origin from one of the entries in the listed regions array



  • if the Coffee is not from one of those regions then this operator does nothing and throws an exception

  • update main to handle the exception by printing a message as shown in the sample output below


a setDisplay function that receives the address of a callback function that displays requested data (byName or byOrigin), stores that address in the current object and returns nothing.


a processCoffee function with no explicit parameters that returns nothing that displays the requested data using the callback function only if the current object has a registered callback function. If any of the Coffee in the container is not roasted, before printing anything, this function roasts the Coffee using the roastCoffee function with two threads. Each thread processes a portion of the Coffee objects from the container.



  • If a callback function is not registered with the current object, this member function aborts execution normally with a return code of 1.


Lastly, upgrade the main function of the program to use a smart pointer.


#include

#include

#include


std::string regions[5]{
"Central America",
"South America",
"Africa",
"Middle East",
"South East Asia"
};


struct Coffee
{

std::string name;

std::string origin;

std::string flavor;

std::string roast;
};


void byOrigin(const std::vector& coffees)
{

std::cout


for (auto& c : coffees)

std::cout

}


void byName(const std::vector& coffees)
{

std::cout


for (auto& c : coffees)

std::cout

}


int main()
{

Coffee coffees[]{

{"Community", "Africa", "Sharp" },

{"Lunji Estate", "Canada", "Delicate" },

{"Hola", "Central America", "Neutral" },

{"Foundry", "Middle East", "Delicate" },

{"Red Brick", "South America", "Sharp" },

};



CoffeeRoaster* coffeeroaster = new CoffeeRoaster();

for (const auto& c : coffees) {

*coffeeroaster += c;

}

coffeeroaster->setDisplay(byOrigin);

coffeeroaster->processCoffee();

coffeeroaster->setDisplay(byName);

coffeeroaster->processCoffee();

delete coffeeroaster;
}



The output produced by this program using your solution should be:


Unknown Origin : Canada


Origin Roast
Africa : Dark
Central America : Medium
Middle East : Light
South America : Dark


Name Roast
Community : Dark
Hola : Medium
Foundry : Light
Red Brick : Dark

Aug 19, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here