Ok... This is my assignment, its fairly easy. I need to make a class for a retail store. storing only 3 items in the class using arrays.
How would I pass a value x into getDiscription() to d[] and have it print the next item. have it print d[0] then increase by one and print d[1].
Does that make sense at all?? Its really hard for me to explain it. I think i need to pass by reference but I am not sure how to do that. I will post the output.
RetailItem.cpp
CODE
#include <cstdlib>
#include <iostream>
#include <string>
#include "RetailItem.h"
using namespace std;
RetailItem::RetailItem()
{
}
double RetailItem::getPrice()
{
p[0] = 59.95;
p[1] = 34.95;
p[2] = 24.95;
return p[];
}
string RetailItem::getDescription()
{
d[0] = "Jacket";
d[1] = "Jeans";
d[2] = "Shirt";
return d[];
}
double RetailItem::getUnitsOnHand()
{
oh[0] = 12;
oh[1] = 40;
oh[2] = 20;
return oh[];
}
RetailItem.h
CODE
#include <cstdlib>
#include <iostream>
#include <string>
#include "RetailItem.h"
using namespace std;
RetailItem::RetailItem()
{
}
double RetailItem::getPrice()
{
p[0] = 59.95;
p[1] = 34.95;
p[2] = 24.95;
return p[];
}
string RetailItem::getDescription()
{
d[0] = "Jacket";
d[1] = "Jeans";
d[2] = "Shirt";
return d[];
}
double RetailItem::getUnitsOnHand()
{
oh[0] = 12;
oh[1] = 40;
oh[2] = 20;
return oh[];
}
Main.cpp
CODE
#include <cstdlib>
#include <iostream>
#include "RetailItem.h"
#include <iomanip>
using namespace std;
const unsigned W = 20;
int main(int argc, char *argv[])
{
RetailItem r;
cout<<setw(W)<<"Description"<<setw(W)<<"Units on Hand"<<setw(W)<<"Price"<<endl;
cout<<endl;
cout<<"Item #1";
cout<<setw(10)<<r.getDescription();
cout<<setw(15)<<r.getUnitsOnHand();
cout<<setw(25)<<r.getPrice()<<endl;
cout<<"Item #2"<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
OUTPUT
CODE
Description Units On Hand Unit Price ($)
Item #1 Jacket 12 59.95
Item #2 Jeans 40 34.95
Item #3 Shirt 20 24.95