View Single Post
  #2 (permalink)  
Old January 28th, 2004, 10:08 PM
nikolai nikolai is offline
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This sounds suspiciously like homework, so I won't give you a working answer. I will tell you that you should #include iostream, NOT iostream.h. Also, the member variable, book, of the card class is declared to be of type char. That's just one character. You probably meant a char *. Better yet, use a std::string. You'll need to #include <string> to get access to that type.


Now then, in your main(), you declare three variables of type "card". You seem confused because these three variables are named "book", "author", and "nocopies". These names don't make sense. Think about it -- you're creating an object of type "card". So the variable name should have something to do with cards. "book", "author", and "nocopies" are *properties* of cards.

A better name would've been "my_card" or something like that.

In fact, the most widely accepted naming convention is to capitalize the names of your classes and data types, and to use lower-case names for your variables. In that sense, you'd have:
------------------------------------------------------------
// card.h
class Card
{
   // Class declarations go here...
};
------------------------------------------------------------
// card.cpp

#include "card.h"

// Class implementations go here...
------------------------------------------------------------


Finally, your main() simply calls show() on each of your three card variables, but you never store() anything in them. So the output of your program would be meaningless -- you'd be displaying three empty cards.

At the bare minimum, you don't need to mess with more than one card, but you DO need to exercise all of your public functions -- that is, store() and show().

That means your main should look something like this:

------------------------------------------------------------
// main.cpp

#include "card.h"

int main(int argc, char * argv[])
{
    Card card;

    card.store();
    card.show();

    return 0;
}
------------------------------------------------------------


One more thing -- don't forget to define constructor(s) and a destructor for your Card class.



And please, please please please -- DON'T TYPE IN ALL CAPS.


Take care,

Nik
http://www.bigaction.org/
Reply With Quote