122 Lab week 8
Labs Start On the Hour
Please arrive at 026 Kla early enough to be seated and do the following:
- start FireFox, login to our Blackboard course site, open
Schedule > Class Calendar
- in the calendar, click the link for the
lab outline for the week
- start SSH, connect to shell.uoregon.edu, & open a File Transfer window
- start Visual C++ & open a project
If you arrive late, your lab instructor will not be able to take time away from the other students to fill you in on what you missed.
Lab Exercises: User-Defined Functions.
-
The structure of a program that contains a user-defined
function shows:
- the function is DECLARED prior to main() using a function prototype
- the function is CALLED by main()
- the function is DEFINED after main()
Example: isPrime.cpp
- Read the Philosopher's Stone of Programming, the Secret of the Software Arts.
- Create a file primeGT.cpp and add it to your project.
The isPrime predicate we covered in class is in a header file, isPrime-fn1.h.Copy it to your local host and store it in /122/include/isPrime-fn1.h.
Add an #include statement to primeGT.cpp that connects to /122/include/isPrime-fn1.h.
To test your include, add this statement to main(), then compile and run primeGT.cpp:
cout << boolalpha << isPrime(63521) << endl; // true
- pw-tester.cpp. Create this program to test a function named pennyWeight() that accepts a weight in pounds as an argument and returns the value of that weight as an equal poundage of pennies.
A penny weighs 2.5 grams. There are 28.47 grams/ounce.
Compile, test and debug pw-tester.cpp.
Add a function header comment to your program.
- qh-tester.cpp. Create this program to test a function namedquarterHeight()that accepts two arguments, feet and inches, that represent a person's height. The function returns the value of a stack of quarters of that height.
Get the facts you need from the U.S. Mint's coin specifications.
Compile, test and debug qh-tester.cpp.
Add a function header comment to your program.
- picAdilly.cpp. If time remains during, you are now ready to begin working on P4's picAdilly.cpp.
- Before you leave your lab, upload your .cpp files to /122/p4/ on shell.uoregon.edu.
The 122 Learning Environment
At the start of the term, your lab instructor will regularly stop and ask the question, "Can all of you hear me, especially in the back of the room? Can you understand what I am saying?"
It's important that you are able to follow along as the instructor presents material. If you cannot hear or understand what is being said, please raise your hand and say (polite always works) that you are having difficulty following the presentation. The lab instructor will appreciate your assistance.
Also, please keep in mind that your responsibility is to pay attention and follow the instructor's directions. In particular, you should not be reading email, surfing the web, visiting with other students, etc., during the lab. Save those activities for after the lab.