Question

In: Computer Science

In C++ Antique Class Each Antique object being sold by a Merchant and will have the...

In C++

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
<Antique.name>: $<price.2digits>

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.

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please rate the answer. Let me know for any help with any other questions.

Thank You !
===========================================================================

#include<iostream>
#include<string>
using namespace std;

class Antique{
   private:
       string name;
       float price;
   public:
       Antique(string name="", float price=0.0);
       string getName() const;
       float getPrice() const;
       void setName(string name);
       void setPrice(float price);
       string toString() ;
};

Antique::Antique(string name, float price): name(name),price(price){}
string Antique::getName() const{return name;}
float Antique::getPrice() const{return price;}
void Antique::setName(string name){this->name=name;}
void Antique::setPrice(float price){this->price=price;}
string Antique::toString() {
   return name +": Price $" +to_string(price);
}

class Merchant{
   private:
       Antique antique[10];
       int quantity[10];
       float revenue;
       int haggled;
   public:
       Merchant(Antique antiques[], int quantities[]);
       void haggle();
       float getRevenue() const;
};
Merchant::Merchant(Antique antiques[], int quantities[]){
  
   haggled =0;
   for(int i=0; i<10;i++){
       antique[i]=antiques[i];
       quantity[i]=quantities[i];
       revenue += antique[i].getPrice()*quantity[i];
   }
}
void Merchant::haggle(){
   if(haggled==1){
       cout<<"Sorry, you have already haggled.\n";
       return;
   }
  
   double price;
   for(int i=0; i<10;i++){
           price = antique[i].getPrice()*0.9;
           antique[i].setPrice(price);
   }
   haggled+=1;
   cout<<"You have successfully haggled and everything is 10% off.\n";
  
}

int main(){
  
   Antique antiques[]={Antique("Ruby",12.99),Antique("Ruby",16.99),Antique("Pearl",18.99),Antique("Diamond",10.99),Antique("Pearl",42.99),
   Antique("Diamond",555.99),Antique("Diamond",55.99),Antique("Pearl",412.99),Antique("Pearl",12.99),Antique("Diamond",45.99)};
   int quantities[] ={1,2,3,4,5,6,7,8,9,0};
  
   Merchant merchant(antiques,quantities);
   merchant.haggle();
   merchant.haggle();
}

===================================================================


Related Solutions

A Bookstore Application C++ Design the class Book. Each object of the class Book can hold...
A Bookstore Application C++ Design the class Book. Each object of the class Book can hold the following information about a book: title, authors, publisher, ISBN Include the member functions to perform the various operations on the objects of Book. For example, the typical operations that can be performed on the title are to show the title, set the title. Add similar operations for the publisher, ISBN , and authors. Add the appropriate constructors and a destructor (if one is...
A series of object are being rotated. The same net torque is being applied to each...
A series of object are being rotated. The same net torque is being applied to each object. Rank the object in order of the resulting angular acceleration (1=lowest). ( ) A solid disk spinning about its center. Total mass is 0.5M and the radius is 2R. ( )An object consisting of two objects connected by a massless rod. Each object has a mass of 2M and is a distance R from the axis of rotation. ( )A solid disk spinning...
Make a class whose objects each represent a battery. The only attribute an object will have...
Make a class whose objects each represent a battery. The only attribute an object will have is the battery type (one letter). Also, the class has to include the following services for its objects: -determine if two batteries are equal -change battery type -get battery type display battery information the program must include: 1.All / Part 2.Overloading of operators 3.Builder 4.Copy constructor 5.Destroyer 6.Dynamic memory C++
DO THIS IN C#,Design and implement class Rectangle to represent a rectangle object. The class defines...
DO THIS IN C#,Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to create a rectangle with user-specified height and width. 4. Method getArea() that returns...
IN C++!!! Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class...
IN C++!!! Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 0 in the default constructor. A non-argument constructor method to create a default rectangle. Another constructor method to create a rectangle with user-specified height and width. Method getArea() that returns the area. Method...
Develop a C++ class called PrimeNumberGenerator. An object of this class will generate successive prime numbers...
Develop a C++ class called PrimeNumberGenerator. An object of this class will generate successive prime numbers on request. Think of the object as being similar to the digital tasbeeh counter. It has a reset button which makes the counter return to 0. There is also a button to get the next prime number. On the tasbeeh, pressing this button increments the current value of the counter. In your object, pressing this button would generate the next prime number for display....
IN C++!! Exercise #2: Design and implement class Radio to represent a radio object. The class...
IN C++!! Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. A private variable of type int named station to represent a station number. Set to A private variable of type int named volume to represent the volume setting. Set to 1. A private variable of type boolean named on to represent the radio on or...
Class object in C++ programming language description about lesson base class and derived class example.
Class object in C++ programming language description about lesson base class and derived class example.
Previous info: Cost Is No Object is a car rental service that specializes in lending antique...
Previous info: Cost Is No Object is a car rental service that specializes in lending antique and luxury cars to clients on a short-term basis. A typical customer might rent a vintage convertible to transport out-of-town clients to a business meeting, or rent a luxury car to transport a wedding party. The service currently has three employees and ten vehicles that it rents. Case Projects CH.4 Case: Cost Is No Object In earlier chapters, you developed classes needed for Cost...
Game theory: Analyze the second price" auction. There are two bidders and one object being sold...
Game theory: Analyze the second price" auction. There are two bidders and one object being sold by auction. Each bidder knows what the object is worth to him, but not what it is worth to the other bidder. In other words, the object is worth v1 to bidder 1 and v2 to bidder 2. Bidder 1 knows v1 but not v2, while bidder 2 knows v2 but not v1. In the sealed bid second price auction, each bidder privately submits...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT