View Single Post
Misc C++ things I have trouble understanding
Old
  (#1)
Bill
Guest
 
Status:
Posts: n/a
Default Misc C++ things I have trouble understanding - 02-04-2004

I find myself asking myself certain questions when I am programming C++. When I consult textbooks, I often find the answers cryptic, or over simplified. Lately, I have been experimenting with pointers and OOP.

I'll start with OOP. Here, I've written a program that declares a class for some of the properties of a gem, creates a gem named "bob", and within the main function, the characteristics for bob are declared then echoed back.

Code:
//*********************************
//Name: Bill					  *
//Project: OOP Experiment		 *
//Date: 3/31/04				   *
//*********************************
//Includes*************************
#include<iostream.h>
#include<lvp\string.h>
//*********************************
enum Color{red, blue, green, amber, violet};
enum Cut{diamond, marquis, oval, round, square};
//Gem******************************
Class Gem
{
 
 public:
  double height;
  double width;
  Color color;
  Cut cut;
  bool isCut (void);
  bool isPolished (void);
};
Gem bob;
//*********************************
 
//Main*****************************
int main()
{
 
 bob.height=5;
 bob.width=3;
 bob.color=blue;
 bob.cut=diamond;
 
 cout << "Here\'s some stuff about Bob\'s Gem: " << endl;
 cout << "The height: " << bob.height << endl;
 cout << "The width: " << bob.width << endl;
 cout << "The color: " << bob.color << endl;
 cout << "The cut: " << bob.cut << endl;
 return(0);
}
//*********************************
I don't know whether or not I'm doing this right, so if I'm not, please, let me know. I know to the compiler I'm not doing it right, because when I attempt to compile, I recieve 3 errors:

Code:
--------------------Configuration: oop - Win32 Debug--------------------
Compiling...
object.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\oop\object.cpp(17) : error C2146: syntax error : missing ';' before identifier 'Gem'
C:\Program Files\Microsoft Visual Studio\MyProjects\oop\object.cpp(17) : error C2501: 'Class' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\oop\object.cpp(17) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

object.obj - 3 error(s), 0 warning(s)
I'm in my first semester of C++, and we haven't covered OOP yet, and we won't cover pointers at all. If anyone has a good tutorial on pointers, I'd appreciate it. I would also appreciate it if someone could help me with my OOP woes.

I guess I seem like a C++ n00b, but we all have to start somewhere, I guess.
  
Reply With Quote