Lab 1: Designing Functions
Part A: Getting Started
Course web site:
http://www.ccs.neu.edu/home/vkp/1101-w03
Reading:
go to Course Reading - go to Design Recipe 1 - leave it open
Lab Notes:
Download Lab1.exe
Extract: get folder Lab1
Find Lab1.mcp - open it
CTRL/F5 - run the project
Evaluate areaOfCircle several times in GUI
Test areaOfCircle and record the results
Save console as .txt - print it: reliable 229
Part B: Writing Code
Writing a program:
Type in the following function:
/* compute the
perimeter of a rectangle, given the width and the height */
double perimeter(double
height, double width){
return (2 * height + 2 * width);
}
/* test the perimeter
function */
void perimeterTests(){
testHeader("Testing the perimeter function");
expected(100.0);
actual (perimeter(20.0,
30.0));
}
Print the source code.
Run the code.
Add more tests.
Try a couple of errors and see the messages:
omit ; after return
type : after return
misspell one of the variable names
omit one of the parentheses
Part C: Using Blackboard
Use the instruction sheet to sign up for Blackboard
Fill out the questionnaire and submit it.
Copy a program in Metrowerks and submit it.
Save all your work on a diskette and clean the hard drive.
Part D: Extras
Explore arithmetic - GUI with text input and eval button - like Interactions window
Design recipe for simple function
Primitive types: int, double, char, boolean
Explore relational and logical operators
Functions with if
Composition of functions