View Single Post
Old 04-22-2005, 12:09 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Quote:
shirt.wear();
shirt.dry();
shirt.wash();
shirt.wash();
shirt.dry();
shirt.dry();
SAMPLE OUTPUT
Wearing this t-shirt
Washing this t-shirt
Drying this t-shirt
Wearing this t-shirt
You cannot dry this t-shirt because it isn’t
wet!
Washing this t-shirt
You cannot wash this t-shirt because it has
already been washed and needs to be dried!
Drying this t-shirt
You cannot dry this t-shirt because it has
already been dried and needs to be worn!
These are the crucial parts, telling you what your functions must do, when combining them in a small virtual run of the program it makes more sence. The order in which the functions are called is crucial in this program, which is what the output tries to tell you.
shirt.wash(); -> "Washing this t-shirt"
shirt.wash(); -> "You cannot wash this t-shirt because it has already been washed and needs to be dried!"
shirt.dry(); -> "Drying this t-shirt"
shirt.dry(); -> "You cannot dry this t-shirt because it has already been dried and needs to be worn!"
shirt.wear(); -> "Wearing this t-shirt"
shirt.dry(); -> "You cannot dry this t-shirt because it isn’t
wet!"

This means, when you wear a Clothing item, it checks the washed and dried boolean, if they are true, the washed boolean will be set to false, and you wear the item, if the washed is false, it needs to be washed, if the dried is false, it needs to be dried.

When you wash a Clothing item, it sees if the washed boolean is false, if it is, set it to true and set the dried boolean to false and just wash it, if not tell the user theres no need to wash it again.

The dry function, sees if the dried boolean is set to false and washed boolean is true, is this the case, set dried to true and dry the item, if washed is false, tell the thing has been worn and it needs to be washed. Else tell theres no need to dry the item.

Does this make it more clear how these three functions work together ?

For the constructor, you just need to set washed and dried to false, and if theres a lable parsed to the constructor use this as the string name of the item, somethign like this:
Code:
class Clothing {
public:
	Clothing ( );
	Clothing(string Kind);
	void wash( );
	void dry( );
	void wear( );
private:
	bool dried;
	bool washed;
        string kind;
};
Code:
Clothing::Clothing() {
    cout << "It is impossible to create a Clothing item, which isn't named anything" << endl;
}
Clothing::Clothing(string Kind) {
    kind = Kind;
    washed = false;
    dried = false;
}
void Clothing::wear( ) {
    if(washed && dried)
    {
        washed = false;
        cout << "Wearing this " << kind << endl;
    }
    else
    {
        cout << "This " << kind;
        if(washed)
            cout <<" has been washed and needs to be dried!" << endl;
        else
            cout << " has been worn and needs to be washed" << endl;
}
// and so forth
Code:
int main()
{
    Clothing item ("t-shirt");
    item.wear();
    item.wash();
    item.dry();
    // and so forth
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote