Program 2, Object Not Seeing It Self
Moderator: Moderators
-
- Inmate
- Posts: 128
- Joined: Sun Jan 27, 2002 4:17 pm
Program 2, Object Not Seeing It Self
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>        private:<br>                //class variables<br>                char empName[11];<br>                char empType[7];<br>                double ratePay;<br>                double input;<br>                double pay;<br>                //Three ways to calculate pay<br>                double setHourlypay (double _hoursWorked) {pay = _hoursWorked * ratePay; aftCalcDisplay(); return pay;};<br>                double setSalespay (double _sales) {pay = _sales * ratepay; aftCalcDisplay(); return pay;};<br>                double setSalarypay (double _salary) {pay = _salary; aftCalcDisplay(); return pay;};<br>                //Input validation<br>                bool inputValidHours (double);<br>                bool inputValidSales (double);<br>                bool inputValidSalary (double);<br>                //Output of empName and pay for the week<br>                void getCalcDisplay (double) {cout << "Weekly Pay For " << empName << " is $" << pay << endl;};<br>        public:<br>                //Overloaded constructor<br>                employee::employee () {empName = "John Doe"; empType = "hourly"; input = 0; ratePay = 0; sales = 0; hours = 0;};<br>                employee::employee (char[] _empName, char[] _empType) {strcpy(empName, _empName); strcpy(empType, _empType); input = 0; ratePay = 0; hours = 0;};<br>                employee::employee (char[] _empName, char[] _empType, double _ratePay) {strcpy(empName, _empName); strcpy(empType, _empType); input = 0; ratePay = _ratePay; hours = 0;};<br>                //Determines which calculation to use for pay<br>                double getPayType ();<br>};<br>#endif;<br><br><br>double employee::getPayType ()<br>{<br>if (strcmp(empType, "hourly") == 0)<br>        {<br>        cout << "Enter number of hours worked for " << empName << endl;<br>        cin >> input;<br>        inputValidHours(input);<br>        getCalcDisplay(pay);<br>        return pay;<br>        }<br>else if (strcmp(empType, "salary")<br>        {<br>        cout << "Enter weekly salary for " << empName << endl;<br>        cin >> input;<br>        inputValidSalary(input);<br>        aftCalcDisplay(pay);<br>        return pay;<br>        }<br>else if (strcmp(empType, "sales")<br>        {<br>        cout << "Enter weekly sales for " << empName << endl;<br>        cin >> input;<br>        inputValidSales(input);<br>        aftCalcDisplay(pay);<br>        return pay;<br>        }<br>else<br>        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>        {<br>        if (_hoursWorked < 0)<br>                {<br>                cout << "Number of hours can not go below 0" << endl;<br>                cout << "Please enter the correct hours: " << endl;<br>                valid = 0;<br>                }<br>        else if (_hoursWorked > 60)<br>                {<br>                cout << "Number of hours can not exceed 60 hours" << endl;<br>                cout << "Please enter the correct hours: " << endl;<br>                valid = 0;<br>                }<br>        else<br>                valid = 1;<br>        }<br>return setHourlypay (_hoursWorked);<br>}<br><br><br>double employee::inputValidSales (double _sales)<br>{<br>        //Validation of sales, between 0 and 1000,000<br>bool valid = 0;<br>while (valid = 0)<br>        {<br>        if (_sales < 0)<br>                {<br>                cout << "The amount of Sales can not go below 0" << endl;<br>                cout << "Please enter the correct Sales number: " << endl;<br>                valid = 0;<br>                }<br>        else if (_sales > 100000)<br>                {<br>                cout << "The amount of Sales can not exceed $100,000" << endl;<br>                cout << "Please enter the correct Sales number: " << endl;<br>                valid = 0;<br>                }<br>        else <br>                valid = 1;<br>        }<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>        {<br>        if (_salary < 0)<br>                {<br>                cout << "The amount of Salary can not go below 0" << endl;<br>                cout << "Please enter the correct Salary number: " << endl;<br>                valid = 0;<br>                }<br>        else if (_salary > 100000)<br>                {<br>                cout << "The amount of Salary can not exceed $1,000" << endl;<br>                cout << "Please enter the correct Salary number: " << endl;<br>                valid = 0;<br>                }<br>        else <br>                valid = 1;<br>        }<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>
-
- Inmate
- Posts: 128
- Joined: Sun Jan 27, 2002 4:17 pm
Re: Program 2, Object Not Seeing It Self
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>        {<br>        Staff[count].employee;<br>        totalPay += Staff[count].getPayType();<br>        }<br>cout << endl;<br>cout << "Total weekly pay: " << totalPay << endl;<br>} <p>-LoS-TimberWolf{FF}<br>Vehicle Specilist</p><i></i>
- XMEN Gambit
- Site Admin
- Posts: 4122
- Joined: Thu Nov 18, 1999 12:00 am
Re: Program 2, Object Not Seeing It Self
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>
-
- Inmate
- Posts: 128
- Joined: Sun Jan 27, 2002 4:17 pm
Re: Program 2, Object Not Seeing It Self
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>
-
- Inmate
- Posts: 966
- Joined: Thu Jan 17, 2002 5:26 pm
Re: Program 2, Object Not Seeing It Self
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>
- XMEN Gambit
- Site Admin
- Posts: 4122
- Joined: Thu Nov 18, 1999 12:00 am
Re: Program 2, Object Not Seeing It Self
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>
-
- Inmate
- Posts: 128
- Joined: Sun Jan 27, 2002 4:17 pm
Re: Program 2, Object Not Seeing It Self
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>        private:<br>                //class variables<br>                char empName[12];<br>                char empType[7];<br>                double ratePay;<br>                double input;<br>                double pay;<br>                //Three ways to calculate pay<br>                double setHourlypay (double _hoursWorked) {pay = _hoursWorked * ratePay; getCalcDisplay(pay); return pay;};<br>                double setSalespay (double _sales) {pay = _sales * ratePay; getCalcDisplay(pay); return pay;};<br>                double setSalarypay (double _salary) {pay = _salary; getCalcDisplay(pay); return pay;};<br>                //Input validation<br>                double inputValidHours (double);<br>                double inputValidSales (double);<br>                double inputValidSalary (double);<br>                //Output of empName and pay for the week<br>                void getCalcDisplay (double) {cout.precision(3); cout << "Weekly Pay For " << empName << " is $" << pay << endl << endl;};<br><br>        public:<br>                //Overloaded constructor<br>                employee::employee ();<br>                employee::employee (char*, char*);<br>                employee::employee (char*, char*, double);<br>                //Determines which calculation to use for pay<br>                double getPayType ();<br>};<br>#endif;<br><br>/*****************************************************************/<br><br>employee::employee()<br>{<br>        strcpy(empName, "John Doe"); <br>        strcpy(empType, "hourly"); <br>        input = 0; <br>        ratePay = 1; <br>};<br><br>/*****************************************************************/<br><br>employee::employee(char* _empName, char* _empType) <br>{<br>        strcpy(empName, _empName); <br>        strcpy(empType, _empType); <br>        input = 0; <br>        ratePay = 1; <br>};<br><br>/*****************************************************************/<br><br>employee::employee(char* _empName, char* _empType, double _ratePay) <br>{<br>        strcpy(empName, _empName); <br>        strcpy(empType, _empType); <br>        input = 0; <br>        ratePay = _ratePay; <br>};<br><br>/*****************************************************************/<br><br>double employee::getPayType()<br>{<br>if (strcmp(empType, "hourly") == 0)<br>        {<br>        cout << "Enter number of hours worked for " << empName << endl;<br>        cin >> input;<br>        inputValidHours(input);<br>        getCalcDisplay(pay);<br>        return pay;<br>        }<br>else if (strcmp(empType, "salary") == 0)<br>        {<br>        cout << "Enter weekly salary for " << empName << endl;<br>        cin >> input;<br>        inputValidSalary(input);<br>        getCalcDisplay(pay);<br>        return pay;<br>        }<br>else if (strcmp(empType, "sales") == 0)<br>        {<br>        cout << "Enter weekly sales for " << empName << endl;<br>        cin >> input;<br>        inputValidSales(input);<br>        getCalcDisplay(pay);<br>        return pay;<br>        }<br>else<br>        cout << "An error in the information has been detected" << endl;<br>        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>        {<br>        if (_hoursWorked < 0)<br>                {<br>                cout << "Number of hours can not go below 0" << endl;<br>                cout << "Please enter the correct hours: " << endl;<br>                valid = 0;<br>                }<br>        else if (_hoursWorked > 60)<br>                {<br>                cout << "Number of hours can not exceed 60 hours" << endl;<br>                cout << "Please enter the correct hours: " << endl;<br>                valid = 0;<br>                }<br>        else<br>                valid = 1;<br>        }<br>return setHourlypay (_hoursWorked);<br>};<br><br>/*****************************************************************/<br><br>double employee::inputValidSales(double _sales)<br>{<br>        //Validation of sales, between 0 and 1000,000<br>bool valid = 0;<br>while (valid = 0)<br>        {<br>        if (_sales < 0)<br>                {<br>                cout << "The amount of Sales can not go below 0" << endl;<br>                cout << "Please enter the correct Sales number: " << endl;<br>                valid = 0;<br>                }<br>        else if (_sales > 100000)<br>                {<br>                cout << "The amount of Sales can not exceed $100,000" << endl;<br>                cout << "Please enter the correct Sales number: " << endl;<br>                valid = 0;<br>                }<br>        else <br>                valid = 1;<br>        }<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>        {<br>        if (_salary < 0)<br>                {<br>                cout << "The amount of Salary can not go below 0" << endl;<br>                cout << "Please enter the correct Salary number: " << endl;<br>                valid = 0;<br>                }<br>        else if (_salary > 100000)<br>                {<br>                cout << "The amount of Salary can not exceed $1,000" << endl;<br>                cout << "Please enter the correct Salary number: " << endl;<br>                valid = 0;<br>                }<br>        else <br>                valid = 1;<br>        }<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>
-
- Inmate
- Posts: 128
- Joined: Sun Jan 27, 2002 4:17 pm
Re: Program 2, Object Not Seeing It Self
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>
- XMEN Gambit
- Site Admin
- Posts: 4122
- Joined: Thu Nov 18, 1999 12:00 am
Re: Program 2, Object Not Seeing It Self
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>
-
- Inmate
- Posts: 128
- Joined: Sun Jan 27, 2002 4:17 pm
Re: Program 2, Object Not Seeing It Self
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>
- XMEN Gambit
- Site Admin
- Posts: 4122
- Joined: Thu Nov 18, 1999 12:00 am
Re: Program 2, Object Not Seeing It Self
<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>