|
|
| Author | Subject / Post |
Bigi
30 Jun 2004 08:19 |
Program Hints 6/29
Okay, due to the difficulty of the program I'll post some hints here. Some answers to common questions: 1. Why do I use char* and char[] instead of string, for strings? Reason is that, honestly, when we do C and C++ programs in college we usually use char* and char[], so it's really a matter of preference. As far as I understand it a "string" data type is really exactly the same as a char* or char[]. To find out more about how char* and char[] can be used as strings, read the last 2 pages of section 5.8 on your textbook, and that sample code. 2. #define means defining a constant. When you have: #define BOSS 1 #define MANAGER 2 #define WORKER 3 you are essentially using the numbers 1,2,3 to represent boss, manager and worker. With this, you can use the constant names to represent employee type. So later on in your code you can do something like: type = BOSS; if (type == MANAGER) ... and so on. It's like how PI is commonly defined as a constants when you first learn programming and you write a program that calculates area of a circle. You do: #define PI 3.14 ... area = radius * radius * PI; 3. always remember that the functions in the class can be modified. change the parameters if they don't fit your needs. add more functions if you need. remove some if you think you don't need some of them. honestly, some of the functions I have are pretty short, like 1 or 2 lines, I could very well have just removed the function. I just wanted to have more function to give you guys to start with so it's better understood how you would approach the problem. 4. you don't have to do a lot of error checking. if you have some, it'll be bonus points. that means, for example of the choice of a menu is between 1-4, you don't have to take care of the case that the user types in 5 or something. but of course it doesn't mean you can let a fired user login. Here's is the flow of the development of code, as how I did it. 1. Do main() first. All the main() function really has to have is to prompt for user login, check the user input string for a match in the staff[10] array. Each staff is an employee object, therefore having a "name" variable inside. You can use the getName() function in employee to compare. So something like: if (strcmp(staff[i ].getName(), input) == 0) // if matching would work. You basically have to put this in a loop, as long as the login name is not "exit", you continue. When a login user is found, call the printMenu for this user, something like staff[i ].printMenu(). 2. The printMenu() function prints the appropriate menu based on the employee type. Since this function is inside the class employee, each object will have a kinda "copy" of this function. you simply have to check the "type" variable to find out which employee type this currently is. so in your printMenu() function you can do something like.. if (type == BOSS) { //print menu for boss here } and so on. 3. Essentially, this is how many of the functions in the class works. Since all 3 types of employees use this same class, and thus have the same functions, depending on what type of employee they are, it may do different things. Some of them might only be used for one type of employee (such as requestPay), some are used in more than 1 (such as addEmployee). 4. In my code, after printMenu(), I take in the user's choice (1-4), then I pass this choice into processAction(). The processAction() function is kind of the central processing area of the program. Depending on the user type, it calls the appropriate functions. My processAction() is actually pretty long, because I did a lot of the stuff that I should've done in those other functions inside my processAction() instead. This is because of the way I setup the parameters of those other functions (which is why I told you guys, feel free to modify those functions' parameters and even take out or add more functions), I had to do a lot of processing first in processAction() before passing them onto the sub-function (kind of). 5. From this point on, you have the skeleton of the whole program down already. All you have to do next is to write these little functions that actually do the things specified. Faraaz mentioned it is confusing how addEmployee inside the employee class adds another new staff member like that, I explained it in the thread he posted how it works. Read that post for details.
modified: 30 Jun 2004 08:22 GMT |
Bigi
30 Jun 2004 08:27 |
PS
I'm sure I'm missing stuff that I didn't explain clearly. Ask away if you have any questions. |
Faraaz
30 Jun 2004 16:32 |
Thanks!
Thanks Bigi...that explanation was really helpful...especially staff[0].addEmployee() <- that kinda made everything click together and i know what you mean now...i was wondering how the staff array connects to the class before...but for anyone else having a problem figuring that out...think of it like...each element of the staff array is its own object in the class...therefore, when an employee is added, you dont have to create a new object, just rename the next element...because the array has already been created as objects of the class... does that make sense?? is that even whats supposed to be going on?!?! lol.
modified: 30 Jun 2004 16:33 GMT |
Bigi
30 Jun 2004 18:18 |
Yes
Yes, Faraaz, you are correct. |
jeffrey
30 Jun 2004 22:23 |
look @ me! i'm a girl
heh. cool icon. anyways .i friggin made a post and it got deleted cuz i'm "not a member" peice of ****. anyways. thanks for the hint bigi. i got questions about the printMenu().. if it's dependent on types, could i set it up with a bunch of if statements. ex. if (type == BOSS) cout << "option 1, option 2, option 3, option 4 etc..." <<; if (type == MANAGER) cout << "moption 1, moption2, moption3 etc..." <<; something like that.. it's just supposed to print the option screen right? for the processAction funciton.. Since this thing takes in int values, i'm assuming that it takes the users input from the printMenu options page and essesntially calls the function. similar to my first question, could i also set this up with a bunch of if statements? like,... if the type == BOSS, i have the set make the options 1, 2, 3 etc... call up the functions that correspong to the choice. if different types, i could make them call up different functions.. ok. am i shooting straight? <= that's soo funny, first time i heard that yesterday. thanks, doumoarigato, danke, gracias, xie xie, etc... -jbl |
jeffrey
30 Jun 2004 22:47 |
so...
so... in that sense, but printMenu is sorta like a void. doesnt' really return anything, just prints out stuff. |
Shyam
30 Jun 2004 22:57 |
weird error
I'm getting this weird error when i compile my program: Undefined first referenced symbol in file employee::employee[in-charge]() /var/tmp//ccHR3yii.o employee::setEmployee(int,float,int,int,char*) /var/tmp//ccHR3yii.o 1d: fatal: Symbol referencing errors. No output written to manage.out collect2: 1d returned 1 exit status anybody know what causes this error? |
jeffrey
30 Jun 2004 23:28 |
ahh
hmm. it's not 4:30 yet so you guys are prolly still teaching. i'll just keep going. hopefully i won't have to erase what i have written. |
Bigi
01 Jul 2004 00:56 |
Re: Jeff
your concepts are all correct. although, the way i did it, i had my printMenu() prints out the correct menu, and then also cin user's choice. i then take that choice integer and return it, so then that function alone takes care of the whole menu. once i get that integer back i pass it onto processAction(), and then everything is as you said. |
Bigi
01 Jul 2004 00:59 |
Re: Shyam
i think your problem is with not defining the employee constructor function and the setEmployee function yet. define these functions first: employee::employee() { } void employee::setEmployee(int etype, float esalary, int estatus, int ehours, char* ename) { } even if you havent written the functions yet, you can define them first and leave them empty, in order to have the code compile. |
jeffrey
01 Jul 2004 01:40 |
nice
this forum is soo sweet. lol. it works best when people CONTRIBUTE. haha. it's not like Aaron will eat us if we help each other. ...................right?.......... ok. anyone knows what is means to log out? does that just jump our ass back to main? |
jeffrey
01 Jul 2004 02:58 |
yo.
so... any ideas on the logout? |
Dan
01 Jul 2004 03:40 |
i need help!!!
i'm getting this error, and i dont' know why: employee.obj : error LNK2019: unresolved external symbol "public: __thiscall employee::employee(void)" (??0employee@@QAE@XZ) referenced in function _$E1 Debug/employee.exe : fatal error LNK1120: 1 unresolved externals thanks! |
jeffrey
01 Jul 2004 03:44 |
i see
employee::employee(void) <-- here's your problem. i'm guessing that you wanted to make your constructor a void... it's actually not a void. when you declare it.. you should do not need to specify the type. straight up : employee::employee() {bla bla bla} |
Bigi
01 Jul 2004 04:39 |
Re: Dan
also, from your error message, it seems like you're using a compiler other than g++. are you working on this at home with a windows C++ compiler like visual C++ or something? there are known compatibility issues between g++ and visual C++. i wouldn't really recommend using it. if you really want to work on your code with notepad at home or something, you can always use Secure File Transfer (comes with SSH) (same method to login, cory.eecs.berkeley.edu, your username and password), upload your source code, then compile with g++ from SSH. |
Dan
01 Jul 2004 05:52 |
Thanks!!
yeh, it's true, i've been using microsoft studio.net at home to do most of my hw. I still have some problems that i think it would show up even in vi, so it would be great if you could help me with them tomorrow...even though it' slike 11 now, n' EVERYONE should be sleeping for CLASS tomorrow... Thanks again! |
jeffrey
01 Jul 2004 05:54 |
it's 11 and i'm ready to sleep
lol. this program is darn long... anyone wanna help me out on set-ups for the logout.. ? i know that i'm supposed to make loging a big fat ass loop.... hmm. crap. i'll think of it tomorrow. help please. |
Faraaz
01 Jul 2004 06:09 |
i do it a bit differently
mmm... the way i do it is a bit different than you jeff...in processaction i have some switch statements, and if the case is 4 which i leave for the logout, i just put a break; in there...nothing else...actually, samantha gave me that idea, im not sure if it would work yet but im pretty sure it does. the login thing is in a loop, i think ill make it a while loop but when processAction(int choice) breaks out of the function, it asks them to login again...which is why i think this should work... and yeah, this program is pretty long but i havent walked into class with my homework done yet. and id like to do that so im staying up and finishing this program...i can sleep on bart :p (i almost missed my stop today, i woke up 5 seconds after the doors opened at the berkeley station , and the other day, i went all the way to fremont instead of getting off at my stop... )
modified: 01 Jul 2004 06:11 GMT |
faraaz
01 Jul 2004 22:50 |
woot
woot im done |
| Reply | Top |
|
0.044 sec
|