Program 2, Object Not Seeing It Self

Wanna understand E=mc2, English grammer, or maybe just build a computer? We can help!

Moderator: Moderators

Post Reply
LoSTimberWolf
Inmate
Posts: 128
Joined: Sun Jan 27, 2002 4:17 pm

Program 2, Object Not Seeing It Self

Post by LoSTimberWolf »

Ok, I have done almost every thing I can figure out, but no matter what I do, they object does not see the functions within itself. I have set it up that one function is called from the main and then the rest is called from that function.<br><br>*EDIT* Latest and greatest coding after help from Gambit, still no work.<br><br>Here is what C++ tells me:<br>: error C2146: syntax error : missing ')' before identifier '_empName'<br>: error C2146: syntax error : missing ';' before identifier '_empName'<br>: error C2501: '_empName' : missing storage-class or type specifiers<br>: warning C4518: 'char ' : storage-class or type specifier(s) unexpected here; ignored<br>: error C2059: syntax error : '['<br>: fatal error C1004: unexpected end of file foundError executing cl.exe.<br><br><br>My teacher still asks for a "class level function", what ever that is. To make this post longer, her is the object (note: I was not given a main this time):<br><br><br>#ifndef EMPLOYEE_H<br>#define EMPLOYEE_H<br><br>//Object created named Employee<br>class employee<br>{<br>&nbsp &nbsp &nbsp &nbsp private:<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //class variables<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp char empName[11];<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp char empType[7];<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double ratePay;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double input;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double pay;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Three ways to calculate pay<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double setHourlypay (double _hoursWorked) {pay = _hoursWorked * ratePay; aftCalcDisplay(); return pay;};<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double setSalespay (double _sales) {pay = _sales * ratepay; aftCalcDisplay(); return pay;};<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double setSalarypay (double _salary) {pay = _salary; aftCalcDisplay(); return pay;};<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Input validation<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp bool inputValidHours (double);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp bool inputValidSales (double);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp bool inputValidSalary (double);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Output of empName and pay for the week<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp void getCalcDisplay (double) {cout << "Weekly Pay For " << empName << " is $" << pay << endl;};<br>&nbsp &nbsp &nbsp &nbsp public:<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Overloaded constructor<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp employee::employee () {empName = "John Doe"; empType = "hourly"; input = 0; ratePay = 0; sales = 0; hours = 0;};<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp employee::employee (char[] _empName, char[] _empType) {strcpy(empName, _empName); strcpy(empType, _empType); input = 0; ratePay = 0; hours = 0;};<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp employee::employee (char[] _empName, char[] _empType, double _ratePay) {strcpy(empName, _empName); strcpy(empType, _empType); input = 0; ratePay = _ratePay; hours = 0;};<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Determines which calculation to use for pay<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double getPayType ();<br>};<br>#endif;<br><br><br>double employee::getPayType ()<br>{<br>if (strcmp(empType, "hourly") == 0)<br>&nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp cout << "Enter number of hours worked for " << empName << endl;<br>&nbsp &nbsp &nbsp &nbsp cin >> input;<br>&nbsp &nbsp &nbsp &nbsp inputValidHours(input);<br>&nbsp &nbsp &nbsp &nbsp getCalcDisplay(pay);<br>&nbsp &nbsp &nbsp &nbsp return pay;<br>&nbsp &nbsp &nbsp &nbsp }<br>else if (strcmp(empType, "salary")<br>&nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp cout << "Enter weekly salary for " << empName << endl;<br>&nbsp &nbsp &nbsp &nbsp cin >> input;<br>&nbsp &nbsp &nbsp &nbsp inputValidSalary(input);<br>&nbsp &nbsp &nbsp &nbsp aftCalcDisplay(pay);<br>&nbsp &nbsp &nbsp &nbsp return pay;<br>&nbsp &nbsp &nbsp &nbsp }<br>else if (strcmp(empType, "sales")<br>&nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp cout << "Enter weekly sales for " << empName << endl;<br>&nbsp &nbsp &nbsp &nbsp cin >> input;<br>&nbsp &nbsp &nbsp &nbsp inputValidSales(input);<br>&nbsp &nbsp &nbsp &nbsp aftCalcDisplay(pay);<br>&nbsp &nbsp &nbsp &nbsp return pay;<br>&nbsp &nbsp &nbsp &nbsp }<br>else<br>&nbsp &nbsp &nbsp &nbsp cout << "An error in the information has been detected" << endl;<br>}<br><br><br>double employee::inputValidHours (double _hoursWorked)<br>{<br>bool valid = 0;<br>//Validation of hours worked, between 0 and 60<br>while (valid = 0)<br>&nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp if (_hoursWorked < 0)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Number of hours can not go below 0" << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Please enter the correct hours: " << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 0;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp else if (_hoursWorked > 60)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Number of hours can not exceed 60 hours" << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Please enter the correct hours: " << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 0;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp else<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 1;<br>&nbsp &nbsp &nbsp &nbsp }<br>return setHourlypay (_hoursWorked);<br>}<br><br><br>double employee::inputValidSales (double _sales)<br>{<br>&nbsp &nbsp &nbsp &nbsp //Validation of sales, between 0 and 1000,000<br>bool valid = 0;<br>while (valid = 0)<br>&nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp if (_sales < 0)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "The amount of Sales can not go below 0" << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Please enter the correct Sales number: " << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 0;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp else if (_sales > 100000)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "The amount of Sales can not exceed $100,000" << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Please enter the correct Sales number: " << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 0;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp else <br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 1;<br>&nbsp &nbsp &nbsp &nbsp }<br>return setSalespay (_sales);<br>}<br><br><br>double employee::inputValidSalary (double _salary)<br>{<br>//Validation of sales, between 0 and 1000,000<br>bool valid = 0;<br>while (valid = 0)<br>&nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp if (_salary < 0)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "The amount of Salary can not go below 0" << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Please enter the correct Salary number: " << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 0;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp else if (_salary > 100000)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "The amount of Salary can not exceed $1,000" << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Please enter the correct Salary number: " << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 0;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp else <br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 1;<br>&nbsp &nbsp &nbsp &nbsp }<br>return setSalarypay(_salary);<br><br>} <p>-LoS-TimberWolf{FF}<br>Vehicle Specilist</p><i>Edited by: <A HREF=http://pub141.ezboard.com/bxmenclan.sho ... berWolf</A> at: 2/5/03 11:48:57 pm<br></i>
LoSTimberWolf
Inmate
Posts: 128
Joined: Sun Jan 27, 2002 4:17 pm

Re: Program 2, Object Not Seeing It Self

Post by LoSTimberWolf »

Oh, and here is the main if you want to look at that too:<br><br>void main ()<br>{<br>double totalPay = 0;<br>employee Staff[] = { employee("Able Smith", "hourly"), employee("Lois Smith", "sales"), employee("Elton Smith", "salary", 0), employee("Bubba Smith", "hourly"), employee("Janet Smith", "sales"), employee("Frank Smith", "salary", 0)};<br>for (int count = 0; count < 6; count++)<br>&nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp Staff[count].employee;<br>&nbsp &nbsp &nbsp &nbsp totalPay += Staff[count].getPayType();<br>&nbsp &nbsp &nbsp &nbsp }<br>cout << endl;<br>cout << "Total weekly pay: " << totalPay << endl;<br>} <p>-LoS-TimberWolf{FF}<br>Vehicle Specilist</p><i></i>
User avatar
XMEN Gambit
Site Admin
Posts: 4122
Joined: Thu Nov 18, 1999 12:00 am

Re: Program 2, Object Not Seeing It Self

Post by XMEN Gambit »

Well, for one thing, your function names don't have "employee::" in front of them, meaning they won't be created as methods of the class and can't see the class's variables. Gotta stop forgetting those, d00d. <!--EZCODE EMOTICON START :) --><img src=http://www.ezboard.com/images/emoticons/smile.gif ALT=":)"><!--EZCODE EMOTICON END--> <br><br>The very first error message you get is because of your attempt to overload the default constructor. The declarative syntax you've used is odd; I'll have to check out the specifics later but for now you could try leaving off the declarations for the constructors and just defining them down with the rest of the functions as <br><!--EZCODE BOLD START--><strong>public employee::employee() {...code here...}</strong><!--EZCODE BOLD END--><br>It may just be that it chokes on seeing a declaration for the default constructor (you don't need that because every class is assumed to have one), and the declarations for the others are OK, but because of the original error it blows so many chunks later. Pascal and C compilers tend to do that, so you work from the top down when fixing bugs.<br><br>This is all top-of-my-head without loading into a project. I'll do that later if these clues don't help. <p><!--EZCODE IMAGE START--><img src="http://www.xmenclan.org/xmengambit.gif"/><!--EZCODE IMAGE END--><br>XMEN member<br>Card-carrying DTM<br>OKL Fish-napper<br><br>Though a program be but three lines long, someday it will have to be maintained.<br><!--EZCODE ITALIC START--><em> The Tao of Programming</em><!--EZCODE ITALIC END--></p><i></i>
Image
LoSTimberWolf
Inmate
Posts: 128
Joined: Sun Jan 27, 2002 4:17 pm

Re: Program 2, Object Not Seeing It Self

Post by LoSTimberWolf »

That helped alot Gambit. This program is due tomarrow about 11am. After doing the correction, adding employee:: to the constructors and functions, there are 5 errors and 1 warning left.<br><br><br>: error C2146: syntax error : missing ')' before identifier '_empName'<br>: error C2146: syntax error : missing ';' before identifier '_empName'<br>: error C2501: '_empName' : missing storage-class or type specifiers<br>: warning C4518: 'char ' : storage-class or type specifier(s) unexpected here; ignored<br>: error C2059: syntax error : '['<br>: fatal error C1004: unexpected end of file found<br>Error executing cl.exe. <p>-LoS-TimberWolf{FF}<br>Vehicle Specilist</p><i></i>
BlackRider
Inmate
Posts: 966
Joined: Thu Jan 17, 2002 5:26 pm

Re: Program 2, Object Not Seeing It Self

Post by BlackRider »

11 am what time zone?<br><br>k...<br><br>char[] _empName is wrong isn't it? shouldn't it be...<br>char _empName[] to make _empName a string?<br><br>need a strcpy() to assign "John Doe" to empName in a constructor<br><br>where are sales and hours defined? (they are used in a constructor)<br><br>I don't see an 'employee' member of the employee class... so how does 'Staff[count].employee;' fit in?<br><br>in 'employee::getPayType ()' you're missing some ')'s<br><br>where in the world is aftCalcDisplay() declared or defined?<br><br>that's all I noticed looking through it... GL <p><!--EZCODE FONT START--><span style="color:red;font-size:large;">C</span><!--EZCODE FONT END--><!--EZCODE FONT START--><span style="color:orange;font-size:large;">O</span><!--EZCODE FONT END--><!--EZCODE FONT START--><span style="color:green;font-size:large;">L</span><!--EZCODE FONT END--><!--EZCODE FONT START--><span style="color:blue;font-size:large;">O</span><!--EZCODE FONT END--><!--EZCODE FONT START--><span style="color:indigo;font-size:large;">R</span><!--EZCODE FONT END--><!--EZCODE FONT START--><span style="color:violet;font-size:large;">S</span><!--EZCODE FONT END--><!--EZCODE FONT START--><span style="color:pink;font-size:xx-large;">!</span><!--EZCODE FONT END--></p><i></i>
User avatar
XMEN Gambit
Site Admin
Posts: 4122
Joined: Thu Nov 18, 1999 12:00 am

Re: Program 2, Object Not Seeing It Self

Post by XMEN Gambit »

Sounds like BR is on it. Sorry, didn't know you had the deadline before and I was going to bed. <!--EZCODE EMOTICON START :) --><img src=http://www.ezboard.com/images/emoticons/smile.gif ALT=":)"><!--EZCODE EMOTICON END--> Bleary brain no workie goodie. <p><!--EZCODE IMAGE START--><img src="http://www.xmenclan.org/xmengambit.gif"/><!--EZCODE IMAGE END--><br>XMEN member<br>Card-carrying DTM<br>OKL Fish-napper<br><br>Though a program be but three lines long, someday it will have to be maintained.<br><!--EZCODE ITALIC START--><em> The Tao of Programming</em><!--EZCODE ITALIC END--></p><i></i>
Image
LoSTimberWolf
Inmate
Posts: 128
Joined: Sun Jan 27, 2002 4:17 pm

Re: Program 2, Object Not Seeing It Self

Post by LoSTimberWolf »

11am Central Standard time.<br><br>It depends were it that is written, such as prototypes. I have changed that to pointers now.<br><br>There are strcpy()'s used to transfer the data into the Object.<br><br>Sales and hours are function variables based off the variable input. Instead of having one veariable for each I decided to condence it some.<br><br>I have removed Staff[count].employee which was to trigger the constructor, but did not.<br><br>What do you mean that ')'s are missing?<br><br>aftCalcDisplay() is now getCalcDisplay() and that is declared up in the object under private.<br><br>I have it compiled and running, but there are still bugs in it. Got just over an hour left.<br><br>Just so you can see what I have now, after getting some sleep myself:<br><br><br>#ifndef EMPLOYEE_H<br>#define EMPLOYEE_H<br><br>//Object created named Employee<br>class employee<br>{<br>&nbsp &nbsp &nbsp &nbsp private:<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //class variables<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp char empName[12];<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp char empType[7];<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double ratePay;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double input;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double pay;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Three ways to calculate pay<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double setHourlypay (double _hoursWorked) {pay = _hoursWorked * ratePay; getCalcDisplay(pay); return pay;};<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double setSalespay (double _sales) {pay = _sales * ratePay; getCalcDisplay(pay); return pay;};<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double setSalarypay (double _salary) {pay = _salary; getCalcDisplay(pay); return pay;};<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Input validation<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double inputValidHours (double);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double inputValidSales (double);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double inputValidSalary (double);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Output of empName and pay for the week<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp void getCalcDisplay (double) {cout.precision(3); cout << "Weekly Pay For " << empName << " is $" << pay << endl << endl;};<br><br>&nbsp &nbsp &nbsp &nbsp public:<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Overloaded constructor<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp employee::employee ();<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp employee::employee (char*, char*);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp employee::employee (char*, char*, double);<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //Determines which calculation to use for pay<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp double getPayType ();<br>};<br>#endif;<br><br>/*****************************************************************/<br><br>employee::employee()<br>{<br>&nbsp &nbsp &nbsp &nbsp strcpy(empName, "John Doe"); <br>&nbsp &nbsp &nbsp &nbsp strcpy(empType, "hourly"); <br>&nbsp &nbsp &nbsp &nbsp input = 0; <br>&nbsp &nbsp &nbsp &nbsp ratePay = 1; <br>};<br><br>/*****************************************************************/<br><br>employee::employee(char* _empName, char* _empType) <br>{<br>&nbsp &nbsp &nbsp &nbsp strcpy(empName, _empName); <br>&nbsp &nbsp &nbsp &nbsp strcpy(empType, _empType); <br>&nbsp &nbsp &nbsp &nbsp input = 0; <br>&nbsp &nbsp &nbsp &nbsp ratePay = 1; <br>};<br><br>/*****************************************************************/<br><br>employee::employee(char* _empName, char* _empType, double _ratePay) <br>{<br>&nbsp &nbsp &nbsp &nbsp strcpy(empName, _empName); <br>&nbsp &nbsp &nbsp &nbsp strcpy(empType, _empType); <br>&nbsp &nbsp &nbsp &nbsp input = 0; <br>&nbsp &nbsp &nbsp &nbsp ratePay = _ratePay; <br>};<br><br>/*****************************************************************/<br><br>double employee::getPayType()<br>{<br>if (strcmp(empType, "hourly") == 0)<br>&nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp cout << "Enter number of hours worked for " << empName << endl;<br>&nbsp &nbsp &nbsp &nbsp cin >> input;<br>&nbsp &nbsp &nbsp &nbsp inputValidHours(input);<br>&nbsp &nbsp &nbsp &nbsp getCalcDisplay(pay);<br>&nbsp &nbsp &nbsp &nbsp return pay;<br>&nbsp &nbsp &nbsp &nbsp }<br>else if (strcmp(empType, "salary") == 0)<br>&nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp cout << "Enter weekly salary for " << empName << endl;<br>&nbsp &nbsp &nbsp &nbsp cin >> input;<br>&nbsp &nbsp &nbsp &nbsp inputValidSalary(input);<br>&nbsp &nbsp &nbsp &nbsp getCalcDisplay(pay);<br>&nbsp &nbsp &nbsp &nbsp return pay;<br>&nbsp &nbsp &nbsp &nbsp }<br>else if (strcmp(empType, "sales") == 0)<br>&nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp cout << "Enter weekly sales for " << empName << endl;<br>&nbsp &nbsp &nbsp &nbsp cin >> input;<br>&nbsp &nbsp &nbsp &nbsp inputValidSales(input);<br>&nbsp &nbsp &nbsp &nbsp getCalcDisplay(pay);<br>&nbsp &nbsp &nbsp &nbsp return pay;<br>&nbsp &nbsp &nbsp &nbsp }<br>else<br>&nbsp &nbsp &nbsp &nbsp cout << "An error in the information has been detected" << endl;<br>&nbsp &nbsp &nbsp &nbsp return 0;<br>};<br><br>/*****************************************************************/<br><br>double employee::inputValidHours(double _hoursWorked)<br>{<br>bool valid = 0;<br>//Validation of hours worked, between 0 and 60<br>while (valid = 0)<br>&nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp if (_hoursWorked < 0)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Number of hours can not go below 0" << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Please enter the correct hours: " << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 0;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp else if (_hoursWorked > 60)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Number of hours can not exceed 60 hours" << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Please enter the correct hours: " << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 0;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp else<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 1;<br>&nbsp &nbsp &nbsp &nbsp }<br>return setHourlypay (_hoursWorked);<br>};<br><br>/*****************************************************************/<br><br>double employee::inputValidSales(double _sales)<br>{<br>&nbsp &nbsp &nbsp &nbsp //Validation of sales, between 0 and 1000,000<br>bool valid = 0;<br>while (valid = 0)<br>&nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp if (_sales < 0)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "The amount of Sales can not go below 0" << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Please enter the correct Sales number: " << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 0;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp else if (_sales > 100000)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "The amount of Sales can not exceed $100,000" << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Please enter the correct Sales number: " << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 0;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp else <br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 1;<br>&nbsp &nbsp &nbsp &nbsp }<br>return setSalespay (_sales);<br>};<br><br>/*****************************************************************/<br><br>double employee::inputValidSalary(double _salary)<br>{<br>//Validation of sales, between 0 and 1000,000<br>bool valid = 0;<br>while (valid = 0)<br>&nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp if (_salary < 0)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "The amount of Salary can not go below 0" << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Please enter the correct Salary number: " << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 0;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp else if (_salary > 100000)<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "The amount of Salary can not exceed $1,000" << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp cout << "Please enter the correct Salary number: " << endl;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 0;<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }<br>&nbsp &nbsp &nbsp &nbsp else <br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp valid = 1;<br>&nbsp &nbsp &nbsp &nbsp }<br>return setSalarypay(_salary);<br><br>}; <p>-LoS-TimberWolf{FF}<br>Vehicle Specilist</p><i>Edited by: <A HREF=http://pub141.ezboard.com/bxmenclan.sho ... berWolf</A> at: 2/6/03 9:49:36 am<br></i>
LoSTimberWolf
Inmate
Posts: 128
Joined: Sun Jan 27, 2002 4:17 pm

Re: Program 2, Object Not Seeing It Self

Post by LoSTimberWolf »

Ok, down to less than an hour and one big bug is sitting onmy face. Everything works as they were designed to do, as far as I have been able to test. But one thing is being printed to the screen, getCalcDisply(), two times in a row when its only called once. Even though the code above is not the most recent, added another function for validation, it is close enough to see whats wrong. Can anyone help?<br><br><br>*EDIT*<br>There is 30 mins left, and I can't figure it out. I am turning in this program right now with the problem. Hope that the TA that grades it is leaniant. <p>-LoS-TimberWolf{FF}<br>Vehicle Specilist</p><i>Edited by: <A HREF=http://pub141.ezboard.com/bxmenclan.sho ... berWolf</A> at: 2/6/03 10:24:46 am<br></i>
User avatar
XMEN Gambit
Site Admin
Posts: 4122
Joined: Thu Nov 18, 1999 12:00 am

Re: Program 2, Object Not Seeing It Self

Post by XMEN Gambit »

Well, I see that it is getting called from setSalespay() and setSalarypay(), as well as from within getPayType().<br><br><br>Debugging tip:<br>If you really want to know exactly where a method is getting called from and when, set a breakpoint on the method, then run the prog in debug mode. When the program stops at the breakpoint, check your call stack and see where the method was called from. <p><!--EZCODE IMAGE START--><img src="http://www.xmenclan.org/xmengambit.gif"/><!--EZCODE IMAGE END--><br>XMEN member<br>Card-carrying DTM<br>OKL Fish-napper<br><br>Though a program be but three lines long, someday it will have to be maintained.<br><!--EZCODE ITALIC START--><em> The Tao of Programming</em><!--EZCODE ITALIC END--></p><i></i>
Image
LoSTimberWolf
Inmate
Posts: 128
Joined: Sun Jan 27, 2002 4:17 pm

Re: Program 2, Object Not Seeing It Self

Post by LoSTimberWolf »

I know it gets called from three different locations, but only one of those are called each time. The debug program hates me anyway, and with this coding it would give me hell. Tomarrow I will start on a new program thats due next week on thursday. <p>-LoS-TimberWolf{FF}<br>Vehicle Specilist</p><i></i>
User avatar
XMEN Gambit
Site Admin
Posts: 4122
Joined: Thu Nov 18, 1999 12:00 am

Re: Program 2, Object Not Seeing It Self

Post by XMEN Gambit »

<br>If you plan to program, even just for class, you MUST learn to use the debugger. It's really the most helpful and effective tool for fixing those problems. The features I use most are single-stepping, so I can see exactly how the proggy came to do what I didn't expect; the call stack, so I can see how it got there; and setting watches on variables so I can check the state of the program at any point. If you're using Visual Studio it's really easy, too.<br><br>Starting on the program well ahead of the due date is an awfully good idea. <!--EZCODE EMOTICON START :) --><img src=http://www.ezboard.com/images/emoticons/smile.gif ALT=":)"><!--EZCODE EMOTICON END--> <br><br> <p><!--EZCODE IMAGE START--><img src="http://www.xmenclan.org/xmengambit.gif"/><!--EZCODE IMAGE END--><br>XMEN member<br>Card-carrying DTM<br>OKL Fish-napper<br><br>Though a program be but three lines long, someday it will have to be maintained.<br><!--EZCODE ITALIC START--><em> The Tao of Programming</em><!--EZCODE ITALIC END--></p><i></i>
Image
Post Reply