Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

16.4 Homework 4 Overview: You have been greeted by a traveling sales merchant who is selling some wares. You will have access to view the

16.4 Homework 4

Overview: You have been greeted by a traveling sales merchant who is selling some wares. You will have access to view the items he is selling and will be able to purchase his wares according to his prices.

Objective: You will be creating a program that focuses on the use of classes and objects. For this assignment, you will be creating a Merchant class and an Antique class.

Main function

In the main function, perform the following tasks:

1) Create two arrays of size 10: one of antique objects and one of integers to represent the quantity of antique

2) Read from standard input the name of the file that stores the initial status of the Merchant's stock

3) Read the content of the file into the array of Antique objects and quantities. The file format is as follows:

, ,  , ,  ... , ,  

You can assume the file will always contain 10 antiques in the above format.

4) Use the two arrays as arguments to create a Merchant object.

5) - budget (float): variable used to store the amount of money the customer can spend. Take in user input for customer's budget like the following :

Enter in budget: $ 

6) Present the user with the following menu:

Make a selection: 1 - Haggle 2 - View menu 3 - Select an antique 4 - Leave 

If the user enters either 1-4, it will call the corresponding member functions of Merchant class (see below). If the user enters anything but 1-4, then it should output to the screen and return to the menu:

Invalid option. 

Antique Class

Each Antique object being sold by a Merchant and will have the following attributes:

  • name (string)
  • price (float)

And will have the following member functions:

  • mutators (setName, setPrice)
  • accessors (getName, getPrice)
  • default constructor that sets name to "" (blank string) and price to 0 when a new Antique object is created
  • a function toString that returns a string with the antique information in the following format
: $ 

Merchant Class

A Merchant class will be able to hold 10 different Antique objects and interact with the user to sell to them. It should include the following attributes:

  • antiques (array): An Antique array of 10 objects
  • quantities (array): An Integer array representing the quantity of each Antique object in stock. This can range from 0 to 10.
  • revenue (float): variable used to store the total amount of money earned by the Merchant after each sale

And will have the following member functions:

  • Merchant (constructor): the constructor takes as arguments an array of Antiques and an array of quantities to use them to initialize antiques and quantities. revenue should be set to 0.
  • haggle: function that decreases each and every Antique object's price by 10%. It will print the following:
You have successfully haggled and everything is 10% off. 

Customer cannot haggle more than once. If he tries to haggle more than once, it will print the following:

Sorry, you have already haggled. 
  • printMenu: function that prints the items available for sale in the following format:
1) : $ 2) : $ ... 10) : $ 
  • selectAntique: this function handles item selection and sale. It begins by printing the message (and ending with a newline):
Enter antique number: 

The antique number is read from standard input and stored. If the antique is not available (quantity = 0), print the following:

Sorry! Antique is out of stock. 

If the user has an insufficient budget, print the following:

Insufficient funds. 

Otherwise, if the sale was successful, decrease the user's budget to reflect the sale, add to revenue, and reduce the quantity of the item by one. Print the following to standard output:

Enjoy your ! 

And append to a text file called "log2.txt" that acts as an itemized receipt like following:

Sold  for $ 
  • leave: this function terminates the program, and appends the budget and revenue to a text file called "log2.txt" at the end:
Total revenue: $ Remaining budget: $ 

IMPORTANT

  • Classes and methods names must match exactly for unit testing to succeed.
  • Submissions with hard coded answers will receive a grade of 0.

C++ PLEASE

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

Entity Alignment Concepts Recent Advances And Novel Approaches

Authors: Xiang Zhao ,Weixin Zeng ,Jiuyang Tang

1st Edition

9819942527, 978-9819942527

More Books

Students also viewed these Databases questions

Question

3. What are two reasons for developing LANs?

Answered: 1 week ago

Question

a. Describe the encounter. What made it intercultural?

Answered: 1 week ago