This is the assignment:
Write a class named Employee that has the following member variables:

name. A string that holds the employee’s name.
idNumber. An int variable that holds the employee’s ID number.
department. A string that holds the name of the department where the employee works.
position. A string that holds the employee’s job title.

The class should have the following constructors:

A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee’s name, employee’s ID number, department, and position.
A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee’s name and ID number. The department and position fields should be assigned an empty string (“ “);
A default constructor that assigns empty strings (“ “) to the name, department, and position member variables, and 0 to the idNumber member variable.

Write appropriate mutator functions that store values in these member variables and accessor functions that return the values in these member variables. Once you have written the class, create a three Employee objects (3 separate instances), in your main function, to hold the following data

#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <iomanip>
#include <string>
using namespace std;

class Employee
{
	string name;
	int idnumber;
	string department;
	string position;

public:
	Employee()
	{
		name=" ";
		idnumber=0;
		department=" ";
		position=" ";
	}

	void setname(string NAME)
	{
		NAME=name;
	}
	void setidnunmber (int ID)
	{
		ID=idnumber;
	}
	void setdepartment (string DEPARTMENT)
	{
		DEPARTMENT=department;
	}
	void setposition (string POSITION)
	{
		POSITION=position;
	}

	string getname()
	{
		return (name);
	}
	int getidnumber()
	{
		return(idnumber);
	}
	string getdepartment()
	{
		return(department);
	}
	string getposition()
	{
		return (position);
	}

	void show_record();
};
void Employee::show_record()
{
	cout << "Name " << getname()<<endl;
	cout << "ID " << getidnumber()<<endl;
	cout << "Department" << getdepartment()<<endl;
	cout << "Posistion" << getposition()<<endl;
}

int main()
{
	const int SIZE=3;
	Employee employee[SIZE];
	
	string NAME;
	int ID;
	string DEPARTMENT;
	string POSITION;
	

	for (int i=0; i<SIZE;i++)
	{
		cout << "Enter the Employee name : " << endl;
		cin>>NAME;
		employee[i].setname(NAME);
		
		cout << "Enter the Employees ID: " << endl; 
		cin >> ID;
		employee[i].setidnunmber(ID);
		
		cout << "Enter the Employees Department: " << endl;
		cin>>DEPARTMENT;
		employee[i].setdepartment(DEPARTMENT);
		
		cout << "Enter the Employees Posistion: " << endl;
		cin>>POSITION;
		employee[i].setposition(POSITION);
	}

	
for (int i=0;i<SIZE;i++)
employee[i].show_record();

system ("pause");
return 0;
}

What happens is when I try to print the data it just gives me blanks.. I could use some help please.

Thank you!

DeftArcher

I am having the same issue with my parking ticket program:

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
using namespace std;

int x=0; 
int Y[10];
int min;
class parkedcar

{
	string makeofcar;
	string modelofcar;
	string color;
	string licenseplate;
	int minutesparked;

public:
	parkedcar()
	{
		makeofcar=" ";
		modelofcar=" ";
		color=" ";
		licenseplate=" ";
		minutesparked=0;
	}

	void setmake(string make)
	{
		makeofcar=make;
	}

	void setmodel (string model)
		{
			modelofcar=model;
	}

	void setcolor (string col)
	{
		color=col;
	}
	
	void setlicenseplate (string license)
	{
		licenseplate=license;
	}

	void setminutesparked (int minp)
	{
		minutesparked=minp;
	}

	string getmake()
	{
		return (makeofcar);
	}

	string getmodel()
	{
		return (modelofcar);
	}

	string getcolor()
	{
		return (color);
	}

	string getlicenseplate()
	{
		return (licenseplate);
	}

	int getminutesparked()
	{
		return (minutesparked);
	}

	void print();
};
void parkedcar::print()
{
	cout << "Car Make" << getmake()<<endl;
	cout << "Car Model" << getmodel()<<endl;
	cout << "Get License Plate Number" << getlicenseplate()<<endl;
	cout << "Car Color" << getcolor()<<endl;

}


	class ticket: public parkedcar
	{
		int fine;
		int minutes;
		void calculatefine();
		 
	public:
		void showfine();
		void getticket(int mins)
		{
			minutes=mins;
			calculatefine();
			cout<<endl;
		}

		void setmin(int min)
		{
			minutes=min;

		}
		 int getfine()
		 {
			 return(fine);
		 }
	};

	void ticket::calculatefine()
	{
		if (minutes/60<=0)
		{
			fine=25;
		}
		else
		{
			int mn;
			mn=minutes-60;
			fine= 25+10+10*(mn/60);
		}
	}

	void ticket::showfine()
		
	{
		cout << "This car is over it's time limit by " <<setprecision(2)<< minutes/60 << "hours and "<<setprecision(2) << minutes%60<< "minutes" <<endl;
		cout << "Fine $: "<<setprecision(2) << fine << endl;
	}

	class parkingmeter
	{
		int minpurchased;

	public:
		parkingmeter()
		{
			minpurchased=0;

		}

		void setminpurchased(int minsPur)
		{
			minpurchased=minsPur;
		}

		int getminpurchased()
		{
			return(minpurchased);
		}

		void print()

		{
			cout << "Minutes Purchased are " << getminpurchased();
		}
	};

	class policeofficer
	{
		string name;
		string badge;
		ticket *Pticket;
	public:
		policeofficer()
		{
			name=" ";
			badge=" ";
			Pticket=NULL;
		}

		void setname(string n)
		{
			name=n;
		}

		void setbadgenumber(string b)
		{
			badge=b;
		}

		string getname()
		{
			return(name);
		}

		string getbadgenumber()
		{
			return (badge);
		}

		ticket* patrol(ticket pc1, parkingmeter pc2)
		{
if ( pc1.getminutesparked() < pc2.getminpurchased() ||
pc1.getminutesparked()==pc2.getminpurchased() )
{
		return NULL;	}

			else
			{
				ticket t1[10];
				t1[x].getticket(pc1.getminutesparked() - pc2.getminpurchased());
				t1[x].showfine();
				Pticket=&t1[x];
				return(Pticket);
			}
		}

		void print()
		{
			cout << "Name: " << name << endl;
			cout << "Badge Number: " << badge << endl;
		}
	};


	int main()
	{
		int c;
		int i=0;
		int j=0;

	policeofficer officer;
	string pname;
	string pbadge;

	cout << "Officers Information" << endl;
	cout << "Name:";
	getline(cin, pname);
	cout << "Badge Number:";
	cin >> pbadge;

	officer.setname(pname);
	officer.setbadgenumber(pbadge);

	ticket tck[10];

	parkingmeter meter[10];

	do
	{
		ticket* pticket = NULL;

		while (x<=j)
		{
			string make;
			string model;
			string license;
			string color;
			int minparked;
			int timeallowed;


			cout << "Please enter the following information" << endl;
			cout << "Make of the vehicle : " ;
		    cin >> make;
			tck[x].setmake(make);
			cout << "Model";
			cin >> model;
			tck[x].setmodel(model);
			cout << "License number:";
			cin>>license;
			tck[x].setlicenseplate(license);
			cout<< "Color";
			cin>>color;
			tck[x].setcolor(color);
			cout << "Minutes parked";
			cin >> minparked;
			tck[x].setminutesparked(minparked);

			cout << "Time Allowed";
			cin >> timeallowed;
			meter[x].setminpurchased(timeallowed);

		pticket=officer.patrol(tck[x],meter[x]);

		if (pticket==NULL)
		{
			tck[x].print();
			cout << "Nothing to see here move along" << endl;
		}

		else
	
		{
			cout << "This vehicle is illegally parked!!!!!" << endl;
			tck[x].print();
			pticket=NULL;
		}

		Y[x]=tck[x].getminutesparked()-meter[x].getminpurchased();
		x++;
		}


cout<<"Enter your choice -"<<endl;
cout<<"0 - Patrol another car"<<endl<<"1 - View cars patrolled"<<endl<<"2 - Exit"<<endl;
cin>>c;
if(c==0)
{
j++;
}
else if(c==1)
{
tck[x].showfine();
tck[x].print();
cout<<"Officer responsible for issuing these tickets and patroling ::"<<endl;
officer.print();
}
else
{
exit(0);
}
}while (c == 0);


system ("pause");

return 0;
}

Help PLEASE!

Recommended Answers

All 3 Replies

This is the assignment:
Write a class named Employee that has the following member variables:

name. A string that holds the employee’s name.
idNumber. An int variable that holds the employee’s ID number.
department. A string that holds the name of the department where the employee works.
position. A string that holds the employee’s job title.

The class should have the following constructors:

A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee’s name, employee’s ID number, department, and position.
A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee’s name and ID number. The department and position fields should be assigned an empty string (“ “);
A default constructor that assigns empty strings (“ “) to the name, department, and position member variables, and 0 to the idNumber member variable.

Write appropriate mutator functions that store values in these member variables and accessor functions that return the values in these member variables. Once you have written the class, create a three Employee objects (3 separate instances), in your main function, to hold the following data

#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <iomanip>
#include <string>
using namespace std;

class Employee
{
	string name;
	int idnumber;
	string department;
	string position;

public:
	Employee()
	{
		name=" ";
		idnumber=0;
		department=" ";
		position=" ";
	}

	void setname(string NAME)
	{
		NAME=name;
	}
	void setidnunmber (int ID)
	{
		ID=idnumber;
	}
	void setdepartment (string DEPARTMENT)
	{
		DEPARTMENT=department;
	}
	void setposition (string POSITION)
	{
		POSITION=position;
	}

	string getname()
	{
		return (name);
	}
	int getidnumber()
	{
		return(idnumber);
	}
	string getdepartment()
	{
		return(department);
	}
	string getposition()
	{
		return (position);
	}

	void show_record();
};
void Employee::show_record()
{
	cout << "Name " << getname()<<endl;
	cout << "ID " << getidnumber()<<endl;
	cout << "Department" << getdepartment()<<endl;
	cout << "Posistion" << getposition()<<endl;
}

int main()
{
	const int SIZE=3;
	Employee employee[SIZE];
	
	string NAME;
	int ID;
	string DEPARTMENT;
	string POSITION;
	

	for (int i=0; i<SIZE;i++)
	{
		cout << "Enter the Employee name : " << endl;
		cin>>NAME;
		employee[i].setname(NAME);
		
		cout << "Enter the Employees ID: " << endl; 
		cin >> ID;
		employee[i].setidnunmber(ID);
		
		cout << "Enter the Employees Department: " << endl;
		cin>>DEPARTMENT;
		employee[i].setdepartment(DEPARTMENT);
		
		cout << "Enter the Employees Posistion: " << endl;
		cin>>POSITION;
		employee[i].setposition(POSITION);
	}

	
for (int i=0;i<SIZE;i++)
employee[i].show_record();

system ("pause");
return 0;
}

What happens is when I try to print the data it just gives me blanks.. I could use some help please.

Thank you!

DeftArcher

I am having the same issue with my parking ticket program:

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
using namespace std;

int x=0; 
int Y[10];
int min;
class parkedcar

{
	string makeofcar;
	string modelofcar;
	string color;
	string licenseplate;
	int minutesparked;

public:
	parkedcar()
	{
		makeofcar=" ";
		modelofcar=" ";
		color=" ";
		licenseplate=" ";
		minutesparked=0;
	}

	void setmake(string make)
	{
		makeofcar=make;
	}

	void setmodel (string model)
		{
			modelofcar=model;
	}

	void setcolor (string col)
	{
		color=col;
	}
	
	void setlicenseplate (string license)
	{
		licenseplate=license;
	}

	void setminutesparked (int minp)
	{
		minutesparked=minp;
	}

	string getmake()
	{
		return (makeofcar);
	}

	string getmodel()
	{
		return (modelofcar);
	}

	string getcolor()
	{
		return (color);
	}

	string getlicenseplate()
	{
		return (licenseplate);
	}

	int getminutesparked()
	{
		return (minutesparked);
	}

	void print();
};
void parkedcar::print()
{
	cout << "Car Make" << getmake()<<endl;
	cout << "Car Model" << getmodel()<<endl;
	cout << "Get License Plate Number" << getlicenseplate()<<endl;
	cout << "Car Color" << getcolor()<<endl;

}


	class ticket: public parkedcar
	{
		int fine;
		int minutes;
		void calculatefine();
		 
	public:
		void showfine();
		void getticket(int mins)
		{
			minutes=mins;
			calculatefine();
			cout<<endl;
		}

		void setmin(int min)
		{
			minutes=min;

		}
		 int getfine()
		 {
			 return(fine);
		 }
	};

	void ticket::calculatefine()
	{
		if (minutes/60<=0)
		{
			fine=25;
		}
		else
		{
			int mn;
			mn=minutes-60;
			fine= 25+10+10*(mn/60);
		}
	}

	void ticket::showfine()
		
	{
		cout << "This car is over it's time limit by " <<setprecision(2)<< minutes/60 << "hours and "<<setprecision(2) << minutes%60<< "minutes" <<endl;
		cout << "Fine $: "<<setprecision(2) << fine << endl;
	}

	class parkingmeter
	{
		int minpurchased;

	public:
		parkingmeter()
		{
			minpurchased=0;

		}

		void setminpurchased(int minsPur)
		{
			minpurchased=minsPur;
		}

		int getminpurchased()
		{
			return(minpurchased);
		}

		void print()

		{
			cout << "Minutes Purchased are " << getminpurchased();
		}
	};

	class policeofficer
	{
		string name;
		string badge;
		ticket *Pticket;
	public:
		policeofficer()
		{
			name=" ";
			badge=" ";
			Pticket=NULL;
		}

		void setname(string n)
		{
			name=n;
		}

		void setbadgenumber(string b)
		{
			badge=b;
		}

		string getname()
		{
			return(name);
		}

		string getbadgenumber()
		{
			return (badge);
		}

		ticket* patrol(ticket pc1, parkingmeter pc2)
		{
if ( pc1.getminutesparked() < pc2.getminpurchased() ||
pc1.getminutesparked()==pc2.getminpurchased() )
{
		return NULL;	}

			else
			{
				ticket t1[10];
				t1[x].getticket(pc1.getminutesparked() - pc2.getminpurchased());
				t1[x].showfine();
				Pticket=&t1[x];
				return(Pticket);
			}
		}

		void print()
		{
			cout << "Name: " << name << endl;
			cout << "Badge Number: " << badge << endl;
		}
	};


	int main()
	{
		int c;
		int i=0;
		int j=0;

	policeofficer officer;
	string pname;
	string pbadge;

	cout << "Officers Information" << endl;
	cout << "Name:";
	getline(cin, pname);
	cout << "Badge Number:";
	cin >> pbadge;

	officer.setname(pname);
	officer.setbadgenumber(pbadge);

	ticket tck[10];

	parkingmeter meter[10];

	do
	{
		ticket* pticket = NULL;

		while (x<=j)
		{
			string make;
			string model;
			string license;
			string color;
			int minparked;
			int timeallowed;


			cout << "Please enter the following information" << endl;
			cout << "Make of the vehicle : " ;
		    cin >> make;
			tck[x].setmake(make);
			cout << "Model";
			cin >> model;
			tck[x].setmodel(model);
			cout << "License number:";
			cin>>license;
			tck[x].setlicenseplate(license);
			cout<< "Color";
			cin>>color;
			tck[x].setcolor(color);
			cout << "Minutes parked";
			cin >> minparked;
			tck[x].setminutesparked(minparked);

			cout << "Time Allowed";
			cin >> timeallowed;
			meter[x].setminpurchased(timeallowed);

		pticket=officer.patrol(tck[x],meter[x]);

		if (pticket==NULL)
		{
			tck[x].print();
			cout << "Nothing to see here move along" << endl;
		}

		else
	
		{
			cout << "This vehicle is illegally parked!!!!!" << endl;
			tck[x].print();
			pticket=NULL;
		}

		Y[x]=tck[x].getminutesparked()-meter[x].getminpurchased();
		x++;
		}


cout<<"Enter your choice -"<<endl;
cout<<"0 - Patrol another car"<<endl<<"1 - View cars patrolled"<<endl<<"2 - Exit"<<endl;
cin>>c;
if(c==0)
{
j++;
}
else if(c==1)
{
tck[x].showfine();
tck[x].print();
cout<<"Officer responsible for issuing these tickets and patroling ::"<<endl;
officer.print();
}
else
{
exit(0);
}
}while (c == 0);


system ("pause");

return 0;
}

Help PLEASE!

Hey. You have some of your assignments in your setters reversed.

void setidnunmber (int ID) {ID=idnumber;}

should be

void setidnunmber (int ID) {idnumber=ID;}

And you've done this with the other functions in your Employee class. As for the same problem in your other classes--you didn't make the same mistake there, and nothing really jumped out at me since you have a fair bit of code there and not sure where to start looking. Can you narrow down the problem with your other classes? Which values can you print and which are blank? Which classes?

I figured the Employee thing out. I can't believe it was such a simple mistake I feel like a tard.

As far as the Parking ticket goes. When I hit review tickets it displays crazy numbers.. such as -512894792375987, and then doesn't show the car model ect.

I figured the Employee thing out. I can't believe it was such a simple mistake I feel like a tard.

As far as the Parking ticket goes. When I hit review tickets it displays crazy numbers.. such as -512894792375987, and then doesn't show the car model ect.

There's a few weird things going on in your code. You have this global int x = 0. And then later on in one of your classes you have:

else			
{				
ticket t1[10];				
t1[x].getticket(pc1.getminutesparked() - pc2.getminpurchased());
t1[x].showfine();				
Pticket=&t1[x];				
return(Pticket);			
}

My question is, why do you need an array of 10 tickets if you only access ticket[0] using your global variable "x"? As for global variables, it is written in the nerd commandments not to use global variables unless absolutely necessary. Find a way to incorporate this variable into one of your classes or eliminate it entirely. This code also won't work properly since anything declared locally (i.e. the array t1[10]) will be deallocated once the function ends. So, Pticket and also the return value are pointing to an address that once held t1[0] but since the memory is free for use, it was probably replaced by some random part of your code/variables. In order to avoid this, you have to declare a ticket using "new", and then return that. I'm going to go back to drinking. Hopefully this helps some I'll check back tomorrow to see.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.