CS35 Lab 0: C++ warm-up

Due 11:59pm Sunday, January 25th, 2015

The goal of this lab is to introduce you to basic concepts in the C++ program language. Concepts you will be familiar with after this lab include:

Some of these programs may seem simple, but it is meant to prepare you for future labs and also to provide practice for in-class topics.

A skeleton directory for your solutions will appear in your cs35/labs/00 directory when you run update35. The program handin35 will only submit files in this directory. In later labs you may have the opportunity to work with a partner, but for this lab you should work on your own. Be sure that all solutions are placed in the cs35/labs/00 directory before submitting.

Exercises
  1. Loops and strings: In the file funStrings.cpp, complete a program that takes in a series of words from the user and outputs a string with the words in the reverse order. The loop should stop when the user enters "done". For example:
    $ ./funStrings
    Now
    is
    the
    winter
    of
    our
    discontent
    Made
    glorious
    summer
    by
    this
    son
    of
    York
    
    In Reverse:
    York of son this by summer glorious Made discontent our of winter the is Now
    

  2. For loops: In the file computeAvg.cpp, write a program that asks a user to enter up to 10 positive integers and computes the average. Your program should accomplish the following:
    • You must use a for loop and no while loops.
    • If the user enters 0 or less, the loop should end and compute the average of the preceding numbers. E.g., if the user enters:
      5
      10
      15
      -3
      
      you should report the average as 10
    • While the inputs are integers, your average should be allowed to take on any real value.

  3. Conditions, Loops, and Functions: In the file grade.cpp complete a program that obtains a user's numerical test score and outputs their letter grade (assume a standard conversion of 90 and above is in A; 80 up to 90 is a B, etc.). Your program should:
    • Ask the user to enter a test score (assume an integer)
    • Ensure the user enters a valid score (i.e., from 0 to 100). If not, repeat the question
    • Convert the score to a letter grade
    • Output the result
    • Your solution should employ functions and good design. That is, your main function should be simple and only a few lines of code. The major tasks should each be placed in separate functions.
  4. Below is some sample output of a correct solution. Your solution does not have to completely match this, as long as it correctly meets the requirements above.

    Sample Run

    ./grade 
    Welcome to the grade calculator
    
    Enter an integer between 0 and 100: 101
    
    Incorrect entry, try again: 99
    
    You earned a(n): A
    
    ./grade 
    
    Welcome to the grade calculator
    
    Enter an integer between 0 and 100: -10
    
    Incorrect entry, try again: 83 
    
    You earned a(n): B
    

  5. Written Response: In a file called README, answer the following questions to test your understanding of course policies:
    1. How many late days are allowed for the entire semester?
    2. Read the academic integrity policy. Is it acceptable to have an upper-level CS student look at your program to help figure out why it is not working?
    3. If you are encountering a problem with your program, what must you do before asking either a ninja or faculty member for assistance?
    4. If you are stuck on your program, rank the following support options by which you should attempt first. Note that some of these should never be attempted, so leave them off your priority list.
      1. Email the professor
      2. Attend a ninja session
      3. Ask a student ninja that you run into around campus
      4. Work on the problem with your lab partner
      5. Ask a fellow student who is not your lab partner
      6. See either instructor during office hours
      7. See either instructor during non-office hours when their door is open
      8. Ask the instructor when you see him at Sharples enjoying an ice cream

General Requirements

Your program should follow good coding practices. Specifically, each file should maintain the following properties:

The following code snippet is a example of good commenting style.
/* findMax
 *
 * Inputs: a,b,c: three integers we want to compare
 * 
 * Returns: the maximal input 
 */
int findMax(int a, int b, int c) {
  int max = a;  // initialize to first input

  // compare max to b
  if(b > max) {
    max = b;
  }

  // now compare max to c
  if(c > max) {
    max = c;
  }

  // return maximal element
  return max;
}

Submit

Once you are satisfied with your code, hand it in by typing handin35. This will copy the code from your cs35/labs/00 to my grading directory. You may run handin35 as many times as you like, and only the most recent submission will be recorded.