Free Essay

Analyzing the Catscat Program

In:

Submitted By versus123180
Words 420
Pages 2
Project 1- Analyzing the CatScat program

Focusing on learning objective 6 :Describe the mechanics of parameter passing, I found the most understandable information on the website, http://www.cs.usfca.edu/~wolber/SoftwareDev/C/paramPassing.htm.

The type of parameter passing that is going on within the following snippet of code is passing by value. It is passing by value because the value is sent to the function and the parameter itself is not changed. In this example notice how the parameters themselves can be used several times within the function without either one of changing.

//*** L6 int isDark ( int numSamples, int darkValue )
{
int i ; long sampleRead = 0L ;
//*** S13, S6 for ( i = 0 ; i < numSamples ; i++ )
{
sampleRead += ( long ) analogRead ( lightSensorChannel ) ;
}
//*** L9 sampleRead = ( 10L * sampleRead ) / numSamples ;
//*** S4 if ( sampleRead > ( darkValue * 10 ) )
{
return 1 ;
}
else
{
return 0 ;
}
}

Focusing on learning objectives L8: Describe the representation of numeric and character data and L10: Discuss the use of primitive data types and built-in data structures, I found the most understandable information on the websites:
L8 http://www.willamette.edu/~gorr/classes/cs130/lectures/data_rep.htm
L10 http://www.cppreference.com/wiki/data_types

For L8, Data representation refers to methods used to represent information stored in a computer. It can store different types of information such as numbers, text, different varieties of graphics and sounds. In our example we are using text. Text is being represented by assigning a unique numeric value for each variable name.

For L10, I found that this website not only introduces you to the basic data types, but also helps you in learning how to read the declarations. Three rules to understand these types of declarations are:
1. Start at the variable name ( buzzerOutputPin, lightSensorChannel, etc in our example)
2. End with the data type (int for our example)
3. Go right when you can, and left when you must. (we don’t have this in our example.)
In this example starting with the first line we realize that buzzOutputPin is an int, which contains the value 9. Of course this is pretty much all you can understand from the code perspective, not taking into account the hardware just yet.

//*** L8, L10 int buzzerOutputPin = 9 ; // Connected to speaker int lightSensorChannel = 0 ; // input from LDR (CdS cell) - goes to A/D converter int ledOutputPin = 12 ; // Turns on the green LED int solenoidOutputPin = 11 ; // Fires the spray can int irSensorPin = 10 ; // input from PIR sensor - detects heat from cat int enableSprayPin = 13 ; // Only activate the spray if this is low.

Similar Documents