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:
- Basic user input/output
- Conditional statements and boolean values
- Loop structures
- Functions
- Using handin35
- Course syllabus and policies
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
- 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
- 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.
- 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.
- Written Response: In a file called README, answer
the following questions to test your understanding of course policies:
- How many late days are allowed for the entire semester?
- 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?
- If you are encountering a problem with your program, what must you
do before asking either a ninja or faculty member for assistance?
- 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.
- Email the professor
- Attend a ninja session
- Post a question on Piazza
- Ask a student ninja that you run into around campus
- Work on the problem with your lab partner
- Ask a fellow student who is not your lab partner
- See either instructor during office hours
- See either instructor during non-office hours when their door is open
- 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:
- Each file should contain a top-level block comment explaining
the purpose of the program. It should also contain your name
- Each function should contain a comment block explaining the functions
purpose as well as all inputs (i.e., parameters) and outputs (i.e., return
values)
- Any non-obvious code should be commented. But don't over do it.
- Comments should be concise
- Variable names/function names should be meaningful and follow
conventions learned in CS21
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.