Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write in C++ Detail Requirements Create a class named Product. Separate the Product class's interface from the implementation. Put the class's interface in a file

Write in C++

Detail Requirements

  1. Create a class named Product. Separate the Product class's interface from the implementation. Put the class's interface in a file named Product.h and the class implementation in a file named Product.cpp.

  2. Create three private data members to hold a product number (long), a product description (characters of length 50 or fewer; Any more than 50 characters will be cut off at 50; Use the string data type), and unit cost (dollars and cents). The product description must allow spaces as part of the description.

  3. Create public accessor and mutator member functions to get and set each of the three data members. Name your functions appropriately.

  4. Create the following constructors.

    1. A default constructor. Initialize the product number to a serial increasing number - one more than the last object created using this constructor (hint: use a static data member). Initialize the description to an empty string and the cost to zero.

    2. A copy constructor. Do not use the default copy constructor provided by the compiler. You must write your own code for the copy constructor.

    3. A conversion constructor that accepts a long for the product number and uses the default values of the empty string for the product description and zero for the unit cost.

    4. A constructor that takes an appropriate argument for each of the three data members: product number, product description, and unit cost.

  5. The class should have a destructor that performs appropriate clean up functions (deleting any memory allocated for the character pointer).

  6. Provide appropriate addition operators such that the following rules are implemented. Each of the functions you write should return back a value with the same data type as the unit cost member variable.

    1. n = productObj2 + productObj1 where n becomes the sum of the unit costs of productObj2 and productObj1 .

    2. n = productObj2 + z where n becomes the sum of the unit cost of productObj2 and the scalar variable/constant/expression z.

    3. n = z + productObj2 where n becomes the sum of the unit cost of productObj2 and the scalar variable/constant/expression z.

  7. Provide appropriate subtraction operators such that the following rules are implemented. Each of the functions you write should return back a value with the same data type as the unit cost member variable.

    1. n = productObj2 - productObj1 where n becomes the unit cost of productObj2 minus the unit cost of productObj1 .

    2. n = productObj2 - z where n becomes the the unit cost of productObj2 minus the scalar variable/constant/expression z.

    3. n = z - productObj2 where n becomes the scalar variable/constant/expression z minus the unit cost of productObj2 .

  8. Add appropriate comparison operators such that the ==, >, < operators all compare the unit cost of one Product object to the unit cost of a second Product object and return an appropriate Boolean value.

  9. Overload the insertion operator (<<) to print the following:

    Information for product n: Description: Cost: 

    You will replace n with the product number, print out the description and cost for the Product object used with the insertion operator.

  10. Overload the extraction operator (>>). This function should create a console "dialog" allowing the user to enter all the data for one Product object. You can assume the user will not enter in a product description longer than 80 characters. The product description must allow the user to enter a value that can contain spaces. Example dialog is shown below.

    Enter the product number : Enter the description: Enter the unit cost: 
  11. Provide an overloaded assignment operator that does a member-wise assignment. Do not use the default memberwise assignment provided by the compiler. You must write your own code for the overloaded assignment operator.

  12. Do not create any inline functions for this class. Other than the overloaded insertion and extraction operator, you should not print from within your Product class.

  13. Write a client application that uses the Product class. Name this file TestProduct.cpp. Create the appropriate objects and perform the necessary operations to test each function and constructor in the Product class. Print appropriate messages to the console to indicate the results of the functions.

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

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions