I just learned class and object today, couldn't even get the code compiled. could anyone help please? Thank you
I have three files: Product.h Product.cpp TestProduct.cpp
We haven't learned to put everything in a project yet. so for now, just just these three source files.
class Product
{
private:
int num;
string name;
int units;
char category;
double cost;
double price;
double totalCost;
public:
Product();
Product(const Product& copyFrom);
Product(int, string, char);
void setNum(int);
int getNum();
void setName(string);
string getName();
void setUnits(int);
int getUnits();
void setCategory(char);
char getCategory();
void setCost(double);
double getCost();
void setPrice(double);
double getPrice();
void setTotalCost(double);
double getTotalCost();
void receipt(int);
void ship(int);
void print();
};
#include "Product.h"
#include <iostream>
#include <string>
#include <iomanip>
Product::Product()
{
num = 00000;
name = "Skirt";
units = 10;
category = 'S';
cost = 9.98;
price = 49.98;
totalCost = cost * units;
}
Product::Product(const Product& copyFrom)
{
num = copyFrom.num;
name = copyFrom.name;
units = copyFrom.units;
category = copyFrom.category;
cost = copyFrom.cost;
price = copyFrom.cost;
totalCost = copyFrom.totalCost;
}
Product::Product(int pNum, string pName, char pCategory)
{
num = pNum;
name = pName;
category = pCategory;
}
void Product::setNum(int pNum)
{
num = pNum;
}
int Product::getNum()
{
return num;
}
void Product::setName(string pName)
{
name = pMame;
}
string Product::getName()
{
return name;
}
void Product::setUnits(int pUnits)
{
units = pUnits;
}
int Product::getUnits()
{
return units;
}
void Product::setCategory(char pCategory)
{
category = pCategory;
}
char Product::getCategory()
{
return category;
}
void Product::setCost(double pCost)
{
cost = pCost;
}
double Product::getCost()
{
return cost;
}
void Product::setPrice(double pPrice)
{
price = pPrice;
}
double Product::getPrice()
{
return price;
}
void Product::setTotalCost(double totalCost)
{
totalCost = cost * units;
}
double Product::getTotalCost()
{
return totalCost;
}
void Product::receipt(int pNum)
{
num = pNum;
units++;
}
void Product::ship(int pNum)
{
num = pNum;
units--;
}
void Product::print()
{
cout << fixed << showpoint << setprecision (2);
cout << num << " " << name << " " << units << " "
<< category << " " << cost << " " << price << " "
<< totalPrice << endl;
}
#include "Product.cpp"
#include <string>
#include <iostream>
using namespace std;
int main()
{
int num;
string name;
int units;
char category;
double cost;
double price;
double totalCost;
Product obj1;
Product obj2(00001, "shirt",'m');
Product obj3;
obj2.setCost(9.99);
obj2.getCost();
obj2.setPrice(39.99);
obj2.getPrice();
obj2.setTotalCost(totalCost);
obj2.getTotalCost();
cout << "Enter the number: " << endl;
cin >> num;
cout << "Enter the name: " << endl;
cin >> name;
cout << "Enter the units: " << endl;
cin >> units;
cout << "Enter the category: " << endl;
cin >> category;
cout << "Enter the cost: " << endl;
cin >> cost;
cout << "Enter the price: " << endl;
cin >> price;
obj3.setNum(num);
obj3.getNum();
obj3.setName(name);
obj3.getName();
obj3.setUnits(units);
obj3.getUnits();
obj3.setCost(cost);
obj3.getCost();
obj3.setPrice(price);
obj3.getPrice();
obj3.setTotalCost(totalCost);
obj3.getTotalCost();
Product obj4(obj3);
obj1.print();
obj2.print();
obj3.print();
obj4.print();
system ("pause");
return 0;
}