Why is my variable undefined

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 955 Views - Last Post: 11 January 2013 - 11:11 AM Rate Topic: -----

#1 llwilkins  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 06-November 12

Why is my variable undefined

Posted 10 January 2013 - 10:43 AM

I am trying to put together a program and would love someone to tell me why it is saying that my variables in my methods are undefined when they are defined in the class. The ones that are giving me errors are the one in my Administrator class that are "Set" methods.


//Lynette Wilkins
//Week 12

#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;

class SalariedEmployee
{
private:
	double wageRate;
	int hours;
protected:
	string name;
	string ssn;
	double netPay;
	string department;

public:
	SalariedEmployee(string n, string s, double np, double w, int h, string d);
	 ~SalariedEmployee() {cout<<endl;}
	 string Getname();  //returns name
	 string Getssn();   // returns social security number
	 double GetnetPay(); //returns netPay
	 string Getdepartment(); // returns department
	 double GetwageRate(); //returns wage rate
	 int Gethours(); //returns hours
	 string Setname(string); //sets name
	 string Setssn(string); //sets ssn
	 double SetnetPay(double); //sets net pay
	 string Setdepartment(string); //sets department
	 double SetwageRate(double); //sets wage rate
	 int Sethours(int); //sets hours
	
};


string SalariedEmployee::Getname()
{
	return name;
}

string SalariedEmployee::Getssn()
{
	return ssn;
}

double SalariedEmployee::GetnetPay()
{
	return netPay;
}

double SalariedEmployee::GetwageRate()
{
	return wageRate;
}

int SalariedEmployee::Gethours()
{
	return hours;
}

string SalariedEmployee::Setname(string n)
{
	name = n;
}

string SalariedEmployee::Setssn(string s)
{
	ssn = s;
}

double SalariedEmployee::SetnetPay(double np)
{
	netPay = np;
}

string SalariedEmployee::Setdepartment(string d)
{
	department = d;
}


double SalariedEmployee::SetwageRate(double w)
{
	wageRate = w;
}

int SalariedEmployee::Sethours(int h)
{
	hours = h;
}


class Administrator : public SalariedEmployee
{
protected:
	string title;
	string responsi;
	string super;
	double salary;
public:
	Administrator(string t, string r, string s, double sa);
	 ~Administrator();
	string Gettitle();
	string Getresponsi();
	string Getsuper();
	double Getsalary();
	string Settitle(string);
	string Setresponsi(string);
	string Setsuper(string);
	double Setsalary(double);
	void print();
};

Administrator::~Administrator()
{
	cout<<endl;
}

string Administrator::Gettitle()
{
	return title;
}

string Administrator::Getresponsi()
{
	return responsi;
}

string Administrator::Getsuper()
{
	return super;
}

double Administrator::Getsalary()
{
	return salary;
}
string Settitle(string ti)
{
	title = ti;
}
string Setresponsi(string re)
{
	responsi = re;
}


string Setsuper(string su)
{
	super=su;
}

double Setsalary(double sa)
{
	salary= sa;
}

void print( )
  {
    
    cout<<"print"<<endl;
  }



int main()
{

	
	string name;
    string soc;
	double net;
	double wage;
	int hrs;
	string dept;
	string admtitle;
	string resp;
	string sup;
	double sal;
	int response;
	string date = "January 12, 2013";

	
	cout<<setprecision(2)
    <<setiosflags(ios::fixed)
    <<setiosflags(ios::showpoint);

SalariedEmployee emp1(name, soc, net, wage, hrs, dept);
Administrator adm1(admtitle, resp, sup, sal);

	cout<<"Employee and Administrator Salary Program "<<endl;
	cout<<"(You will have to enter data first before you do anything else)"<<endl<<endl;
	cout<<"Enter Employee Data,    Enter 1"<<endl;
	cout<<"Change data,   Enter 2"<<endl;
	cout<<"Print Check,   Enter 3"<<endl<<endl;
	cout<<"Please make your selection"<<endl;

	
int response;
cin>> response;
cin.getline;

	switch (response)
	{
	case 1:
		cout <<"The employee's data will be entered here: "<<endl<<endl;
		cout<<"Enter the employees name: "<<endl;
		getline(cin, name);

		cout<<"Enter the employees social security number: "<<endl;
		getline(cin, soc);

		cout<<"Enter the employees net pay: "<<endl;
		cin>>net;

		cout<<"Enter the employees wage rate: "<<endl;
		cin>>wage;

		cout<<"Enter the number of hours the employer worked: "<<endl;
		cin>>hrs;
	
		cout<<"Enter the employees title: "<<endl;
		getline(cin, admtitle);

		cout<<"Enter the employees area responsibility: "<<endl;
		getline(cin, resp);

		cout<<"Enter the employees salary: "<<endl;
		cin>>sal<<endl<<endl<<endl;

		

		cout<<"Change data,   Enter 2"<<endl;
	    cout<<"Print Check,   Enter 3"<<endl<<endl;
	    cout<<"Please make your selection"<<endl;

		int response;
        cin>> response;
        cin.getline;

		break;

	case 2:

		cout<<"Please change the data you entered previously here. " <<endl<<endl;

		cout<<"Enter the employees name: "<<endl;
		getline(cin, name);

		cout<<"Enter the employees social security number: "<<endl;
		getline(cin, soc);

		cout<<"Enter the employees net pay: "<<endl;
		cin>>net;

		cout<<"Enter the employees wage rate: "<<endl;
		cin>>wage;

		cout<<"Enter the number of hours the employer worked: "<<endl;
		cin>>hrs;
	
		cout<<"Enter the employees title: "<<endl;
		getline(cin, admtitle);

		cout<<"Enter the employees area responsibility: "<<endl;
		getline(cin, resp);

		cout<<"Enter the employees salary: "<<endl;
		cin>>sal<<endl<<endl<<endl;


			
	    cout<<"Print Check,   Enter 3"<<endl<<endl;
	    cout<<"Please make your selection"<<endl;

		int response;
        cin>> response;
        cin.getline;

		break;

				
	case 3:

		cout <<"Informatin Printed"<<endl<<endl;

		adm1.print;



		break;


	default:

		cout<<endl<<endl
			<<"Invalid Selection! Try Again"<<endl;
		exit(1);
		
}

		




	system("PAUSE");
	return 0;
}




Nevermind I figured it out.

I had to actually chang it to

string Administrator::Settitle(string ti)
{
	title = ti;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Why is my variable undefined

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4337
  • View blog
  • Posts: 12,137
  • Joined: 18-April 07

Re: Why is my variable undefined

Posted 10 January 2013 - 10:46 AM

I think you are forgetting something, to prefix your methods with the class name...

// Not
string Settitle(string ti)
{
	title = ti;
}

// This

string Administrator::Settitle(string ti)
{
	title = ti;
}



Your Settitle and similar functions are part of the Administrator class. So you have to say that this method is part of that class by specifying it using a scope resolution operator (the double colons).

Add that to your methods for functions in your Administrator class and then the variable undefined errors should disappear (because it now knows that the variables you are referencing are part of the Administrator class).

:)

This post has been edited by Martyr2: 10 January 2013 - 10:46 AM

Was This Post Helpful? 1
  • +
  • -

#3 IceHot  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 213
  • Joined: 28-August 12

Re: Why is my variable undefined

Posted 10 January 2013 - 11:04 AM

Also, this is unrelated, but I would suggest a while loop for handling selections. This way, if the user would type in some other number by accident, they can still keep going. Also, using system() is generally a bad way to go; read this article for the reason why: http://www.cplusplus...articles/11153/ . I would recommend, as a substitution for
system("PAUSE")
, that you use something like:
void PressEnterToContinue()
{
	int c = 0;
	cout << "Press ENTER to continue";
	fflush(stdout);
	do
	{
		c = getchar();
	}	//end do
	while ((c != EOF) && (c != '\n'))
}	//end PressEnterToContinue


and then just call PressEnterToContinue() whenever you need it. I hope this helps!

This post has been edited by IceHot: 10 January 2013 - 11:09 AM

Was This Post Helpful? 0
  • +
  • -

#4 llwilkins  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 06-November 12

Re: Why is my variable undefined

Posted 10 January 2013 - 11:56 AM

I have to use system because my instructor told me to do so. When I did not include it one time I got points taken off and the rest of my program was perfect. Yeah its that serious.

Ok now I have another problem after figuring the first one out. I am getting some errors and I have tried everything and nothing is working. I don't even know what the problem possibly could be


//Lynette Wilkins
//Week 12

#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;

class SalariedEmployee
{
private:
	double wageRate;
	int hours;
protected:
	string name;
	string ssn;
	double netPay;
	string department;

public:
	SalariedEmployee(string n, string s, double np, double w, int h, string d);
	 ~SalariedEmployee() {cout<<endl;}
	 string Getname();  //returns name
	 string Getssn();   // returns social security number
	 double GetnetPay(); //returns netPay
	 string Getdepartment(); // returns department
	 double GetwageRate(); //returns wage rate
	 int Gethours(); //returns hours
	 void Setname(string); //sets name
	 void Setssn(string); //sets ssn
	 void SetnetPay(double); //sets net pay
	 void Setdepartment(string); //sets department
	 void SetwageRate(double); //sets wage rate
	 void Sethours(int); //sets hours
	
};


string SalariedEmployee::Getname()
{
	return name;
}

string SalariedEmployee::Getssn()
{
	return ssn;
}

double SalariedEmployee::GetnetPay()
{
	return netPay;
}

double SalariedEmployee::GetwageRate()
{
	return wageRate;
}

int SalariedEmployee::Gethours()
{
	return hours;
}
void SalariedEmployee::Setname(string n)
{
	name = n;
	
}

void SalariedEmployee::Setssn(string s)
{
	ssn = s;
}

void SalariedEmployee::SetnetPay(double np)
{
	netPay = np;
}

void SalariedEmployee::Setdepartment(string d)
{
	department = d;
}


void SalariedEmployee::SetwageRate(double w)
{
	wageRate = w;
}

void SalariedEmployee::Sethours(int h)
{
	hours = h;
}


class Administrator : public SalariedEmployee
{
protected:
	string title;
	string responsi;
	string super;
	double salary;
public:
	Administrator(string t, string r, string s, double sa);
	 ~Administrator();
	string Gettitle();
	string Getresponsi();
	string Getsuper();
	double Getsalary();
	void Settitle(string);
	void Setresponsi(string);
	void Setsuper(string);
	void Setsalary(double);
	void print();
};

Administrator::~Administrator()
{
	cout<<endl;
}

string Administrator::Gettitle()
{
	return title;
}

string Administrator::Getresponsi()
{
	return responsi;
}

string Administrator::Getsuper()
{
	return super;
}

double Administrator::Getsalary()
{
	return salary;
}
void Administrator::Settitle(string ti)
{
	title = ti;
}
void Administrator::Setresponsi(string re)
{
	responsi = re;
}


void Administrator::Setsuper(string su)
{
	super=su;
}

void Administrator::Setsalary(double sa)
{
	salary= sa;
}

void Administrator::print( )
  {
    
    cout << "\n_______________________________________________\n";
	
    cout << "Pay to the order of " << name<< endl;
    cout << "The sum of " << netPay << " Dollars\n";
    cout << "_________________________________________________\n";
    cout <<endl<<endl;
    cout << "Employee Number: " << ssn << endl;
    cout << "Salaried Employee. Regular Pay: " 
       << salary << endl; 
    cout << "_________________________________________________\n";
  }

  



int main()
{

	
	string name;
    string soc;
	double net = 0;
	double wage = 0;
	int hrs = 0;
	string dept;
	string admtitle;
	string resp;
	string sup;
	double sal = 0;
	int response;
	
	string date = "January 12, 2013";

	
	cout<<setprecision(2)
    <<setiosflags(ios::fixed)
    <<setiosflags(ios::showpoint);




	cout<<"Employee and Administrator Salary Program "<<endl;
	cout<<"(You will have to enter data first before you do anything else)"<<endl<<endl;
	cout<<"Enter Employee Data,    Enter 1"<<endl;
	cout<<"Change data,   Enter 2"<<endl;
	cout<<"Print Check,   Enter 3"<<endl<<endl;
	cout<<"Please make your selection"<<endl;

	

cin>> response;

	switch (response)
	{
	case 1:
		cout <<"The employee's data will be entered here: "<<endl<<endl;
		cout<<"Enter the employees name: "<<endl;
		getline(cin, name);

		cout<<"Enter the employees social security number: "<<endl;
		getline(cin, soc);

		cout<<"Enter the employees net pay: "<<endl;
		cin>>net;

		cout<<"Enter the employees wage rate: "<<endl;
		cin>>wage;

		cout<<"Enter the number of hours the employer worked: "<<endl;
		cin>>hrs;
	
		cout<<"Enter the employees title: "<<endl;
		getline(cin, admtitle);

		cout<<"Enter the employees area responsibility: "<<endl;
		getline(cin, resp);

		cout<<"Enter the employees salary: "<<endl;
		cin>>sal;
		cout<<endl<<endl<<endl;

		SalariedEmployee (name, soc, net, wage, hrs, dept);
        Administrator (admtitle, resp, sup, sal);

		cout<<"Change data,   Enter 2"<<endl;
	    cout<<"Print Check,   Enter 3"<<endl<<endl;
	    cout<<"Please make your selection"<<endl;

		
        cin>> response;
      

		break;

	case 2:

		cout<<"Please change the data you entered previously here. " <<endl<<endl;

		cout<<"Enter the employees name: "<<endl;
		getline(cin, name);

		cout<<"Enter the employees social security number: "<<endl;
		getline(cin, soc);

		cout<<"Enter the employees net pay: "<<endl;
		cin>>net;

		cout<<"Enter the employees wage rate: "<<endl;
		cin>>wage;

		cout<<"Enter the number of hours the employer worked: "<<endl;
		cin>>hrs;
	
		cout<<"Enter the employees title: "<<endl;
		getline(cin, admtitle);

		cout<<"Enter the employees area responsibility: "<<endl;
		getline(cin, resp);

		cout<<"Enter the employees salary: "<<endl;
		cin>>sal;
		cout<<endl<<endl<<endl;


			
	    cout<<"Print Check,   Enter 3"<<endl<<endl;
	    cout<<"Please make your selection"<<endl;

		
        cin>> response;
        

		break;

				
	case 3:

		cout <<"Informatin Printed"<<endl<<endl;

		cout<<"_____________________________"<<date<<endl;
		&Administrator::print;



		break;


	default:

		cout<<endl<<endl
			<<"Invalid Selection! Try Again"<<endl;
		exit(1);
		
}

		




	system("PAUSE");
	return 0;
}







here are the errors

1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Administrator::Administrator(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,double)" (??0Administrator@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00N@Z) referenced in function _main

1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall SalariedEmployee::SalariedEmployee(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,double,double,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0SalariedEmployee@@QAE@V?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@0NNH0@Z) referenced in function _main

1>C:\Users\student\Documents\Visual Studio 2010\Projects\week 12 test\Debug\week 12 test.exe : fatal error LNK1120: 2 unresolved externals
Was This Post Helpful? 0
  • +
  • -

#5 IceHot  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 213
  • Joined: 28-August 12

Re: Why is my variable undefined

Posted 10 January 2013 - 01:39 PM

Looks like a problem with your constructors. (I could be wrong here.) I don't understand why
&Administrator::print;
is needed. Could you make do with creating instances of the classes you need to call?
Was This Post Helpful? 0
  • +
  • -

#6 llwilkins  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 06-November 12

Re: Why is my variable undefined

Posted 10 January 2013 - 02:20 PM

honestly I put it because the visual basics application actually requested me to do so. Yeah it has to be something going on with the constructors but this application is not telling me what. so i am lost.
Was This Post Helpful? 0
  • +
  • -

#7 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1347
  • View blog
  • Posts: 4,642
  • Joined: 19-February 09

Re: Why is my variable undefined

Posted 10 January 2013 - 02:54 PM

I don't see where you have created the constructor functions :

024	    SalariedEmployee(string n, string s, double np, double w, int h, string d);
...
107	    Administrator(string t, string r, string s, double sa);



not that you really need them at the moment.

You could create the function and not do anything :

024	    SalariedEmployee(string n, string s, double np, double w, int h, string d) {}
...
107	    Administrator(string t, string r, string s, double sa) {}




If you create them you will probably be told that these lines need an object. You haven't created any objects to hold data.

249	        SalariedEmployee (name, soc, net, wage, hrs, dept);
250	        Administrator (admtitle, resp, sup, sal);




You have a few options - use the current functions to update the data, or create set functions that will update all the data at once.

    // class SalariedEmployee 
    void Set(string n, string s, double np, double w, int h, string d);
    ...
    // class Administrator 
    void Set(string t, string r, string s, double sa);



or have a function in the classes that will allow the user to enter data

    // class SalariedEmployee 
    void EnterData();
    ...
    // class Administrator 
    void EnterData();




In main you need objects to store data into.

SalariedEmployee employee;
Administrator admin;




You could have the menu in a separate function.
Was This Post Helpful? 0
  • +
  • -

#8 llwilkins  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 06-November 12

Re: Why is my variable undefined

Posted 10 January 2013 - 03:18 PM

I have changed up quite a few things and it looks like it is getting better but can someone tell me exactly how to send the variables to the Administrator class.


//Lynette Wilkins
//Week 12

#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;

class SalariedEmployee
{
private:
	double wageRate;
	int hours;
protected:
	string name;
	string ssn;
	double netPay;
	string department;

public:
	SalariedEmployee(string n, string s, double np, double w, int h, string d);
	 ~SalariedEmployee() {cout<<endl;}
	 string Getname();  //returns name
	 string Getssn();   // returns social security number
	 double GetnetPay(); //returns netPay
	 string Getdepartment(); // returns department
	 double GetwageRate(); //returns wage rate
	 int Gethours(); //returns hours
	 void Setname(string); //sets name
	 void Setssn(string); //sets ssn
	 void SetnetPay(double); //sets net pay
	 void Setdepartment(string); //sets department
	 void SetwageRate(double); //sets wage rate
	 void Sethours(int); //sets hours
	
};

SalariedEmployee::SalariedEmployee(string n, string s, double np, double w, int h, string d) : name(n),
      ssn(s),
      netPay(np),
      wageRate(w),
      hours(h),
      department(d)
{}
	  

string SalariedEmployee::Getname()
{
	return name;
}

string SalariedEmployee::Getssn()
{
	return ssn;
}

double SalariedEmployee::GetnetPay()
{
	return netPay;
}

double SalariedEmployee::GetwageRate()
{
	return wageRate;
}

int SalariedEmployee::Gethours()
{
	return hours;
}
void SalariedEmployee::Setname(string n)
{
	name = n;
	
}

void SalariedEmployee::Setssn(string s)
{
	ssn = s;
}

void SalariedEmployee::SetnetPay(double np)
{
	netPay = np;
}

void SalariedEmployee::Setdepartment(string d)
{
	department = d;
}


void SalariedEmployee::SetwageRate(double w)
{
	wageRate = w;
}

void SalariedEmployee::Sethours(int h)
{
	hours = h;
}


class Administrator : public SalariedEmployee
{
protected:
	string title;
	string responsi;
	string super;
	double salary;
public:
	Administrator(string t, string r, string s, double sa);
	 ~Administrator();
	string Gettitle();
	string Getresponsi();
	string Getsuper();
	double Getsalary();
	void Settitle(string);
	void Setresponsi(string);
	void Setsuper(string);
	void Setsalary(double);
	void print();
};


Administrator::Administrator(string t, string r, string s, double sa) : SalariedEmployee(), title(t), responsi(r), super(s), salary(sa)
{
}

Administrator::~Administrator()
{
	cout<<endl;
}

string Administrator::Gettitle()
{
	return title;
}

string Administrator::Getresponsi()
{
	return responsi;
}

string Administrator::Getsuper()
{
	return super;
}

double Administrator::Getsalary()
{
	return salary;
}
void Administrator::Settitle(string ti)
{
	title = ti;
}
void Administrator::Setresponsi(string re)
{
	responsi = re;
}


void Administrator::Setsuper(string su)
{
	super=su;
}

void Administrator::Setsalary(double sa)
{
	salary= sa;
}

void Administrator::print( )
  {
    
    cout << "\n_______________________________________________\n";
	
    cout << "Pay to the order of " << name<< endl;
    cout << "The sum of " << netPay << " Dollars\n";
    cout << "_________________________________________________\n";
    cout <<endl<<endl;
    cout << "Employee Number: " << ssn << endl;
    cout << "Salaried Employee. Regular Pay: " 
       << salary << endl; 
    cout << "_________________________________________________\n";
  }

  



int main()
{

	
	string name;
    string soc;
	double net = 0;
	double wage = 0;
	int hrs = 0;
	string dept;
	string admtitle;
	string resp;
	string sup;
	double sal = 0;
	int response = 0;
	
	string date = "January 12, 2013";

	
	cout<<setprecision(2)
    <<setiosflags(ios::fixed)
    <<setiosflags(ios::showpoint);
	
	SalariedEmployee emp1(name, soc,net, wage, hrs, dept);
	Administrator adm1(admtitle, resp, sup, sal);


while(response != 4){

	cout<<"Employee and Administrator Salary Program "<<endl;
	cout<<"(You will have to enter data first before you do anything else)"<<endl<<endl;
	cout<<"Enter Employee Data,  Enter 1"<<endl;
	cout<<"Change data,   Enter 2"<<endl;
	cout<<"Print Check,   Enter 3"<<endl;
	cout<<"End Program, Enter 4"<<endl<<endl;
	cout<<"Please make your selection"<<endl;

	
  
cin>> response;

	switch (response)


	{
	case 1:
		cout <<"The employee's data will be entered here: "<<endl<<endl;
		
		cout<<"Enter the employees name: ";
	    cin.ignore();
		getline(cin, name);

		cout<<"Enter the employees social security number: ";
		 cin.ignore();
		getline(cin, soc);

		cout<<"Enter the employees net pay: ";
		cin>>net;

		cout<<"Enter the employees wage rate: ";
		cin>>wage;

		cout<<"Enter the number of hours the employer worked: ";
		cin>>hrs;
	
		cout<<"Enter the employees title: ";
		cin.ignore();
	    getline(cin,admtitle);

		cout<<"Enter the employees area responsibility: ";
		cin.ignore();
		getline(cin, resp);

		cout<<"Enter the employees salary: ";
		cin>>sal;



		cout<<endl<<endl<<endl;

		
		break;
      

		

	case 2:

		cout<<"Please change the data you entered previously here. " <<endl<<endl;

		cout<<"Enter the employees name: ";
	    cin.ignore();
		getline(cin, name);

		cout<<"Enter the employees social security number: ";
		 cin.ignore();
		getline(cin, soc);

		cout<<"Enter the employees net pay: ";
		cin>>net;

		cout<<"Enter the employees wage rate: ";
		cin>>wage;

		cout<<"Enter the number of hours the employer worked: ";
		cin>>hrs;
	
		cout<<"Enter the employees title: ";
		cin.ignore();
	    getline(cin,admtitle);

		cout<<"Enter the employees area responsibility: ";
		cin.ignore();
		getline(cin, resp);

		cout<<"Enter the employees salary: ";
		cin>>sal;

		

		cout<<endl<<endl<<endl;
break;
        

					
	case 3:

		cout <<"Information Printed"<<endl<<endl;

		cout<<"_____________________________"<<date<<endl;
		&Administrator::print;



		break;


	default:

		cout<<endl<<endl
			<<"Invalid Selection! Try Again"<<endl;
		exit(1);
		
}
}
		




	system("PAUSE");
	return 0;
}





Was This Post Helpful? 0
  • +
  • -

#9 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1347
  • View blog
  • Posts: 4,642
  • Joined: 19-February 09

Re: Why is my variable undefined

Posted 10 January 2013 - 04:40 PM

You can set the title :

  adm1.Settitle(admtitle);




The SalariedEmployee class is inherited by the Administrator class so the data and functions are available :
So you can set the name :

  adm1.Setname(name);





Classes (I)
Was This Post Helpful? 0
  • +
  • -

#10 llwilkins  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 06-November 12

Re: Why is my variable undefined

Posted 11 January 2013 - 06:42 AM

I have been working on this code for quite some time now and I had posted it before but then after fixing that problem another problem arose so I created a new post with the name of this problem. Ok the problem is that I am obviously not passing the variables to the Administrator class the right way. I have tried two ways which is all my book shows and both have given me an error that says error C2512: 'SalariedEmployee' : no appropriate default constructor available". I have tried

 
Administrator::Administrator(string t, string r, string s, double sa) :  title(t), responsi(r), super(s), salary(sa)
{
}


as well as this

  

Administrator::Administrator(string t, string r, string s, double sa) :  SalariedEmployee(),title(t), responsi(r), super(s), salary(sa)
{
}




Nothing works!! Please help. I need to pass the variables to this class so I can see if the rest of the program works.

//Lynette Wilkins
//Week 12

#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;

class SalariedEmployee
{
private:
	double wageRate;
	int hours;
protected:
	string name;
	string ssn;
	double netPay;
	string department;

public:
	SalariedEmployee(string n, string s, double np, double w, int h, string d);
	 ~SalariedEmployee() {cout<<endl;}
	 string Getname();  //returns name
	 string Getssn();   // returns social security number
	 double GetnetPay(); //returns netPay
	 string Getdepartment(); // returns department
	 double GetwageRate(); //returns wage rate
	 int Gethours(); //returns hours
	 void Setname(string); //sets name
	 void Setssn(string); //sets ssn
	 void SetnetPay(double); //sets net pay
	 void Setdepartment(string); //sets department
	 void SetwageRate(double); //sets wage rate
	 void Sethours(int); //sets hours
	
};

SalariedEmployee::SalariedEmployee(string n, string s, double np, double w, int h, string d) : name(n),
      ssn(s),
      netPay(np),
      wageRate(w),
      hours(h),
      department(d)
{}
	  

string SalariedEmployee::Getname()
{
	return name;
}

string SalariedEmployee::Getssn()
{
	return ssn;
}

double SalariedEmployee::GetnetPay()
{
	return netPay;
}

double SalariedEmployee::GetwageRate()
{
	return wageRate;
}

int SalariedEmployee::Gethours()
{
	return hours;
}
void SalariedEmployee::Setname(string n)
{
	name = n;
	
}

void SalariedEmployee::Setssn(string s)
{
	ssn = s;
}

void SalariedEmployee::SetnetPay(double np)
{
	netPay = np;
}

void SalariedEmployee::Setdepartment(string d)
{
	department = d;
}


void SalariedEmployee::SetwageRate(double w)
{
	wageRate = w;
}

void SalariedEmployee::Sethours(int h)
{
	hours = h;
}


class Administrator : public SalariedEmployee
{
protected:
	string title;
	string responsi;
	string super;
	double salary;
public:
	Administrator(string t, string r, string s, double sa);
	 ~Administrator();
	string Gettitle();
	string Getresponsi();
	string Getsuper();
	double Getsalary();
	void Settitle(string);
	void Setresponsi(string);
	void Setsuper(string);
	void Setsalary(double);
	void print();
};


Administrator::Administrator(string t, string r, string s, double sa) :  title(t), responsi(r), super(s), salary(sa)
{
}

Administrator::~Administrator()
{
	cout<<endl;
}

string Administrator::Gettitle()
{
	return title;
}

string Administrator::Getresponsi()
{
	return responsi;
}

string Administrator::Getsuper()
{
	return super;
}

double Administrator::Getsalary()
{
	return salary;
}
void Administrator::Settitle(string ti)
{
	title = ti;
}
void Administrator::Setresponsi(string re)
{
	responsi = re;
}


void Administrator::Setsuper(string su)
{
	super=su;
}

void Administrator::Setsalary(double sa)
{
	salary= sa;
}

void Administrator::print( )
  {
    
    cout << "\n_______________________________________________\n";
	
    cout << "Pay to the order of " << name<< endl;
    cout << "The sum of " << netPay << " Dollars\n";
    cout << "_________________________________________________\n";
    cout <<endl<<endl;
    cout << "Employee Number: " << ssn << endl;
    cout << "Salaried Employee. Regular Pay: " 
       << salary << endl; 
    cout << "_________________________________________________\n";
  }

  



int main()
{

	
	string name;
    string soc;
	double net = 0;
	double wage = 0;
	int hrs = 0;
	string dept;
	string admtitle;
	string resp;
	string sup;
	double sal = 0;
	int response = 0;
	
	string date = "January 12, 2013";

	
	cout<<setprecision(2)
    <<setiosflags(ios::fixed)
    <<setiosflags(ios::showpoint);
	
	SalariedEmployee emp1(name, soc,net, wage, hrs, dept);
	Administrator adm1(admtitle, resp, sup, sal);


while(response != 4){

	cout<<"Employee and Administrator Salary Program "<<endl;
	cout<<"(You will have to enter data first before you do anything else)"<<endl<<endl;
	cout<<"Enter Employee Data,  Enter 1"<<endl;
	cout<<"Change data,   Enter 2"<<endl;
	cout<<"Print Check,   Enter 3"<<endl;
	cout<<"End Program, Enter 4"<<endl<<endl;
	cout<<"Please make your selection"<<endl;

	
  
cin>> response;

	switch (response)


	{
	case 1:
		cout <<"The employee's data will be entered here: "<<endl<<endl;
		
		cout<<"Enter the employees name: ";
	    cin.ignore();
		getline(cin, name);

		cout<<"Enter the employees social security number: ";
		 cin.ignore();
		getline(cin, soc);

		cout<<"Enter the employees net pay: ";
		cin>>net;

		cout<<"Enter the employees wage rate: ";
		cin>>wage;

		cout<<"Enter the number of hours the employer worked: ";
		cin>>hrs;
	
		cout<<"Enter the employees title: ";
		cin.ignore();
	    getline(cin,admtitle);

		cout<<"Enter the employees area responsibility: ";
		cin.ignore();
		getline(cin, resp);

		cout<<"Enter the employees salary: ";
		cin>>sal;



		cout<<endl<<endl<<endl;

		
		break;
      

		

	case 2:

		cout<<"Please change the data you entered previously here. " <<endl<<endl;

		cout<<"Enter the employees name: ";
	    cin.ignore();
		getline(cin, name);

		cout<<"Enter the employees social security number: ";
		 cin.ignore();
		getline(cin, soc);

		cout<<"Enter the employees net pay: ";
		cin>>net;

		cout<<"Enter the employees wage rate: ";
		cin>>wage;

		cout<<"Enter the number of hours the employer worked: ";
		cin>>hrs;
	
		cout<<"Enter the employees title: ";
		cin.ignore();
	    getline(cin,admtitle);

		cout<<"Enter the employees area responsibility: ";
		cin.ignore();
		getline(cin, resp);

		cout<<"Enter the employees salary: ";
		cin>>sal;

		

		cout<<endl<<endl<<endl;
break;
        

					
	case 3:

		cout <<"Information Printed"<<endl<<endl;

		cout<<"_____________________________"<<date<<endl;
		&Administrator::print;



		break;


	default:

		cout<<endl<<endl
			<<"Invalid Selection! Try Again"<<endl;
		exit(1);
		
}
}
		




	system("PAUSE");
	return 0;
}





Was This Post Helpful? 0
  • +
  • -

#11 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Why is my variable undefined

Posted 11 January 2013 - 07:04 AM

If you notice closely, in your line 25 you are declaring a destructor instead of a constructor.

regards,
Raghav

This post has been edited by raghav.naganathan: 11 January 2013 - 07:05 AM

Was This Post Helpful? 0
  • +
  • -

#12 llwilkins  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 06-November 12

Re: Why is my variable undefined

Posted 11 January 2013 - 07:13 AM

I'm actually working with the one on line 115 the derived class.
Was This Post Helpful? 0
  • +
  • -

#13 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Why is my variable undefined

Posted 11 January 2013 - 07:17 AM

Well, the destructor you have declared is ~SalariedEmployee() but the line 115 has nothing at all to do with SalariedEmployee()

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#14 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: Why is my variable undefined

Posted 11 January 2013 - 07:32 AM

The base class constructor accepts some parameters,
024	    SalariedEmployee(string n, string s, double np, double w, int h, string d);



While you didn't pass any in both the cases, either you intended it to call the default constructor or one with empty parameter list which you even didn't declared...
Was This Post Helpful? 0
  • +
  • -

#15 llwilkins  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 06-November 12

Re: Why is my variable undefined

Posted 11 January 2013 - 07:54 AM

View Postraghav.naganathan, on 11 January 2013 - 07:17 AM, said:

Well, the destructor you have declared is ~SalariedEmployee() but the line 115 has nothing at all to do with SalariedEmployee()

regards,
Raghav


Right I know that I created a destructor in SalariedEmployee but what I am trying to pass this too is the Administrator class. So are you telling me I should get rid of the destructor?

View PostAKMafia001, on 11 January 2013 - 07:32 AM, said:

The base class constructor accepts some parameters,
024	    SalariedEmployee(string n, string s, double np, double w, int h, string d);



While you didn't pass any in both the cases, either you intended it to call the default constructor or one with empty parameter list which you even didn't declared...



OK you lost me a little here.


	SalariedEmployee emp1(name, soc,net, wage, hrs, dept);
	Administrator adm1(admtitle, resp, sup, sal);




This is the area where I am passing the variables and I think that the first one was passed it is just the second one that I am not knowing how to code properly.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2