Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,648 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,120 people online right now. Registration is fast and FREE... Join Now!




Need Help Displaying Assignment

 
Reply to this topicStart new topic

Need Help Displaying Assignment

trying2compile
post 4 Sep, 2008 - 08:25 AM
Post #1


New D.I.C Head

*
Joined: 4 Sep, 2008
Posts: 12

cpp

// Employee.cpp : Defines the entry point for the console application.
// description: Employee
// programmer: Erin
// date: 09/03/2008#include <iostream>
using std::cout;
using std::endl;

class Employee
{

// data declaration section
private:
int ID; // declare ID as a integer variable
double RATE; // declare RATE as a double variable
int Employee1; // declare as obect


// methods declaration section
;public:
Employee(); // the constructor's declaration statement
void showEmployeeValues (); // this will be an accessor
void setNewEmployeeValues (int, double); // this will be a mutator
void displayEmployeeValues();
};

// methods implementaion section
Employee::Employee() // this is a constructor
{
ID = 99;
RATE = 99.99;
cout << "A new Employee object using the default constructor.\n;
}


void Employee::showEmployeeValues() // this is an accessor
{
cout << " ID = " << ID << "\n RATE = "<< RATE << endl;
}

void Employee::setNewEmployeeValues(int ID, double RATE) //this is a mutator
{
cout << Employee1.ID = 11 ;Employee1.double RATE = 11.11
cout << Employee2.ID = 22 ;Employee2.double RATE = 22.22
};

int main ()
{
Employee Employee1; // declare a variable of type Employee


cout << "The values for this Employee is: \n";
<< Employee1.showEmployeeValues (); // use a class method on this object
cout << "\nThe values for this Employee is: \n";
<< Employee2.showEmployeeValues (); // use another class method on this object

Employee1.setNewEmployeeValues (11,11.11); // call the mutator
Employee2.setNewEmployeeValues (22,22.22); // call the mutator


cout << "\nThe values for this Employee have been changed to:";
<< Employee1.showEmployeeValues();
<< "\nThe values of this Employee is: ";
<< Employee1.displayEmployeeValues();
<< Employee2.displayEmployeeValues()<< endl;

return 0;
}



This is my code but I am unable to compile without any errors.
My assignement was to :
1. The class requires two instance variables:
• An integer variable called ID to store the employee ID
• A double variable called RATE to store the employee hourly pay rate

2. The class requires a constructor that creates each employee object with the following default values:
• ID = 99
• RATE = 99.99

3. The class requires an Accessor method that returns the value stored in the ID instance variable.

4. The class requires an Accessor method that returns the value stored in the RATE instance variable.

5. The class requires a Mutator method that allows the user to set the value stored in the ID instance variable.

6. The class requires a Mutator method that allows the user to set the value stored in the RATE instance variable.

Part B: Create a main program to test the Employee class. The main program will do the following:

1A. Create an Employee object named Employee1.
1B. Create an Employee object named Employee2.

2A. Display the Employee1 value for ID
2B. Display the Employee1 value for RATE

3A. Display the Employee2 value for ID
3B. Display the Employee2 value for RATE

4A. Set the ID value for Employee1 to be 11
4B. Set the RATE value for Employee1 to be 11.11

5A. Set the ID value for Employee2 to be 22
5B. Set the RATE value for Employee2 to be 22.22

6A. Display the Employee1 value for ID
6B. Display the Employee1 value for RATE

7A. Display the Employee2 value for ID
7B. Display the Employee2 value for RATE

I honestly need help, I have tried everything to get this code to compile, and the program to display.
Appreciate all feedback.
Thanks


Mod Edit: Please use code tags when posting your code. Code tags are used like so => code.gif

Thanks,
PsychoCoder smile.gif
User is offlineProfile CardPM

Go to the top of the page

jjsaw5
post 4 Sep, 2008 - 08:53 AM
Post #2


I vill break you

Group Icon
Joined: 4 Jan, 2008
Posts: 1,364



Thanked 6 times

Dream Kudos: 125

Expert In: HTML, CSS, Database,

My Contributions


When posting code please make sure you are using the [code] tags!
User is offlineProfile CardPM

Go to the top of the page

JackOfAllTrades
post 4 Sep, 2008 - 09:05 AM
Post #3


D.I.C Addict

Group Icon
Joined: 23 Aug, 2008
Posts: 508



Thanked 45 times

Dream Kudos: 25
My Contributions


The compiler's errors will tell you what the problems are, but you failed to tell us. Here's what I get on Linux:

CODE

hw.cpp:32: error: missing terminating " character
hw.cpp: In constructor ‘Employee::Employee()’:
hw.cpp:33: error: expected primary-expression before ‘}’ token
hw.cpp:33: error: expected `;' before ‘}’ token


That is all because of this line:
cpp
cout << "A new Employee object using the default constructor.\n;

and the first error is the most important one there. You're missing an end quote.

Next,
CODE
hw.cpp:43: error: request for member ‘ID’ in ‘((Employee*)this)->Employee::Employee1’, which is of non-class type ‘int’
hw.cpp:43: error: expected unqualified-id before ‘double’
hw.cpp:43: error: expected `;' before ‘double’
hw.cpp:44: error: ‘Employee2’ was not declared in this scope
hw.cpp:44: error: expected unqualified-id before ‘double’
hw.cpp:44: error: expected `;' before ‘double’


The internals of your setNewEmployeeValues(int ID, double RATE) are all screwed up; you need to think about what you're trying to do in there.

Next,
CODE
hw.cpp: In function ‘int main()’:
hw.cpp:53: error: expected primary-expression before ‘<<’ token
hw.cpp:55: error: expected primary-expression before ‘<<’ token


You're doing output in Employee::showEmployeeValues(), and it doesn't return anything, so you shouldn't be trying to send it to cout (doing this in a couple of places):
cpp
cout << "The values for this Employee is: \n";
<< Employee1.showEmployeeValues(); // use a class method on this object


Finally,
CODE
hw.cpp:55: error: ‘Employee2’ was not declared in this scope

You never created an Employee2 instance of the Employee class.



User is offlineProfile CardPM

Go to the top of the page

trying2compile
post 4 Sep, 2008 - 09:25 AM
Post #4


New D.I.C Head

*
Joined: 4 Sep, 2008
Posts: 12

Sorry about that. I am new to this. Just need a lot of help.
I have the following compiler errors:

Compiling...
Employee.cpp
(32) : error C2001: newline in constant
(33) : error C2143: syntax error : missing ';' before '}'
(43) : error C2228: left of '.ID' must have class/struct/union type
type is 'int'
(43) : error C2061: syntax error : identifier 'RATE'
(44) : error C2228: left of '.Employee2' must have class/struct/union type
type is 'int'
(44) : error C2061: syntax error : identifier 'RATE'
(49) : fatal error C1903: unable to recover from previous error(s); stopping compilation

Build log was saved at "file://c:\Documents and Settings\-EDB79AF6\My Documents\Visual Studio Projects\Employee\Debug\BuildLog.htm"
Employee - 7 error(s), 0 warning(s)


---------------------- Done ----------------------

Build: 0 succeeded, 1 failed, 0 skipped

User is offlineProfile CardPM

Go to the top of the page

sensui
post 4 Sep, 2008 - 10:29 AM
Post #5


D.I.C Head

Group Icon
Joined: 24 Aug, 2008
Posts: 132



Thanked 20 times

Dream Kudos: 50
My Contributions


I will help you but not with the entire program ( you must put the code for getID(), getRate(), setID() and setRate(), it's easy, you must add only one instruction --> you must figure out which one ).

OK, here is the code:
cpp

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

class Employee {
private:
int ID;
double RATE;

public:
Employee();
int getID();
double getRate();
void setID( int number );
void setRate( double number );
};

Employee::Employee() {
ID = 99;
RATE = 99.99;
//you missed a " here
cout << "A new Employee object using the default constructor.\n";
}

int Employee::getID() {
//your code goes here
}

double Employee::getRate() {
//your code goes here
}

void Employee::setID( int number ) {
//your code goes here
}

void Employee::setRate( double number ) {
//your code goes here
}

int main () {
Employee employee1;

cout << "The values for this Employee are: " << endl
<< "ID: " << employee1.getID() << endl
<< "Rate: " << employee1.getRate();

employee1.setID( 11 );
employee1.setRate( 11.11 );

cout << "\nThe values for this Employee have been changed to: " << endl
<< "ID: " << employee1.getID() << endl
<< "Rate: " << employee1.getRate();

cin.get();
return EXIT_SUCCESS;
}


I can't help you more then that. As I said, you must figure what instruction to put in place of "//your code goes here".

I hope that this will help you!
User is offlineProfile CardPM

Go to the top of the page

trying2compile
post 4 Sep, 2008 - 10:43 AM
Post #6


New D.I.C Head

*
Joined: 4 Sep, 2008
Posts: 12

Thank You All So much!!!!
I compiled with no errors!!!!!
Sensui, you are the Best! I figured it out. I understand everything now. smile.gif icon_up.gif
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 05:04AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month