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

SOLUTION-

I have solve the problem in C++ code with comments and screenshot for easy understanding :)

CODE-

UsedFurnitureItem.hpp

#ifndef USED_FURNITURE_ITEM_H
#define USED_FURNITURE_ITEM_H
#include<string>
using namespace std;
//class declaration
class UsedFurnitureItem
{
private: //private members
double age;
double brandNewPrice;
string description;
char condition;
double size;
double weight;
double calculateCurrentPrice();
double calculateShippingCost(double);
public: //public members
UsedFurnitureItem(double,double,string,char,double,double);
void printInvoice(double);
};

#endif

UsedFurnitureItem.cpp

#include <iostream>
#include "UsedFurnitureItem.hpp"
using namespace std;
//constructor
UsedFurnitureItem::UsedFurnitureItem(double ag,double price,string desc,char cond,double sz,double wt )
{
age=ag;
description=desc;
brandNewPrice=price;
condition=cond;
size=sz;
weight=wt;
}

//function to calcul;ate price
double UsedFurnitureItem::calculateCurrentPrice()
{
double price=0;
if(condition=='A' ||condition=='a') //if condition is A
{
if(age<=7) //if age is less than 7
{
double percent=age*10.0; //percentage depreciation
price=((100-percent)/100)*brandNewPrice; //final price
}
else //if age is more than 7
price=0.3*brandNewPrice; //30% of new price
}

else if(condition=='B' ||condition=='b') //if condition is B
{
if(age<=5) //if age is less than 5
{
int percent=age*15.0; //percentage depreciation
price=((100-percent)/100)*brandNewPrice; //final price
}
else //if age is more than 5
price=0.2*brandNewPrice; //20% of new price
}
else //if condition is C
{
price=0.1*brandNewPrice; //price is 10% of new price
}

return price; //return price
}
//function to calculate shipping cost
double UsedFurnitureItem::calculateShippingCost(double miles)
{
double cost;
if(weight<=20 && size <=1000)
cost=miles; //1 cent per mil
else
cost=2*miles; //2 cents per mile

return cost/100; //returning in dollars
}
//function to print invoice
void UsedFurnitureItem::printInvoice(double miles)
{
cout<<"Age: "<<age<<endl;
cout<<"Brand New Price: $"<<brandNewPrice<<endl;
cout<<"Description: "<<description<<endl;
cout<<"Condition: "<<condition<<endl;
cout<<"Size: "<<size<<endl;
cout<<"Weight: "<<weight<<endl;
cout<<"Calculated current price: $"<<calculateCurrentPrice()<<endl; //calling function fro price calculator
cout<<"Calculated shipping cost: $"<<calculateShippingCost(miles)<<endl; //calling function to calculate shipment cost
cout<<endl;
}

main.cpp

#include <iostream>
#include "UsedFurnitureItem.hpp"

using namespace std;
//main
int main()
{
//variables for different inputs
double age;
double brandNewPrice;
string description;
char condition;
double size;
double weight;
double miles;
//prompt for different inputs and reading those input
cout << "Enter the age of Item: ";
cin>>age; //enter age
cout << "Enter the Brand New Price of Item: ";
cin>>brandNewPrice;
cout << "Enter the condition of Item(A,B,C): ";
cin>>condition;
cout << "Enter the Description of Item: ";
cin.ignore(); //clearing the buffer of cin
getline(cin,description);
cout << "Enter the Size of Item: ";
cin>>size; //enter size
cout << "Enter the Weight of Item: ";
cin>>weight;
cout << "Enter the Shipping miles: ";
cin>>miles; //enter miles for shipping
//creating object of UsedFurnitureItem with parameters
UsedFurnitureItem item(age,brandNewPrice,description,condition,size,weight);
item.printInvoice(miles); //printing invoice for item
return 0;
}

SCREENSHOT -

IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


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