Question

1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files)...

1a. Create a class named Inventory
- Separate declaration from implementation (i.e. Header and CPP files)
1b. Add the following private member variables
- a int variable named itemNumber
- an int variable named quantity
- a double variable named cost
- a double variable named totalCost. Total cost is defined as quantity X cost.
- updateTotalCost() which takes no arguments and sets the values of the variable totalCost.
1c. Add the following public functions:
- Accessor and Mutators for all private member variables
- getTotalCost which returns the value of totalCost
- Default constructor which sets all the member variables to 0. Finally, call the updateTotalCost function.
- A non-default constructor which accepts an item’s number, quantity, and cost as arguments. This constructor must calls the mutator functions to set the values of the appropriate member variables. Finally, call the updateTotalCost function.
1d. Write a main():
- Create an instance of type Inventory using the default constructor.
- Prompt the user to enter an itemNumber, cost, and quantity.
- Use the mutator methods to update itemNumber, cost, and quantity.
- Using the accessor functions, print the values of itemNumber, cost, quantity, and totalCost.
- Create a new instance of type Inventory using the non-default constructor.
- Using the accessor functions, print the values of itemNumber, cost, quantity, and totalCost.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Inventory.h
#ifndef Inventory_H
#define Inventory_H
class Inventory{
  
   private:
       int itemNumber;
       int quantity;
       double cost;
       double totalCost;
       void updateTotalCost();
      
   public:
       Inventory();
       Inventory(int itn, int qty, double cost);
       void setItemNumber(int itn);
       int getItemNumber();
       void setQuantity(int qty);
       int getQuantity();
       void setCost(double Cost);
       double getCost();
       double getTotalCost();
};
#include"Inventory.cpp"
#endif
Inventory.cpp

#include"Inventory.h"

Inventory::Inventory()
{
   itemNumber = 0;
   quantity = 0;
   cost = 0.0;
   updateTotalCost();
}

Inventory::Inventory(int itn, int qty, double cst)
{
   itemNumber = itn;
   quantity = qty;
   cost = cst;
   updateTotalCost();
}

void Inventory::setItemNumber(int itn)
{
   itemNumber = itn;
}

void Inventory::setQuantity(int qty)
{
   quantity = qty;
   updateTotalCost();
}

void Inventory::setCost(double Cost)
{
   cost = Cost;
   updateTotalCost();
}

int Inventory::getItemNumber()
{
   return itemNumber;
}

int Inventory::getQuantity()
{
   return quantity;
}

double Inventory::getCost()
{
   return cost;
}

double Inventory::getTotalCost()
{
   return totalCost;
}

void Inventory::updateTotalCost()
{
   totalCost = quantity * cost;
}

Main.cpp

#include"Inventory.h"
#include<iostream>
using namespace std;

int main()
{
   Inventory myInventory;
   int itemNum, quantity;
   double cost;
   cout << "Enter the item number: ";
   cin >> itemNum;
   cout << "Enter the Quantity of the item: ";
   cin >> quantity;
   cout << "Enter the unit cost of the item: $";
   cin >> cost;
   myInventory.setItemNumber(itemNum);
   myInventory.setQuantity(quantity);
   myInventory.setCost(cost);
   cout << endl;
   cout << "Item number: " << myInventory.getItemNumber() << endl;
   cout << "Quantity: " << myInventory.getQuantity() << endl;
   cout << "Unit cost: $" << myInventory.getCost() << endl;
   cout << "Total cost: $" << myInventory.getTotalCost() << endl;
  
   cout << endl;
   cout << "-- Testing the parameterized constructor --" << endl;
   Inventory myInventory2(itemNum, quantity, cost);
   cout << "Item number: " << myInventory2.getItemNumber() << endl;
   cout << "Quantity: " << myInventory2.getQuantity() << endl;
   cout << "Unit cost: $" << myInventory2.getCost() << endl;
   cout << "Total cost: $" << myInventory2.getTotalCost() << endl;
}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1a. Create a class named Computer - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Computer - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - an int variable named year - a string variable named model - a string variable named purpose 1c Add the following public functions: - Default constructor which sets numeric members to -1 and string members to the empty string - Destructor to print "Removing instance from memory" - A non-default constructor to set the year and...

  • I need help with my homework please. I should write this program in C++ language and...

    I need help with my homework please. I should write this program in C++ language and use Inventory.h file (header file), Inventory.cpp file (implementation file), and main.cpp file (main program). This is the program: Demonstrate the class in a driver program. Input validation, don’t accept negative values for item number, quantity, or cost. 6. Inventory Class Design an Inventory class that can hold information and calculate data for items ma retail store's inventory. The class should have the following private...

  • Help with this coding assignment for C++! Add any comments for better understanding. Create a class...

    Help with this coding assignment for C++! Add any comments for better understanding. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The constructor will initial all member variable to a default value 0. • One public pure virtual function showingredients() that returns void....

  • Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type...

    Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type double that stores the amount of the payment and appropriate accessor (getPaymentAmount() ) and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment. Override toString() method to call the paymentDetails() method to print the contents of payment amount and any other details not included in paymentDetails(). Define a class named CashPayment that is...

  • Create a class named Cash. Include one private integer variable to hold the number of dollars...

    Create a class named Cash. Include one private integer variable to hold the number of dollars and one to hold the number of cents. Create your own accessor and mutator functions to read and set both member variables. Create a function that returns the amount of money as a double. Test all of your functions. Use at least 4 Cash objects. Must be done in c++

  • Please submit a .cpp file or upload zip if you have more than one file before...

    Please submit a .cpp file or upload zip if you have more than one file before the time up. No library function is allowed. ***The code must contain your name and has proper format. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The...

  • Using C++, Write a class named Employee that has the following member variables: name. A string...

    Using C++, Write a class named Employee that has the following member variables: name. A string that holds the employee's name. idNumber. An int variable that holds the employee's ID number. department. A string that holds the name of the department where the employee works. position. A string that holds the employee's job title. The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee's name,...

  • Implement the following class in interface and implementation files. A separate file (the main project file)...

    Implement the following class in interface and implementation files. A separate file (the main project file) shall have the main function that exercises this class. Create a class named Student that has three member variables: name - string that stores the name of the student numClasses - integer that tracks how many courses the student is currently enrolled in, this number must be between 1 and 100 ClassList - an array of strings of size 100 used to store the...

  • In JAVA 1. Create a class called Rectangle that has integer data members named - length...

    In JAVA 1. Create a class called Rectangle that has integer data members named - length and width. Your class should have a default constructor (no arg constructor) Rectangle() that initializes the two instance variables of the object Rect1. The second overloading constructor should initializes the value of the second object Rect2. The class should have a member function named GetWidth() and GetLength() that display rectangle's length and width. OUTPUT: Rectl width: 5 Rectl length: 10 Enter a width :...

  • C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to...

    C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to the project. Copy and paste the code is listed below: Design a class named Employee. The class should keep the following information in member variables: Employee name Employee number Hire date // Specification file for the Employee class #ifndef EMPLOYEE_H #define EMPLOYEE_H #include <string> using namespace std; class Employee { private:        // Declare the Employee name string variable here. // Declare the Employee...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT