Question

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:

6. Inventory Class Design an Inventory class that can hold information and calculate data for items ma retail stores invento

Demonstrate the class in a driver program. Input validation, don’t accept negative values for item number, quantity, or cost.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer :

please upvote if answer upto your expectation or comment for any query . thanks

"inventory.h"

#ifndef INVENTORY_H
#define INVENTORY_H


class inventory
{
public:
inventory();
inventory(int itemNum,int Quantity,double Cost);
void setItemNumber(int Item);
void setQuantity(int Quantity);
void setCost(double cost);
void setTotalCost();
int getItemNumber();
int getQuantity();
double getCost();
double getTotalCost();


private:
int itemNumber;
int quantity;
double cost;
double totalCost;
};

#endif // INVENTORY_H

"inventory.cpp"

#include<iostream>
#include "inventory.h"
using namespace std;
inventory::inventory() // default constructor set all values to zero
{
itemNumber=0;
quantity=0;
cost=0.0;
totalCost=0.0;


}

inventory :: inventory(int itemNum,int Quantity,double Cost) //set all values passed using parameter constructor
{
setItemNumber(itemNum);
setQuantity(Quantity);
setCost(Cost);
setTotalCost(); //calculate cost

}

void inventory :: setItemNumber(int itemNum)
{
if(itemNum>=0) //check for negative value if so set zero and print a message
itemNumber=itemNum;
else
{
itemNumber=0;
cout<<"don't pass negative value" <<"\n";
}
}

void inventory :: setQuantity(int Quantity)
{
if(Quantity>=0) //check for negative value if so set zero and print a message
quantity=Quantity;
else
{
quantity=0;
cout<<"don't pass negative value" <<"\n";
}

}

void inventory :: setCost(double Cost)
{
if(Cost>=0) //check for negative value if so set zero and print a message
cost=Cost;
else
{
cost=0.0;
cout<<"don't pass negative value" <<"\n";
}
}

void inventory :: setTotalCost()
{
totalCost=quantity*cost;
}


int inventory :: getItemNumber()
{
return itemNumber; //return itemNumber
}

int inventory :: getQuantity()
{
return quantity; //return item quantity

}

double inventory :: getCost()
{
return cost; //return cost
}

double inventory :: getTotalCost()
{

return totalCost; //return total cost
}


"main.cpp"

#include <iostream>

#include "inventory.h"
using namespace std;

int main()
{
cout << "Testing for parameter constructor" << endl;
inventory in(11,12,18.19); //set and get values using parameter constructor
cout<<in.getCost()<<endl;
cout<<in.getItemNumber()<<endl;
cout<<in.getQuantity()<<endl;
cout<<in.getTotalCost()<<endl;
inventory Int; //set and get values using default constructor

cout<<"Testing for default constructor "<<endl;
Int.setCost(110.98);
Int.setItemNumber(10);
Int.setQuantity(16);
Int.setTotalCost();
cout<<Int.getCost()<<endl;
cout<<Int.getItemNumber()<<endl;
cout<<Int.getQuantity()<<endl;
cout<<Int.getTotalCost()<<endl;

cout<<"testing for negative values"<<endl;

inventory I(11,12,-10); //set and get values using parameter constructor
cout<<I.getCost()<<endl;
cout<<I.getItemNumber()<<endl;
cout<<I.getQuantity()<<endl;
cout<<I.getTotalCost()<<endl;


return 0;
}

X CAUsers tinku\Desktop\main\bin\Debug\main.exe Testing for parameter constructor 18.19 11 12 218.28 Testing for default cons

Add a comment
Know the answer?
Add Answer to:
I need help with my homework please. I should write this program in C++ language and...
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 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...

  • C++ Retailltem.h, Retailltem.cpp, Store.h, Store.cpp, and Driver.cpp. Description: Write a set of programs that holds data...

    C++ Retailltem.h, Retailltem.cpp, Store.h, Store.cpp, and Driver.cpp. Description: Write a set of programs that holds data about items in a retail store. Your submission should include 5 files, Retailltem.b, Retailltem.cpp, Store, Store.cpp, and Driver.cpp 1. Retailltem class: The class should have three member variables • description (a string, represent the item's name. A name contains space) quantity (an int, represent how many current available) price (a double, item's price) Member Functions Constructor with default argument get Description getQuantity getPrice setDescription...

  • Write a program in C++ that simulates a soft drink machine. The program will need several...

    Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...

  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • Note- can you rewrite the code in C++ if there is any existing code. Can you...

    Note- can you rewrite the code in C++ if there is any existing code. Can you not use arrow -> operator. Write a circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument . • setRadius. A mutator function...

  • c++ I need help! create Student.h In this class, you are provided with a class skeleton...

    c++ I need help! create Student.h In this class, you are provided with a class skeleton for the Student type. This type should contain two member variables: a string called name a vector of doubles called grades Additionally, you should declare the following functions: A constructor which accepts a single string parameter called name A void function, addGrade which accepts a single double parameter and adds it to the grades vector A function which accepts no parameters and returns the...

  • (Classes and Objects) Design a class named Box. The class should have the following private members:...

    (Classes and Objects) Design a class named Box. The class should have the following private members: width - A double member variablethat holds the width of the box. length – A double member variable for holding the length of the box. height – A double member variable of type double that holds the height of the box. In addition, provide the following member functions with full (inline) implementation. a) A default constructor that sets all member variables to 0. b)...

  • Write the implementation (.cpp file) of the GasTank class of the previous exercise. The full specification...

    Write the implementation (.cpp file) of the GasTank class of the previous exercise. The full specification of the class is: A data member named amount of type  double . An data member named capacity of type  double . A constructor that accepts a parameter of type  double . The value of the parameter is used to initialize the value of capacity. The constructor also sets amount to zero. A function named addGas that accepts a parameter of type  double . The value of the...

  • Long Answer 2: (Classes and Objects) Design a class named Box. The class should have the...

    Long Answer 2: (Classes and Objects) Design a class named Box. The class should have the following private members: width - A double member variablethat holds the width of the box. length – A double member variable for holding the length of the box. height – A double member variable of type double that holds the height of the box. In addition, provide the following member functions with full (inline) implementation. a) A default constructor that sets all member variables...

  • Write the implementation (.cpp file) // i cant figure out what it wants where the is a ? the...

    Write the interface (.h file) of a class Accumulator containing:A data member named sum of type integer.A constructor accepting an integer parameter.A function named getSum that accepts no parameters and returns an integer.A function named add that accepts an integer parameter and returns no value.class Accumulator{int sum;Accumulator(int);int getSum ();void add (int);};Write the implementation (.cpp file) of the Accumulator class of the previous exercise. The full specification of the class is:An data member named sum of type integer.A constructor that accepts...

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
Active Questions
ADVERTISEMENT