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'