In Lab: Week 1


Run update35 to download class files. Then cd into this week's directory.
$ update35                           # download updates
$ cd                                 # go to home directory
$ cd cs35                            # go to the cs35 directory
$ pwd	          
  /home/your_user_name/cs35

$ cd class                           # go to the class directory 
$ pwd		
  /home/your_user_name/cs35/class

$ cd 01                          # go to this week's directory
$ pwd           
  /home/your_user_name/cs35/class/01

You should see several files:

$ ls
array1.cc  forLoop1.cc	 function2.cc  whileLoop1.cc
array2.cc  forLoop2.cc	 hello.cc      whileLoop2.cc
array3.cc  function1.cc  hello.py

  1. To begin, start a new file firstProg.cc. The goal of this excercise is to practice using different data types, and basic control flow. Be sure to implement one step at a time, save, compile, execute, and test it. This will you give repeated practice at the edit/recompile/execute/test cycle. You'll learn to love it. Or possibly not.

    1. First, get your program to ask the user to enter their first name, then say hello to the person, such as "Hello Ameet".

    2. Ask user to enter their birth year, then calculate their approximate age.

    3. Ask for gender of user. Output a summary of the user's bio.

    4. More advanced exercise if you finish early. Ask user to enter their height in feet and inches, then compare their height to the average height for females (63.8 inches) or males (69.4 inches), report the percentage difference.

  2. Next, we will look at function1.cc and function2.cc to see examples of functions. Trace through the code, keeping in mind that C++ uses pass by value to copy parameters.

  3. Add a function to function1.cc to calculate whether the average score is an A or not. The prototype (or declaration) for your function be:
    	bool isAnA(float avg);
    	
  4. We will trace through a few examples of using arrays. In array2.cc, complete the minimum function to return the smallest value in the array.

  5. In array3.cc, implement the function increment, and notice how pass-by-reference maintains any changes to a function.

  6. Spring 2011 CS21 Lab 1, exercise 2: Using C++ instead of Python, write a program cubes.cc that asks the user for an integer n and then prints all of the cubes between 1 and n inclusive. Compile and test your program.