CSCI 160 lab 2: getting started

As mentioned in the incremental design section at the bottom of the lab exercise 2 page, it's useful to start simple and gradually flesh out your program.

Here we'll look at just the first few steps of one incremental example. First we'll creating a basic skeleton for our program (here I'm assuming the iostream library for I/O), then in the second phase we'll add the welcome function prototype, implementation, and call.

Part 1: bare skeleton, with preliminary design comments

We'll start with just the basic structure, with comments describing what we plan on adding and where.

#include <iostream>
#include <cmath>
using namespace std;

// our prototype for the welcome function would go here

// our prototype for the get user data function would go here

// our prototype for the calculation function would go here

// our prototype for the final display function would go here

int main()
{
   // declare our constant for the maximum user value

   // declare variables for the data value we'll process
   //    and for the calculated result

   // call the welcome function (no paramters required)

   // call the function to get user data, passing our constant as the parameter
   //    and storing the return value in our variable for the data to process

   // call the function to do the calculation, passing the variable for the
   //    data to process and storing the return value in the variable for
   //    the calculated result

   // call the final display function, passing both variables
}

// our implementation of the welcome function would go here

// our implementation of the get user data function would go here

// our implementation of the calculation function would go here

// our implementation of the final display function would go here

We can compile at this point, but running it won't actually do anything.

Next, we'll add the main routine's constant/variables, plus the welcome function's prototype, call, and implementation where we had the comments for them.

#include <iostream>
#include <cmath>
using namespace std;

// our prototype for the welcome function would go here
void welcomeUser();

// our prototype for the get user data function would go here

// our prototype for the calculation function would go here

// our prototype for the final display function would go here

int main()
{
   // declare our constant for the maximum user value
   const long MaxUserVal = 2047;

   // declare variables for the data value we'll process
   //    and for the calculated result
   long val2process, calcResult;

   // call the welcome function (no paramters required)
   welcomeUser();

   // call the function to get user data, passing our constant as the parameter
   //    and storing the return value in our variable for the data to process

   // call the function to do the calculation, passing the variable for the
   //    data to process and storing the return value in the variable for
   //    the calculated result

   // call the final display function, passing both variables
}

// our implementation of the welcome function would go here
void welcomeUser()
{
   cout << "Welcome to lab exercise 2" << endl;
   cout << "This program ... blah blah blah ..." << endl;
}

// our implementation of the get user data function would go here

// our implementation of the calculation function would go here

// our implementation of the final display function would go here

Now we can compile and run it, and we should see our welcome message displayed (then the program just ends).

We would continue in this fashion, maybe next adding the prototype, call, and implementation of the function to get the data from the user.