Dec 4, 2011 at 11:39pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include<iostream>
#include<string>
using namespace std;
class RetailItem
{
private :
char *description;
int unitsOnHold;
double price;
public :
RetailItem(char *description,int stock,double price)
{
this ->description = description;
unitsOnHold = stock;
double price = price;
}
int getStock()
{
return unitsOnHold;
}
double getPrice()
{
return price;
}
char *getDescription()
{
return description;
}
void setStock(int stock)
{
unitsOnHold = stock;
}
void setdescription(char *ptr)
{
description = ptr;
}
void setPrice(double price)
{
price = price;
}
};
int main()
{
RetailItem obj1("jacket" ,12,59.95);
RetailItem obj2("Designer Jeans" ,40,34.95);
RetailItem obj3("Shirt" , 20, 24.95);
cout << obj1 << endl;
cout << obj2 << endl;
cout << obj3 << endl;
system("pause" );
return 0;
}
This code will not compile, i can't figure out why. I'm trying to have it print out the each of the objects. Anyone see a problem?
Last edited on Dec 5, 2011 at 1:00am UTC
Dec 4, 2011 at 11:46pm UTC
You don't need semicolon after function definitions. You forgot the closing bracket for the class definition. You have not defined an istream& operator <<(istream&, const RetailItem&)
. Line 14 should be this ->description = description;
. Use const char *
for the strings.
Dec 5, 2011 at 1:00am UTC
Updated code. i'm still having some trouble. I also am not sure what you mean by what i didn't define. You're gonna have to explain more i'm really slow with this stuff. Thanks!
Dec 5, 2011 at 1:07am UTC
What and how do you think this should work cout << obj1 << endl;
? What I'm saying is that you have not defined the operator to make this possible.
Dec 5, 2011 at 1:20am UTC
Thanks, i get what you meant now haha. All fixed :)
on another note, does anyone know how to create a UML diagram in Microsoft Visual C++ 2010?