CS35 Lab 0: C++ warm-up

Due 11:59pm Sunday, September 8, 2013

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
    to
    be
    or
    not
    to
    be
    that
    is
    the
    question
    done
    
    In reverse:
    question the is that be to not or be to
    

  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 (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 a few lines and the major tasks should be placed in separate functions.

  4. 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. Post a question on Piazza
      4. Ask a student ninja that you run into around campus
      5. Work on the problem with your lab partner
      6. Ask a fellow student who is not your lab partner
      7. See either instructor during office hours
      8. See either instructor during non-office hours when their door is open
      9. Ask either instructor when you see them at Sharples enjoying ice cream.

General Requirements

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

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.