Antique Class
Each Antique object being sold by a Merchant and will have the following attributes:
And will have the following member functions:
<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:
And will have the following member functions:
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.
The code is below:-
#include <iostream>
#include <string>
using namespace std;
class Antique { // The class
public: // Access specifier
string name; // Attribute (string variable)
float price; // Attribute (float variable)
Antique(){
name="";
price = 0;
}
string getName(){
return name;
}
void setName(string userName){
name = userName;
}
float getPrice(){
return price;
}
void setPrice(float itemPrice){
price = itemPrice;
}
string toString(){
float value = (int)(price * 100 + .5);
float temp1 = (float)value / 100;
string temp = "Name: "+name+" Price: "+ to_string(temp1);
return temp;
}
};
class Merchent{
Antique *arr;
int *quantities;
float revenue;
public:
Merchent(Antique a[10],int q[10]){
arr = a;
quantities = q;
revenue=0;
}
int haggleUsed = 0;
void haggle() {
if (haggleUsed == 1) { // checking if it's value if 1 then not changing anything
cout<<"Sorry, you have already haggled."<<endl;
} else {
for (int i = 0; i < 10; i++) { // else decreasing the price by 10 percent
float temp = arr[i].getPrice();
temp = temp - (float) (temp * 0.10);
arr[i].setPrice(temp);
cout<<"haggle "<<arr[i].getPrice()<<endl;
haggleUsed = 1;
}
}
}
};
int main() {
Antique an[10];
an[0].setName("Rishab");
an[0].setPrice(45.56);
an[1].setName("qwert");
an[1].setPrice(5.56);
an[2].setName("zxcv");
an[2].setPrice(74.56);
an[3].setName("wscde");
an[3].setPrice(65.56);
an[4].setName("polkij");
an[4].setPrice(25.56);
an[5].setName("yhnmju");
an[5].setPrice(98.56);
an[6].setName("efbrgn");
an[6].setPrice(64.56);
an[7].setName("fjbgh");
an[7].setPrice(10.56);
an[8].setName("yhjur");
an[8].setPrice(35.56);
an[9].setName("asdbteh");
an[9].setPrice(30.56);
int quantity[]={1,2,3,4,5,6,7,8,9,10};
Merchent mr(an,quantity);
mr.haggle();
for(int i=0;i<10;i++){
cout<<an[i].getPrice()<<endl;
}
mr.haggle();
}
FOR ANY OTHER QUERY PLEASE COMMENT
Antique Class Each Antique object being sold by a Merchant and will have the following attributes:...
IN c++ i post this question 5 times. hope this time somebody answer.. 16.5 Homework 5 OVERVIEW This homework builds on Hw4(given in bottom) We will modify the classes to do a few new things We will add copy constructors to the Antique and Merchant classes. We will overload the == operator for Antique and Merchant classes. We will overload the + operator for the antique class. We will add a new class the "MerchantGuild." Please use the provided templates...
I am writing a program that has a class called merchant however when I try to initialize a merchant object which takes in as parameters two arrays something is going wrong as I cannot call the functions within the merchant.cpp. Not sure where the problem is? Merchant merch(Antique antiques[], int quantities[]); //cout << "Enter in budget: $"; //cin >> budget; cin >> selection; switch (selection) { case '1': merch.haggle(); case '2': merch.printMenu(); case '3': merch.selectAntique(); case '4': default: break; #ifndet...
Book: - title: String - price: double +Book() +Book(String, double) +getTitle(): String +setTitle(String): void +getPrice(): double +setPrice(double): void +toString(): String The class has two attributes, title and price, and get/set methods for the two attributes. The first constructor doesn’t have a parameter. It assigns “” to title and 0.0 to price; The second constructor uses passed-in parameters to initialize the two attributes. The toString() method returns values for the two attributes. Notation: - means private, and + means public. 1....
Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...
Additional info is this will use a total of four classes Book, BookApp, TextBook, and TextBookApp. Also uses Super in the TextBook Class section. Problem 1 (10 points) Вook The left side diagram is a UML diagram for Book class. - title: String The class has two attributes, title and price, and get/set methods for the two attributes. - price: double Вook) Book(String, double) getTitle(): String setTitle(String): void + getPrice() double setPrice(double): void toString() String + The first constructor doesn't...
When answering this question, can you please specify what you name your files? Thank you! Write a Java application, and an additional class to represent some real-world entity. Keep in mind that a class is a model in code of something real or imagined, which has attributes (member variables) and behaviors (member methods). The class will: a. Create a total of 5 member variables for the class, selecting the appropriate data types for each field. For example, a class to...
C++ Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...
Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1. A private variable of type double named radius to represent the radius. Set to 1. 2. Constructor Methods: • Python : An overloaded constructor method to create a default circle. • C# & Java: Default Constructor with no arguments. • C# & Java: Constructor method that creates a circle with user-specified radius. 3. Method getRadius() that returns the radius. 4. ...
Write code in Java programming language. The ShoppingCart class will be composed with an array of Item objects. You do not need to implement the Item class for this question, only use it. Item has a getPrice() method that returns a float and a one-argument constructor that takes a float that specifies the price. The ShoppingCart class should have: Constructors: A no-argument and a single argument that takes an array of Items. Fields: • Items: an array of Item objects...