**please follow the format exactly and specify what code would be in which file.
ID: 3555287 • Letter: #
Question
**please follow the format exactly and specify what code would be in which file. please write in c++ not c#
Define a class named Inventory. The class inventory should be written in a header file name Inventory.hpp. The class consists of following variables and functions--
Variables:
Functions:
All the class variables should be private and the class functions public. The class functions should be implemented in a file Inventory.cpp which should be linked with the inventory.hpp file.
After being done with the class declaration, create a file named Inventory-Main.cpp where you need to write your main function. You need to link both Inventory.cpp and Inventory.hpp to this file. In the main function, create an object of Type Inventory. Prompt the user to enter a value for the variables itemNumber, quantity, and cost. Set the variables and calculate the total cost. Display the values of all the variables for the object using the get functions in the following format:
"The item number 1 has 12 quantity each having a cost of 1.5 unit with the total cost being 18 units"
Explanation / Answer
Inventory.hpp
#include <iostream>
using namespace std;
class Inventory {
public:
Inventory();
void setItemNumber(int itemNo);
void setQuantity(int q);
void setCost(double c);
void setTotalCost();
int getItemNumber();
int getQuantity();
double getCost();
double getTotalCost();
private:
int itemNumber;
int quantity;
double cost;
double totalCost;
};
Inventory.cpp
#include "Inventory.hpp"
Inventory::Inventory() {
itemNumber = 0;
quantity = 0;
cost = 0;
totalCost = 0;
}
void Inventory::setItemNumber(int itemNo) {
itemNumber = itemNo;
}
void Inventory::setQuantity(int q) {
quantity = q;
}
void Inventory::setCost(double c) {
cost = c;
}
void Inventory::setTotalCost() {
totalCost = cost*quantity;
}
int Inventory::getItemNumber() {
return itemNumber;
}
int Inventory::getQuantity() {
return quantity;
}
double Inventory::getCost() {
return cost;
}
double Inventory::getTotalCost() {
return totalCost;
}
Inventory-Main.cpp
#include <iostream>
#include "Inventory.hpp"
using namespace std;
int main() {
int itNo, q;
double c;
Inventory inv = Inventory();
cout << "Input the item Number: ";
cin >> itNo;
inv.setItemNumber(itNo);
cout << "Input the quantity: ";
cin >> q;
inv.setQuantity(q);
cout << "Input the cost: ";
cin >> c;
inv.setCost(c);
inv.setTotalCost();
cout << "The item number "<<inv.getItemNumber()<<" has "<<inv.getQuantity()<<" quantity each having a cost of "<<inv.getCost()<<" unit with the total cost being "<<inv.getTotalCost()<<" units ";
return 0;
}
How to run:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.