Completely Lost...

P

Phlip

bd said:
I am supposed to be writing a driver file, "Employee.cpp", that
somehow displays information from another file, "Employee.h".
"Employee.h" refers back to two other files, "Name.h" and
"Address.h".  I think these files are referred to as classes.

I sort of get the idea of what we are doing, but I get lost in the
vocabulary of what to call certain items and techniques.

Any brave souls willing to look at my code and help out?

No.

Your teacher has assumed a prerequisite has covered the difference between a
class and the .h file that some classes store in.

You must get down with more books than this course's tutorial, and you must
download online projects.

This newsgroup can't spoon-feed you all that stuff. We are always here to
help, but set the threshold above what should be in the first few chapters
of any programming tutorial!
 
B

bd

I am completely lost on the first assignment in my data structures
class. Last semester, my first C++ class was a piece of cake;
however, this year I am going to learn all about OOP.

My dilemma... this is an on-line class (as all of my classes have
been) and I am unable to just raise my hand and ask questions. I am
hoping that I won't get flamed too bad and some people on here will be
nice enough to help...

I am supposed to be writing a driver file, "Employee.cpp", that
somehow displays information from another file, "Employee.h".
"Employee.h" refers back to two other files, "Name.h" and
"Address.h". I think these files are referred to as classes.

I sort of get the idea of what we are doing, but I get lost in the
vocabulary of what to call certain items and techniques.

Any brave souls willing to look at my code and help out?
 
D

Dale

No.

Your teacher has assumed a prerequisite has covered the difference between a
class and the .h file that some classes store in.

You must get down with more books than this course's tutorial, and you must
download online projects.

This newsgroup can't spoon-feed you all that stuff. We are always here to
help, but set the threshold above what should be in the first few chapters
of any programming tutorial!

You have a good point, but I am not looking to get spoon-fed. I
realize now that I may have sounded that way. I am going to post my
Employee.h file. If anyone has any suggestions as to what I'm doing
wrong in the file, then I am certainly open to them.

+----------------------------------------------------------------------
+
#include <iostream>
#include <iomanip>
#include <string>
#include "Name.h"
#include "Address.h"

using namespace std;

class EMPLOYEE
{
private:
NAME empName;
ADDRESS empAddress;
string empSSN;

public:
//default constructor
EMPLOYEE()
{
empName("John","H.","Doe");
empAddress("99999 Sunset Boulevard" , "Beverly Hills", "CA",
"99999");
empSSN = "999-99-9999";
}

//non-default constructor
EMLOYEE(NAME nameDefault, ADDRESS addressDefault, string ssn)
{
empName = nameDefault.prtFullName();
empAddress = addressDefault.prtAddress();
empSSN = ssn;
}

~EMPLOYEE(){;}//destructor
NAME getName(){return empName;}
ADDRESS getAddress(){return empAddress;}
string getSSN(){return empSSN;}
void prtAll()
{
cout << empName.prtFullName() << ' ' << empAddress.prtAddress() << '
' << empSSN << endl;
}
}

+----------------------------------------------------------------------
+
 
G

Gianni Mariani

bd wrote:
....
Any brave souls willing to look at my code and help out?

Not really.

Your questions needs to be more specific.

BTW, there are plenty of open source projects that show how you can
split functionality across multiple header files (virtually every open
source C++ program will do it).

I refer to ".h" files as "header" files because they usually get
referred to by "#include" pre-processor directives at the head. .h
files define the "INTERFACE". Think of the interface as that which you
need to publish for other code to use elements implementing the
interface. You can put anything in a header file as long as it is not a
definition of something that will become defined multiple times so that
you will not be able to link your code.

One way to approach this is to write your code all in one file and then
re-arrange the interface components and split the file after you have
something working.
 
B

BobR

Dale wrote in message...
You have a good point, but I am not looking to get spoon-fed. I
realize now that I may have sounded that way. I am going to post my
Employee.h file. If anyone has any suggestions as to what I'm doing
wrong in the file, then I am certainly open to them.

+----------------------------------------------------------------------
+
#include <iostream>
#include <iomanip>
#include <string>
#include "Name.h"
#include "Address.h"

using namespace std;

A header file is the worst possible place to use that line. Remove it!
class EMPLOYEE

All-uppercase names are usually reserved for macros. It's not a C++ error,
just a style thing. (makes it easy to spot macros in code.)
{
private:

'private' is not required here. Ok to leave it (for documentation).
A 'class' defaults to private access.
NAME empName;
ADDRESS empAddress;
string empSSN;

public:
file://default constructor
EMPLOYEE()
{
empName("John","H.","Doe");
empAddress("99999 Sunset Boulevard" , "Beverly Hills", "CA",
"99999");
empSSN = "999-99-9999";
}

All that between the curly-braces should go into an 'initialization list',
not in the Ctor body.
file://non-default constructor
EMLOYEE(NAME nameDefault, ADDRESS addressDefault, string ssn)
{
empName = nameDefault.prtFullName();
empAddress = addressDefault.prtAddress();
empSSN = ssn;
}

All that should go into an 'initialization list', not in the Ctor body.
// > ~EMPLOYEE(){;}//destructor
~EMPLOYEE(){}//destructor // lose the semicolon.
NAME getName(){return empName;}
ADDRESS getAddress(){return empAddress;}
string getSSN(){return empSSN;}

All those get*() should be 'const'.

string getSSN() const { return empSSN; }
void prtAll()
{
cout << empName.prtFullName() << ' ' << empAddress.prtAddress() << '
' << empSSN << endl;
}
// > }
};

A semicolon is required at the end of class/struct/enum (and a few others
<G>).

Have you read the FAQ for this NG?
FAQ http://www.parashift.com/c++-faq-lite
It's a goldmine of information. At least read section 5.

Questions?
 
O

osmium

Dale said:
You have a good point, but I am not looking to get spoon-fed. I
realize now that I may have sounded that way. I am going to post my
Employee.h file. If anyone has any suggestions as to what I'm doing
wrong in the file, then I am certainly open to them.

+----------------------------------------------------------------------
+
#include <iostream>
#include <iomanip>
#include <string>
#include "Name.h"
#include "Address.h"

using namespace std;

class EMPLOYEE
{
private:
NAME empName;
ADDRESS empAddress;
string empSSN;

public:
//default constructor
EMPLOYEE()
{
empName("John","H.","Doe");
empAddress("99999 Sunset Boulevard" , "Beverly Hills", "CA",
"99999");
empSSN = "999-99-9999";
}

//non-default constructor
EMLOYEE(NAME nameDefault, ADDRESS addressDefault, string ssn)
{
empName = nameDefault.prtFullName();
empAddress = addressDefault.prtAddress();
empSSN = ssn;
}

~EMPLOYEE(){;}//destructor
NAME getName(){return empName;}
ADDRESS getAddress(){return empAddress;}
string getSSN(){return empSSN;}
void prtAll()
{
cout << empName.prtFullName() << ' ' << empAddress.prtAddress() << '
' << empSSN << endl;
}
}

Missing semi-colon. That's a killer mistake a lot of people make from time
to time. If you still have problems, repost the new code. It's not obvious
to me that that is your real unerlying problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top