Assignment 0

CS 135: Computer Science I

Spring 2008

Outcomes/Objectives

  1. You will learn to use an Integrated Development Environment (IDE)
  2. You will learn to use two fundamental program organization constructs
    1. Sequence: Instruction execution in sequence
    2. Functions: Modules or black boxes that perform a useful task and that may be used repeatedly in your program

Using an IDE

You will see a link to a working program, "patternPrinter.cpp" on the class web page. This program prints a pattern of asterisks ('*') to the screen (standard output).

   *****
   *****
   *****

Copy, compile, and run this program.

Turning in instructions:

Print the output on the lab printer - you will turn this in as part of this assignment.

Plus Sign (+)

Modify the patternPrinter to print a plus sign. To do this, save your "patternPrinter.cpp" file to "plussign.cpp" and modify the function calls in main to produce a six line “plus sign” like the one shown below:

^^^**
^^^**
^******
^******
^^^**
^^^**

The carets (^) should be replaced with spaces ( ). We have used the carets above to make it easier for you to tell exactly how many spaces you need to be printing before printing asterisks.

When you look at your copied code, you will see that each space and each asterisk is printed as a result of specific function calls. The functions that we use are named printAsterisk and printSpace. There is also a printEndLine function, so that you can end the line you are on and start over on another. You will also notice that the code in the main function has comments that break the program into sections or modules, with each module focused on one line of output.

Turning in instructions

  1. While you are modifying, compiling, testing, and running your plus sign printing program, your work is likely to generate compilation errors. For at least one error, cut the error messages generated, paste them into a text program (e.g., MS Notepad) , then write in what you did to fix the error, and print this for handing in to your TA.  In the unlikely event that you do not accidently create an error, go ahead and force one. Remove a semicolon from one of the statements, or change the spelling of one of the functions.  In any event, you must turn in at least one example error and your way of fixing it for each of these exercises.
  2. Print the source code of your plus sign program and turn this in to your TA.
  3. Print the output of your plus sign program and turn this in to your TA

Pound Sign (#)

Now save your “plussign.cpp” file to “lbsign.cpp”, and change the code so that you generate the giant pound sign shown below.

^^^^**^^^**

^^^^*^^^^*

^**********

^^^*^^^^*

^**********

^^*^^^^*

^**^^^**

The carets once again indicate the number of spaces.

Turning in instructions

  1. As before, find (or create) at least one error during your compilation process, copy the error, paste it into a text editor, write down what you did to fix the error, print it out and turn it in to your TA.
  2. Print the source code of your pound sign program and turn this in to your TA.
  3. Print the output of your pound sign program and turn this in to your TA
  4. Answer the following two questions (type the questions and your answers) on a separate sheet of paper.
    1. How was your program structured?
    2. How was modularity used in your program? Did modularity help your program design process?

Extra Credit - Parameterized Function Use

This next part is optional, but you can get 10% extra credit for it, and it should be pretty easy for you to do.

Up to this point, you have been using void functions without parameters. This is a little arduous since you have to write a function for every space or asterisk. To make life a little easier, there are two more functions you can use called printAsterisks and printSpaces. There are two differences between these and the functions you have used thus far. First, they are spelled differently - they are plural. Second, they require some information to be passed to them so that they can do their task correctly. This information is called a parameter to the function. In this case, the parameter is an integer number (called a value parameter) that is passed to the function by placing the number between the parentheses in the call to the function.

What does the following code segment do?

// First Line
printSpaces(  3 );
printAsterisks( 5 );
printEndLine();
 
// Second Line
printSpaces( 3 );
printAsterisks( 5 );
printEndLine();
 
// Third Line
printSpaces( 3 );
printAsterisks( 5 );
printEndLine();

Verify your hypothesis by incorporating this code segment into a brand new program that you will place in a file called "sqr.cpp." Print the output, you will be turning this output in to your TA.

Now modify this program to print either a plus sign or a pound sign (your choice), exactly like the previous ones using the two parameterized functions. This program should be in a file called "partest.cpp".

Turning in instructions

  1. Print the source code in "sqr.cpp" and turn this in to your TA.
  2. Print the source code in "partest.cpp" and turn this in to your TA.
  3. Print the output from running the program in "sqr.cpp" and turn this in to your TA
  4. Print the output from running the program in "partest.cpp" and turn this in to your TA
  5. Answer the following two questions (type the questions and your answers) on a separate sheet of paper.
    1. How was your program structured?
    2. How was modularity used in your program? Did modularity help your program design process?

Turning in your lab assignment

Assume that this format will be used for all your laboratory assignments throughout the semester unless otherwise specified.

Turn in a Folder (Binder) containing:

  1. Cover sheet with:
    1. Assignment Number
    2. Your Section Number
    3. Your name
    4. Your TA's name
  2. Source code and executables on a rewritable CD or a memory stick with your name and section number written on the CS/Stick. This CD/Stick should contain:
    1. Source code files (patternPrinter.cpp, plussign.cpp, lbsign.cpp, sqr.cpp, and partest.cpp if you did the extra credit)
    2. Executables for each of the files above.
  3. For each of the sections in this assignment, a hardcopy of each of the printouts that are specified in the instructions for each activity.

Good Luck