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.
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;
}
I need help with my homework please. I should write this program in C++ language and...
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 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...
C++ 8. Circle Class 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 for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area...
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 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 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 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: 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 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 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...