Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

SEP200 XXXXXXXXXXSummer 2022 Term Object-Oriented Programming Final Test-Question-Part2 Page 1 of 4 Instructions: • The Final Test-Part2 should be completed individually. • Part2 is worth 50% of the...

1 answer below »

SEP200 XXXXXXXXXXSummer 2022 Term
Object-Oriented Programming
Final Test-Question-Part2

Page 1 of 4

Instructions:
• The Final Test-Part2 should be completed individually.
• Part2 is worth 50% of the final test grade and will be evaluated through your
submission.
• Duration: You have 75 minutes to complete this part.
• Every file that you submit must contain (as a comment) at the top your
name, your Seneca email, Seneca Student ID and the date when you
completed the work.
• Add comments throughout the code where necessary.
• The submitted files must be appropriately created according to C++ standards and best
practices.
• Submit the required file(s) through Blackboard.
• If you have to submit more than one file, you must merge the
equired files into one zip file and upload it through Blackboard.

Question 1. Complete the following program by coding a class called Wallet and a global
function called AddTax.
a. You need to download the startup code file: main.cpp

Note the startup code is not complete and contains compilation
e
ors. Your task is to complete the program by coding a class
called Wallet and a global function called AddTax.


AddTax Function Requirements
• Your global function named AddTax receives as input parameters iterators to the
eginning and end of a range of lottery Tickets.
• This function adds HST to the price data member for each Ticket in the received range
and stores the result in the price_w_tax data member.

SEP200 XXXXXXXXXXSummer 2022 Term
Object-Oriented Programming
Final Test-Question-Part2

Page 2 of 4

Wallet Class Requirements
Your Wallet class includes the following members:
• An STL container that holds lottery Ticket objects
• A boolean flag that holds true only if all Ticket objects in the container have their HST
added
• An overloaded += operator that adds a Ticket object to the container, sets the boolean
flag to false and returns a reference to the cu
ent object only if the ratio of the prize to
the price (prize/price) for that Ticket object is greater than or equal to the good-odds
atio ((prize/price) >= GOOD_ODDS).
o If the ratio is less than the GOOD_ODDS ratio , then this operator changes
nothing and throws an exception of type string with the message as shown in
the sample output below.
 Remember to update main to handle the exception.
• A member function named display that:
o receives the address of one of the global functions that display the requested
information (byName or byOdds) and calls it for each Ticket object. If the
eceived address is invalid, this function terminates the program with code 11.
o adds HST to the price for each Ticket object (if necessary; see next bullet) and
displays the requested data.
o If any data (i.e., Ticket) in the container is not taxed, this function adds tax using
the AddTax function and two threads before printing anything. For this
purpose, the function divides the container elements into two consecutive
halves where each thread processes one half.
Other Mandatory Requirements
• Upgrade the main function of the program to use a smart pointer.
SEP200 XXXXXXXXXXSummer 2022 Term
Object-Oriented Programming
Final Test-Question-Part2

Page 3 of 4

Startup Code Exists in the file main.cpp
You need to download the startup code file: main.cpp
Note the startup code is not complete and contains compilation
e
ors. Your task is to complete the program by coding a class
called Wallet and a global function called AddTax.

#include
#include
#include
constexpr double HST{ 0.13 };
constexpr double GOOD_ODDS{ 20.0 };
odds cutoff

struct Ticket
{
std::string name;
unsigned prize;
double price;
double price_w_tax;
};
void byName(const std::vecto
Ticket>& lotteries)
{
std::cout
std::fixed
std::setprecision(2);
std::cout
"\nLottery Price\n";
for (auto& l : lotteries)
std::cout
std::setw(10)
std::left
l.name

": "
std::setw(5)
std::right
l.price_w_tax
'\n';
}
void byOdds(const std::vecto
Ticket>& lotteries)
{
std::cout
std::fixed
std::setprecision(2);
std::cout
"\nPrize/Price Price\n";
for (auto& l : lotteries)
std::cout
std::setw(11)
std::left
l.prize / l.price_w_tax

": "
std::setw(5)
std::right
l.price_w_tax
'\n';
}
int main() {
Ticket winner[]{
{"Lotto Max ", 350, 5.00},
{"Lotto 6/49", 140, 3.00},
{"Daily Keno", 25, 0.99},
{"Encore ", 10, 1.00},
{"Ontario 49", 20, 1.00},
};
Wallet* wallet = new Wallet();
for (const auto& i : winner)
*wallet += i;

wallet->display(byName);
wallet->display(byOdds);
delete wallet;
}
SEP200 XXXXXXXXXXSummer 2022 Term
Object-Oriented Programming
Final Test-Question-Part2

Page 4 of 4

Sample Output
The output produced by this program using your solution should be:
Poor Odds on Encore

Prize/Price Price
61.95 : 5.65
41.30 : 3.39
22.35 : 1.12
17.70 : 1.13

Lottery Price
Lotto Max : 5.65
Lotto 6/49: 3.39
Daily Keno: 1.12
Ontario 49: 1.13

How to Submit your Solution

• You must submit one file: main.cpp
• If you have to submit more than one file, you must merge the
equired files into one zip file and upload it through Blackboard.


    Instructions:
    AddTax Function Requirements
    Wallet Class Requirements
    Other Mandatory Requirements
    Startup Code Exists in the file main.cpp
    Sample Output
    How to Submit your Solution
Answered Same Day Aug 17, 2022

Solution

Jahir Abbas answered on Aug 17 2022
61 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here