Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Error after compiling Employee.cpp with header files.

$
0
0
Hey guys, I have a problem getting this program to compile. Here are the instructions:

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.

Employee e1:

A Name n1: John W Smith

an Address A1: your own address

string ssn1: 987-65-4321

print employee e1.

Remember to drop the following files in the drop box:

Name.h
Address.h
Employee.h
Employee.cpp

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
Employee e1:
John W Smith
your own address
987-65-4321

My problem is that I cannot get the Employee e1 to print/display. I get the following error:
"cannot convert parameter 1 from 'NAME' to 'std::string' "

Here is my code:

Employee.cpp


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

// Implementation of the Employee class.
#include "Name.h"
#include "Address.h"
#include "Employee.h"

int main()
	{
		NAME n;
		ADDRESS A;
		EMPLOYEE e;
		
		NAME n1("John", "W", "Smith");
        ADDRESS A1("9300 Black Woods Dr", "Anytown", "TN", "01234");
        string ssn1("987-65-4321");

        EMPLOYEE e1(n1,A1,ssn1);
		

		cout << "Name: " << endl;	/** Display name. */
		n.prtName();
		cout << "Address: " << endl;	/** Display address. */
		A.prtAddress();
		cout << endl << "Employee: " << endl;	/** Display employee */
		e.prtEmployee();

		cout << endl << "Employee e1: " << endl; /** Displays Employee e1. */
		cout << "xxx-xx-xxxx" << endl;
		e1.prtEmployee();

	cin.get(); // Hold display.

}





Employee.h


#ifndef EMPLOYEE_H // Keeps header file from being defined more than once.
#define EMPLOYEE_H

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

class EMPLOYEE	// Create class.
{
private:
	ADDRESS adr;
	NAME nam;
	string SSN; // String variable Social Security Number.
public:
	EMPLOYEE()

		{
			NAME nam("John", "H.", "Doe");
			ADDRESS adr("99999 Sunset Boulevard", "Beverly Hills", "CA", "99999");
			SSN = "999-99-9999";
		}
		EMPLOYEE(string ssn, NAME &n, ADDRESS &A)
		{
			SSN = ssn;
			nam = n;
			adr = A;
		}

		~EMPLOYEE(){;}	// Destructor
		NAME getName(){return nam;}
		ADDRESS getAddress(){return adr;}
		string getSSN(){return SSN;}
		void prtEmployee(){
		nam.prtName();
		adr.prtAddress();
		cout << SSN << endl;
		}
		
};
#endif




Name.h


#ifndef NAME_H // Keeps header file from being defined more than once.
#define NAME_H

#include<iostream>
#include<iomanip>
#include<string>

using namespace std;

class NAME
{
private:	// Declare private members.
			string First;
			string Middle;
			string Last;
public:
	NAME() // Constructor
		{
			First = "John";
			Middle = "H.";
			Last = "Doe";
		}
		NAME(string Fn, string Mi, string Ln)
		{
			First = Fn;
			Middle = Mi;
			Last = Ln;
		}
		~NAME(){;}
		string getFirst() {return First;}	// Returns first name.
		string getMiddle() {return Middle;}	// Returns middle name.
		string getLast() {return Last;}		// Returnslast name. 
		void prtName()						
		{
		cout << First << ' ' << Middle << ' ' << Last << endl;	// Displays name.
		}

};
#endif




Address.h


#ifndef ADDRESS_H // Keeps header file from being defined more than once.
#define ADDRESS_H

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;


class ADDRESS

{

private:
				string Street;	// declare private members.
				string City;
				string State;
				string Zip ;
			
public:
	ADDRESS()	// Constructor
		{


			Street = "99999 Sunset Boulevard";
			City = "Beverly Hills";
			State = "CA";
			Zip = "99999";
		}

	ADDRESS(string St, string Ct, string st, string zip) // Address function.
		{
			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 prtAddress()
		{ 
		cout << Street << ' ' << City << ' ' << State << ' ' << Zip << endl; // Displays strret, city, state, and zip.
		}		
};
#endif



Viewing all articles
Browse latest Browse all 51036

Trending Articles