The topic of "function overloading" is crucial to a discussion of classes, especially when it comes to understanding constructors. When we covered functions, we glossed over section 3.20 in your textbook, but we need to revisit that now. So, please re-read section 3.20 sometime this week.
The idea of function overloading is similar to the idea of "multiple senses of a word" in the English language. Consider the uses of the word "rose" in the following three sentences:
In one sentence, "rose" refers to a flower. In another "rose" is the past tense of "rise", and in the third, "rose" refers to a color. The word "rose" by itself is ambiguous—capable of having multiple meanings. We "disambiguate" the word by looking at the surrounding context.
In the same way, a given "name" in C++ can refer to different functions. We can "disambiguate" the name by looking at context. The main idea of "function overloading" is that in C++ (unlike in plain C), a programmer may include more than one function with exactly the same name in the same program. This is called "overloading" the function name. So, for example, you can define two (or more) different functions that are both named "squared". However, each of the versions of the function must have different parameters. This is how the compiler can distinguish between the different functions when you make a function call. Again, the technical term is "disambiguate"; the compiler is "removing the ambiguity" that is created by having multiple functions with the same name, by using context: in this case, the number and type of parameters.
If possible, review section 3.20 of your textbook before proceeding (if you don't have a textbook handy, you can still proceed with the lab, but you'll find it easier if you get a chance to look over section 3.20). You can find the source code for the program from Figure 3.25 of your text in the lab08 subdirectory (filename: fig03_25.cpp). Copy this file into your account and run it.
Then, write your own program, according to these instructions:
int readInteger(void);
min, for example:
int readInteger(int min);
This function should check the value entered by the user; if it is less than min, print an error message, and ask the user to enter the value again. Repeat this process until the user enters a valid value, and then return that value as the result of the function.
CC -c readInteger.cc CC -c lab08b.cc CC readInteger.o lab08b.o -o lab08b
As part of your credit for lab08, complete step 1 of project 2. The submission and grading guidelines are the same as for project 2, so please reference those instructions: http://udel.edu/~pconrad/cisc181/05S/work/proj/proj2.html
For this part of the lab, go ahead and work in your project 2 subdirectory. Submit your p2s1.cc and p2s1.txt files, as per the instructions in the project 2 directory.
Note: these are sample deductions. They are not the only possible deductions.
Part 1. Overloaded functions 50 pts
- C++ correctness 15 pts
- readInteger.h 3 prototypes 3 pts
- no ifndef in .h, -2 pts
- readInteger.cpp 3 functions 9 pts
- main.cpp calls 3 functions 3 pts
- C++ style 10 pts
- misleading var names, -2 pts each
- Correct script 5 pts
- cat 3 files + Makefile, clean
- Correct Makefile, tar file 10 pts
- No .h dependencies, -3 pts
- tar file contains .o or executables -3
- Sufficiently test program 10 pts
Part 2. First steps of project 2 50 pts - C++ correctness 15 pts - C++ style 10 pts - Correct script/submission 15 pts - Sufficiently test program 10 pts