Question

In: Computer Science

Code in C++ Must show: unit testing ------------------------------------ UsedFurnitureItem Create a class named UsedFurnitureItem to represent...

Code in C++

Must show: unit testing

------------------------------------

UsedFurnitureItem

  1. Create a class named UsedFurnitureItem to represent a used furniture item that the store sells.
  2. Private data members of a UsedFurnitureItem are:
    1. age (double) // age in years – default value for
    2. brandNewPrice (double) // the original price of the item when it was brand new
    3. description (string) // a string description of the item
    4. condition (char) // condition of the item could be A, B, or C.
    5. size (double) // the size of the item in cubic inches.
    6. weight (double) // the weight of the item in pounds.
  3. Private member functions of a UsedFurnitureItem object are
    1. double CalculateCurrentPrice( ): Current price depends on age, brandNewPrice, and condition of the used furniture Item. If the item is in A-condition, the current price will go down by extra 10% of the brandNewPrice for each year of its age until 7 years (e.g., After the first year, and item with a $100 brandNewPrice will cost $90, after 2 years, $ 80, and so on). If the age is greater than 7 years, the price is fixed at 30% of the brandNewPrice. The current price of B-condition items goes down by extra 15 % of the brandNewPrice for each year until the 5th year. After that, the current price is fixed at 20% of the brandNewPrice. Items with C-condition are priced at 10% of the brandNewPrice regardless of age.
    1. double CalculateShippingCost( ): Shipping cost of a UsedFurnitureItem depends on weight, size, and distance. While weight and size are member variables, shipping distance is provided as an additional argument to this function. Shipping rate is 1 cent per mile for items that are smaller than 1000 cubic inches and smaller than 20 pounds. Items with larger size or weight cost 2 cents per mile.
  4. Public member functions of a UsedFurnitureItem
    1. Constructors – default and overloaded [default values: age = 1.0, brandNewPrice = 10.00, description = “Not available”, condition = ‘A’, size = 1.0, weight = 1.0]
    2. Accessors (getters)
    1. Mutators (setters) – You should ensure that invalid (zero or negative) values do not get assigned to age, brandNewPrice, size or weight data members. An invalid character (other than ‘A’, ‘B’ or ‘C’) should not be allowed to be assigned

-------------------------------------

Test Program:

The test program will test each setter (for objects of both types in a sequence) by calling the setter to set a value and then call the corresponding getter to print out the set value. This test should be done twice on data members that could be set to invalid values (that have numerical or character data type) – once after trying to set invalid values and subsequently, once after setting them to valid values. The data members with string data types (model, description) can be tested just once.

Solutions

Expert Solution


#include <iostream>
#include <iomanip>

using namespace std;

class UsedFurnitureItem
{
private:
// Declaring instance variables
double age;
double brandNewPrice;
string description;
char condition;
double size;
double weight;

public:
// Zero argumented constructor
UsedFurnitureItem()
{
this->age = 1.0;
this->brandNewPrice = 10.00;
this->description = "Not available";
this->condition = 'A';
this->size = 1.0;
this->weight = 1.0;
}

// Parameterized constructor
UsedFurnitureItem(double age, double brandNewPrice, string description, char condition,
double size, double weight)
{
this->age;
this->brandNewPrice = 10.00;
this->description = "Not available";
this->condition = 'A';
this->size = 1.0;
this->weight = 1.0;
}

// This function will calculate the current price
double calculateCurrentPrice()
{
double decAmt = 0.0;
if (condition == 'A')
{
decAmt = brandNewPrice * 0.10;

if (age <= 7)
{
for (int i = 1; i <= age; i++)
{
brandNewPrice -= decAmt;
}
}
else if (age > 7)
{
for (int i = 1; i <= 7; i++)
{
brandNewPrice -= decAmt;
}
}
}
else if (condition == 'B')
{
decAmt = brandNewPrice * 0.15;

if (age <= 5)
{
for (int i = 1; i <= age; i++)
{
brandNewPrice -= decAmt;
}
}
else if (age > 5)
{
for (int i = 1; i <= 5; i++)
{
brandNewPrice -= decAmt;
}
}
}
else if (condition == 'C')
{
decAmt = brandNewPrice * 0.10;


for (int i = 1; i <= age; i++)
{
if (brandNewPrice - decAmt >= 0)
brandNewPrice -= decAmt;
}
}
}

// This function will calculate the shipping cost
double CalculateShippingCost(int miles)
{
int cents = 0;
if (size < 1000 || weight < 20)
{
cents = miles;
}
else if (size >= 1000 || weight >= 20)
{
cents = miles * 2;
}
return (cents / 100.0);
}

// Setters and getters
double getAge()
{
return age;
}
void setAge(double age)
{
this->age = age;
}
double getBrandNewPrice()
{
return brandNewPrice;
}
void setBrandNewPrice(double brandNewPrice)
{
this->brandNewPrice = brandNewPrice;
}
string getDescription()
{
return description;
}
void setDescription(string description)
{
this->description = description;
}
char getCondition()
{
return condition;
}
void setCondition(char condition)
{
this->condition = condition;
}
double getSize()
{
return size;
}
void setSize(double size)
{
this->size = size;
}
double getWeight()
{
return weight;
}
void setWeight(double weight)
{
this->weight = weight;
}
};
int main()
{
       //setting the precision to two decimal places
   std::cout << std::setprecision(2) << std::fixed;
     
// Creating an instance of UsedFurnitureItem class
UsedFurnitureItem ufi;

// Calling the setters on the UsedFurnitureItem instance
ufi.setAge(12);
ufi.setBrandNewPrice(120);
ufi.setCondition('A');
ufi.setDescription("Sofa Set");
ufi.setSize(1500);
ufi.setWeight(25);

// Calling the getters on the UsedFurnitureItem instance
cout << "Description :" << ufi.getDescription() << endl;
cout << "Age :" << ufi.getAge() << endl;
cout << "Brand New Price :$" << ufi.getBrandNewPrice() << endl;
cout << "Condition :" << ufi.getCondition() << endl;
cout << "Size :" << ufi.getSize() << " cubic Inches." << endl;
cout << "Weight " << ufi.getWeight() << " pounds" << endl;

cout << "\nCurrent Price :$" << ufi.calculateCurrentPrice() << endl;
cout << "Shipping Cost :$" << ufi.CalculateShippingCost(1500) << endl;

return 0;
}

/***************************************************/

/***************************************************/

output:

/***************************************************/


Related Solutions

Code in C++ Must show: unit testing ------------------------------------ UsedFurnitureItem Create a class named UsedFurnitureItem to represent...
Code in C++ Must show: unit testing ------------------------------------ UsedFurnitureItem Create a class named UsedFurnitureItem to represent a used furniture item that the store sells. Private data members of a UsedFurnitureItem are: age (double) // age in years – default value for brandNewPrice (double) // the original price of the item when it was brand new description (string) // a string description of the item condition (char) // condition of the item could be A, B, or C. size (double) //...
c++ E2b: Design a class named Rectangle to represent a rectangle. The class contains:
using c++E2b: Design a class named Rectangle to represent a rectangle. The class contains:(1) Two double data members named width and height which specifies the width and height of the rectangle .(2) A no-arg constructor that creates a rectangle with width 1 and height 1.(3) A constructor that creates a rectangle with the specified width and height .(4) A function named getArea() that returns the area of this rectangle .(5) A function named getPerimeter() that returns the perimeter of this...
Create a class named RemoveDuplicates and write code: a. for a method that returns a new...
Create a class named RemoveDuplicates and write code: a. for a method that returns a new ArrayList, which contains the nonduplicate elements from the original list public static ArrayList removeDuplicates(ArrayList list) b. for a sentinel-controlled loop to input a varying amount of integers into the original array (input ends when user enters 0) c. to output the original array that displays all integers entered d. to output the new array that displays the list with duplicates removed Use this TEST...
Create a class named UsedFurnitureItem to represent a used furniture item that the store sells. Private...
Create a class named UsedFurnitureItem to represent a used furniture item that the store sells. Private data members of a UsedFurnitureItem are: age (double) // age in years – default value for brandNewPrice (double) // the original price of the item when it was brand new description (string) // a string description of the item condition (char) // condition of the item could be A, B, or C. size (double) // the size of the item in cubic inches. weight...
Design a class named Fan to represent a fan. The class contains: ■ Three constants named...
Design a class named Fan to represent a fan. The class contains: ■ Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. ■ A private int data field named speed that specifies the speed of the fan (the default is SLOW). ■ A private boolean data field named on that specifies whether the fan is on (the default is false). ■ A private double data field named radius that specifies...
WRITE IN C++ Create a class named Coord in C++ Class has 3 private data items...
WRITE IN C++ Create a class named Coord in C++ Class has 3 private data items               int xCoord;               int yCoord;               int zCoord; write the setters and getters. They should be inline functions               void setXCoord(int)             void setYCoord(int)            void setZCoord(int)               int getXCoord()                     int getYCoord()                   int getZCoord() write a member function named void display() that displays the data items in the following format      blank line      xCoord is                          ????????      yCoord is                          ????????      zCoord...
Code in Java Create a class named DictionaryWord as: DictionaryWord - word: String                            &n
Code in Java Create a class named DictionaryWord as: DictionaryWord - word: String                                                              - meanings: String + DictionaryWord (String word, String meanings) + getWord(): String + setWord (String word): void + getMeanings(): String + setMeanings(String meanings): void Write a program with the following requirements: Creates 8 DictionaryWord objects with: Word and meanings as the table: word meanings bank robber Steals money from a bank burglar Breaks into a home to steal things forger Makes an illegal copy of something...
in c#: Create a class named Square that contains fields for area and the length of...
in c#: Create a class named Square that contains fields for area and the length of a side and whose constructor requires a parameter for the length of one side of a Square. The constructor assigns its parameter to the length of the Square’s side field and calls a private method that computes the area field. Also include read-only properties to get a Square’s side and area. Create a class named DemoSquares that instantiates an array of ten Square objects...
Create a file named StudentArrayList.java,within the file create a class named StudentArrayList. This class is meant...
Create a file named StudentArrayList.java,within the file create a class named StudentArrayList. This class is meant to mimic the ArrayList data structure. It will hold an ordered list of items. This list should have a variable size, meaning an arbitrary number of items may be added to the list. Most importantly this class should implement the interface SimpleArrayList provided. Feel free to add as many other functions and methods as needed to your class to accomplish this task. In other...
Java Q1: Create a class named Triangle, the class must contain: Private data fields base and...
Java Q1: Create a class named Triangle, the class must contain: Private data fields base and height with setter and getter methods. A constructor that sets the values of base and height. A method named toString() that prints the values of base and height. A method named area() that calculates and prints the area of a triangle. Draw the UML diagram for the class. Implement the class. Q2: Write a Java program that creates a two-dimensional array of type integer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT