View Single Post
Old 04-21-2005, 09:47 PM   #1 (permalink)
cleverest
Registered User
 
Join Date: Mar 2005
Posts: 22
cleverest is on a distinguished road
Question Classes started with C++ classes and now I'm lost...HELP

I'm supposed to make my first C++ Program using classes and I've barely learned how to use functions.....I've went from having to make one file (.cpp) to having to make THREE (.cpp .cpp .h)

If anyone can point me in the right direction with how to do this I'd appreciate it. I don't think what the instructor is teaching us is sinking in very well (I take these classes online, not in a classroom, maybe that's the problem...or I'm just not getting it...probably more likely)

This is the current assignment, I don't expect anyone to do it for me just need some idea if the code I've written below is on the right track....please don't add anymore complexity then needed as I'm not even comprehending what I'm using already. lol

Quote:
THE ASSIGNMENT:

Project 1: Clothing
The class Clothing represents a washable article of clothing. Implement the class Clothing so
that each instance of Clothing has a string kind and two boolean values which mark whether
the article is clean or dirty, wet or dry. As the sample driver shows, the wash( ), dry( )
and wear( ) methods of Clothing cannot be called twice or more times in succession. Read
the driver code and sample output carefully to understand the ordering of the method calls and
the appropriate output statements your class should generate.
The point behind this assignment is to realize that not all methods are created equal. In fact,
very often, there is a logical sequence to order in which certain methods can be called. It is the
class itself that enforces this ordering. Note the various errors that are printed when driver code
doesn't use the Clothing class correctly, like when it tries to dry clothes that are not wet, or
when it tries to re-wash clothing that has already been washed and is waiting to be dried. As
we learn more complex classes, this kind of sequence to the way methods are called is quite
typical.
Following the class diagrams shown below, implement the Clothing class. Embed your class in
a suitable test program that provides the sample dialogue shown below. You may choose to
create any number of additional methods, but you are required to implement all of the public
methods shown below. You are free to ignore the private parts of the class I suggest below.

Implementation Details

Sample CLASS
(the Clothing Class to make?)

Clothing
Clothing( string kind );
void wash( );
void dry( );
void wear( );
bool isClean( );
bool isWet( );
bool isDirty( );
String my_Kind;
bool my_isClean;
bool my_isWet;



SAMPLE DRIVER
Clothing shirt( “t-shirt” );
shirt.wear();
if (shirt.isDirty()) {
shirt.wash();
if (shirt.isWet()) {
shirt.dry();
}
else {
cout << “shirt should be
wet!” << endl;
}
}
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!
My work so far (it doesn't do anything yet...)....probably totally messed up anyways....

MY CLOTHING.H file

Code:
#ifndef CLOTHING_H
#define CLOTHING_H
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;


class Clothing {
public:
	Clothing ( );
	Clothing(string Kind);
	string my_Kind( );
	void wash( );
	void setWash( );
	void dry( );
	void setDry( );
	void wear( );
	void getWear( );
	bool isClean( );
	bool isWet( );
	bool isDirty( );


private:
	bool my_isClean;
	bool my_isWet;

};

#endif


MY CLOTHING.CPP file

Code:
#include <iostream>
#include <cstdlib>
#include <string>

#include "Clothing.h"

using namespace std;



Clothing::Clothing() {


}







void Clothing::wear( ) {

}

void Clothing::wash( ) {


}

void Clothing::dry( ) {


}

void Clothing::getWear( ){


}
void Clothing::setWash( ) {


}

void Clothing::setDry( ) {


}


bool isClean( ){

}

bool isWet( ){

}

bool isDirty( ){

}

bool my_isClean( ){{

}


}

MY DRIVER FILE (driver.cpp)

Code:
#include <iostream>
#include <cstdlib>
#include <string>

#include "Clothing.h"

using namespace std;

int main()
{
string shirt;
string my_Kind;

cout << "Wearing this t-shirt\n";
cout << "Washing this t-shirt\n";
cout << "Drying this t-shirt\n";
cout << "Wearing this t-shirt\n";
cout << "You cannot dry this t-shirt because it isn’t wet!\n";
cout << "Washing this t-shirt\n";
cout << "You cannot wash this t-shirt because it has\n";
cout << "already been washed and needs to be dried!\n";
cout << "Drying this t-shirt\n";
cout << "You cannot dry this t-shirt because it has\n";
cout << "already been dried and needs to be worn!\n";

return 0;

}
I know I've practically done nothing, but I'm not sure how to progress...help anyone? Thanks in advance.
cleverest is offline   Reply With Quote