What am I not doing right? I won't build!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//Header file

#include <iostream>
#include <string> 
using namespace std;
using  std::string;

class Employee
{
public:
	Employee ( string, string, double ); //Constructor that takes all three
        
	Employee ( string, string ); // constructor that takes only two 
    
	void setEmpFName( string ); // function that set First name

	string getEmpFName(); // function that gets first name
     
	void setEmpLName ( string ); //function that set Last name

	string getEmpLName(); // function that gets Last name
 
	void setSalary ( double ); // set monthly salary

	double getSalary (); // get monthly salary
        
        double yearlyRaise(); // method to give raise
	
 

private:

	string fName;// Employee First name

	string lName;// Employee Last name

	double Msalary;// Employee Monthly salary
 
// Constructor

Employee::Employee( string Name1, string Name2, double Msalary ){

	setEmpFName(Name1);
	setEmpLname(Name2);
	setSalary(Msalary) 
   }

// Constructor

Employee::Employee ( string Name1, string Name2){

	setEmpFName(Name1);
	setEmpLname(Name2);
	setSalary();

  }

// Set Salary method

void Employee::setSalary( double Msalary ) {
	
	if ( salary < 0 )
	  {
		Msalary = 0;
		cout << "Monthly salary must be greater than 0. Monthly salary is 0." << endl;
	  }
	else {
		Msalary = Msalary;
	
	   } 
     }

//Set Empployee First Name

void setEmpFName ( string Name1){

     EmpFName = Name1;
}

//Set Employee Last Name

void setEmpLName ( string Name2){

    EmpLName = Name2;
 }

// Get Funtions

string Employee::getEmpFName(){
   
   	return EmpFName; 
  }


string Employee::getEmpLName(){
   
   	return EmpLName; 
  }


double Employee::getSalary(){

       return Msalary;

      }

// allows yearly raise

   double Employee::yearlyRaise(){

   Msalary = Msalary * 1.10;
   
   }
}




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// .Cpp file

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

#include <string>
using  std::string;


#include "Employee2.h"


int main(){
    
    //creates 2 new employee objects wit diff perameters
  
    Employee Employee1("Justin", "Gardner", 75000);
    Employee Employee2("Justina", "Gardner");

    //Displays Emp current info
     
    cout<< "Employee Number 1 Name and Current Salary:"<< Employee1.getEmpFName() << Employee1.getEmpLName() << 

Employee1.getSalary() << endl;

    cout<< "Employee Number 2 Name and Current Salary:"<< Employee2.getEmpFName() << Employee2.getEmpLName() << 

Employee2.getSalary() << endl;

    // 10 percent raise for both employees
    
    Employee1.yearlyRaise();
    Employee2.yearlyRaise();
    

    //Display new emp info

    cout<< "Employee Number 1 Name and Current Salary:"<< Employee1.getEmpFName() << Employee1.getEmpLName() << 

Employee1.getSalary() << endl;

    cout<< "Employee Number 2 Name and Current Salary:"<< Employee2.getEmpFName() << Employee2.getEmpLName() << 

Employee2.getSalary() << endl;
    

return 0;

}





When I try to build it in visual c++, this pops up:

1>------ Build started: Project: Homework1, Configuration: Debug Win32 ------
1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>C:\Users\Documents\Visual Studio 2010\Projects\Homework1\Debug\Homework1.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


This is what I get when I run it in the cmd prompt:

Employee2.h:41: `Employee::Employee(string, string, double)' is already defined
in class Employee
Employee2.h:50: `Employee::Employee(string, string)' is already defined in class
Employee
Employee2.h:60: `Employee::setSalary(double)' is already defined in class Employ
ee
Employee2.h:75: `Employee::setEmpFName(string)' is already defined in class Empl
oyee
Employee2.h:82: `Employee::setEmpLName(string)' is already defined in class Empl
oyee
Employee2.h:89: `Employee::getEmpFName()' is already defined in class Employee
Employee2.h:95: `Employee::getEmpLName()' is already defined in class Employee
Employee2.h:101: `Employee::getSalary()' is already defined in class Employee
Employee2.h:109: `Employee::yearlyRaise()' is already defined in class Employee
employee.cpp:15: semicolon missing after declaration of `Employee'
employee.cpp:15: extraneous `int' ignored
employee.cpp:15: semicolon missing after declaration of `class Employee'
You all the functions defined twice for some reason; a prototype inside the class body, then the implementation again inside the class body. You want to move the implementation into a separate source (cpp) file.
Oh my, look at this.

First up, all those Employee:: decorators are incorrect, since you're defining the functions within the body of the class definition. They have to go.

http://womble.decadent.org.uk/c++/syntax-errors.html

You are trying to use many variables that do not exist. For example, getEmpFName tries to return EmpFName, which does not exist. There are more like this.

You're missing a bunch of semi-colons. Put one at the end of your class definition, and also at the end of various other lines that are missing one.

All this:

1
2
3
4
5
Employee ( string, string, double ); //Constructor that takes all three
...        
...	
... 
double yearlyRaise(); // method to give raise 


Since you're defining the functions within the class body, you don't need them.

This
setSalary();
is tryig to call a function that does not exist. The setSalary function you defined takes a parameter.


This:
LINK : error LNK2001: unresolved external symbol _mainCRTStartup
indicates that you are trying to build a Win32 GUI type application. I'm guessing you're using Visual Studio. Make a new project and be sure to select just a plain console application.

Last edited on
Here's something that compiles. Compare it with the corresponding lines of your original code and you'll see where you went wrong.

Sticking using namespace std; at the top of a header file is very bad form, by the way, and is a habit you should try to rid yourself of at the earliest opportunity.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//Header file

#include <iostream>
#include <string> 
using namespace std;


class Employee
{

private:

  

	string EmpFName;// Employee First name

	string EmpLName;// Employee Last name

	double Msalary;// Employee Monthly salary
 

  public:        



// Set Salary method

void setSalary( double Msalary ) {
	
	if ( Msalary < 0 )
	  {
		Msalary = 0;
		cout << "Monthly salary must be greater than 0. Monthly salary is 0." << endl;
	  }
	else {
		Msalary = Msalary;
	
	   } 
};


//Set Empployee First Name

void setEmpFName ( string Name1){

     EmpFName = Name1;
};


//Set Employee Last Name

void setEmpLName ( string Name2){

    EmpLName = Name2;
};


// Get Funtions

string getEmpFName(){
   
   	return EmpFName; 
};



string getEmpLName(){
   
   	return EmpLName; 
};



double Employee::getSalary(){

       return Msalary;

};


// allows yearly raise

   double yearlyRaise(){

   Msalary = Msalary * 1.10;
   
   };

Employee( string Name1, string Name2, double Msalary ){

	setEmpFName(Name1);
	setEmpLName(Name2);
	setSalary(Msalary) ;
        
          };


// Constructor

Employee ( string Name1, string Name2){

	setEmpFName(Name1);
	setEmpLName(Name2);
	
};
   
};


Last edited on
Topic archived. No new replies allowed.