I have a program that I can't get to compile. I have problem with Employee.cpp but I can't figure out how to fix it.
Here are the requirements for the program.
Create a C++ class called Employee which will implement the Employee constructor. Remember that once the Name of the Employee is entered and the Address of the Employee is entered, once you add an SSN you are ready to create an employee.
Here what the Name Header file (Name.h) will have:
1- a default constructor
2- 3 private string instance variables for :First Name, Middle Name, and a last Name
3- getFirstLast function: it returns the first and middle name and last name in order
4- print function: it prints the first, middle, and last name.
Here what the Address Header File (Address.h) will have:
1- a default constructor
2- 4 private string instance variables for :Street, City, State, Zip
3- getCity: it returns the City
4- getState: It returns the State
5- getStreet: It returns the street
6- getZip: it returns the zip
7- print function: it prints the Street, City, State, and Zip.
Here what the Employee Header File (Employee.h) will have:
1- 3 private instance variables: One for Name (Use the Header Name from above), One for The Address
(Use the Address Header from above), a string variable for the SSN.
2- a default constructor which initializes the SSN to "999-99-9999", Name to "John H. Doe", Address to
"99999 Sunset Boulevard" , "Beverly Hills", "CA", "99999"
3- a constructor with 3 parameters
4- getName function: it returns the Name of the Employee
5- getAddress function : it returns the address of the Employee.
6- getSSN function: it returns the SSN as a string
7- print function: Prints the name, prints the Address, prints the SSN.
Implement the Employee class using the constructor as an external function:
1- Remember that the default constructor for Employee has the following initial values:
SSN to "999-99-9999", Name to "John H. Doe", Address to "99999 Sunset Boulevard" ,
Beverly Hills, CA, 99999
2- Remember that the default constructor for Address has the following initial values:
Address to "99999 Sunset Boulevard" , "Beverly Hills", "CA", "99999"
3- Remember that the default constructor for Name has the following initial values:
Name to "John H. Doe",
In the void main() function you would declare:
a Name n;
an Address A;
and an Employee e;
and print the values of each.
Remember to compile the Employee.cpp file and execute it to verify the output:
Name:
John H. Doe
Address:
9999 Sunset Boulevard" , Beverly Hills, CA, 99999 (Address)
Employee:
John H. Doe
99999 Sunset Boulevard" , Beverly Hills, CA, 99999
xxx-xx-xxxx
Here are the errors I am getting:
1>c:\users\eric\documents\visual studio 2010\projects\employee\employee\employee.cpp(19): error C2065: 'SSN' : undeclared identifier
1>c:\users\eric\documents\visual studio 2010\projects\employee\employee\employee.cpp(19): error C2146: syntax error : missing ';' before identifier 'ssn'
1>c:\users\eric\documents\visual studio 2010\projects\employee\employee\employee.cpp(19): error C2065: 'ssn' : undeclared identifier
1>c:\users\eric\documents\visual studio 2010\projects\employee\employee\employee.cpp(29): error C2065: 'ssn' : undeclared identifier
1>c:\users\eric\documents\visual studio 2010\projects\employee\employee\employee.cpp(30): error C2065: 'ssn' : undeclared identifier
Any help is appreciated.
Here is the code for my program.
Employee.cpp
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
|
#include "StdAfx.h"
#include "Name.h"
#include "Address.h"
#include "Employee.h"
using namespace std;
//entry point of program
void main()
{
//create Name, Address, and Employee object
Name n;
Address A;
Employee e;
SSN ssn;
//print out defaults of an employee object
e.prtEmployee();
Name n1 ("George", "Victor", "Meghabghab");
Address a1 ("3709 Hoch Court", "Murfreesboro", "TN", "37128");
ssn = "987-65-4321";
Employee e1 (ssn,n1, a1);
e1.prtEmployee();
cin.get();
}
|
Employee.h
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
|
#ifndef Employee_H
#define Employee_H
#include <iostream>
#include <iomanip>
#include <string>
#include "Address.h"
#include "Name.h"
using namespace std;
class Employee
{
private:
Address A;
Name n;
string SSN; // string variable for Social Security Number
public:
Employee()
{
Name n("John", "H.", "Doe");
Address A("99999 Sunset Boulevard", "Beverly Hills", "CA", "99999");
SSN = "999-99-9999";
}
Employee(Name &n1, Address &a1, string ssn)
{
SSN = ssn;
n = n1;
A = a1;
}
~Employee(){;} // destructor
Name getName()
{
return n;
}
Address getAddress()
{
return A;
}
string getSSN()
{
return SSN;
}
void prtEmployee()
{
n.printName();
A.printAddress();
cout << SSN << endl;
}
};
#endif;
|
Address.h
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
|
#ifndef Address_H
#define Address_H
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Address
{
private:
string Street;
string City;
string State;
string Zip ;
public:
Address()
{
Street = "99999 Sunset Boulevard";
City = "Beverly Hills";
State = "CA";
Zip = "99999";
}
Address(string St, string Ct, string st, string zip)
{
Street = St;
City = Ct;
State = st;
Zip = zip;
}
~Address(){;} //destructor
string getCity(){return City;}
string getState(){return State;}
string getStreet(){return Street;}
string getZip(){return Zip;}
void printAddress()
{
cout << City << ' '<< State << ' ' << Street << ' ' << Zip << endl;
}
};
#endif
|
Name.h
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
|
#ifndef Name_H
#define Name_H
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
class Name
{
private:
string First;
string Middle;
string Last;
public:
Name() // Default constructor
{
First = "John";
Middle = "H.";
Last = "Doe";
}
Name(string Fi, string Mi, string La)
{
First = Fi;
Middle = Mi;
Last = La;
}
~Name(){;}
string getFirst() // returns First name
{
return First;
}
string getMiddle() // return Middle name
{
return Middle;
}
string getLast() // returns Last name
{
return Last;
}
void printName() // prints full name
{
cout << First << " " << Middle << " " << Last << endl;
}
};
#endif
|