CS 1005, C-term 03
Homework 1
Calculating change
Due: January 21, 2003 at 11:59pm
Assignment
Write a C++ program that takes as input the total amount of a customer's
purchases
and the cash
tendered by the customer, and outputs the change to be returned so that the
number of coins is a minimum.
Outcomes
After successfully completing this assignment, you will...
- be able to code a solution to a simple problem using the C++ programming language
- know how to use program development tools on the Unix system to create
an executable program from C++ source code
- understand how integer and floating point values are stored and
operated upon
- be familiar with the CS department documentation standard and be able to
adequately document programs for CS 1005
- know how to submit homework electronically using the turnin program
Before Starting
Read Chapter 0 and Chapter 1
Details about the Program
The solution to this problem requires an understanding of converting numbers
from one data type to another. Remember that variables of type float are
approximations, and that when C++ converts from float to int, it truncates
the decimal portion of the number. (You may find it necessary to round numbers
before converting from one type to another - a quick and easy way to round
off a positive number to the nearest whole number is to add 0.5, then truncate.)
Since this program deals with dollars and cents, you should output all
floating point numbers with two digits to the right of the decimal point.
See Floating Point Output Formats
on the class webpage for a discussion of this topic.
The only statements needed for this
program are declarations, input and output statements, and assignment
statements.
Sample Execution
This program will calculate your change, given the cost of your
purchases and the amount of money tendered. The minimum number
of coins will be returned in your change.
Enter the total amount of your purchases: $3.39
Enter the amount of cash tendered: $10.00
The cash to be returned is $6.61
The number of quarters returned is 2
The number of dimes returned is 1
The number of nickels returned is 0
The number of pennies returned is 1
Program terminating...
Include files
iostream allows you to use cin, cout, endl
iomanip allows you to use setprecision
Assumptions and restrictions
You may assume that the user of the program enters numeric values for the
amount of the purchases and the amount of money tendered. You may also
assume that the amount tendered is greater than or equal to the amount of
the purchases.
Program style and Comments
There's a lot more to programming than writing code that works.
A good program is well-documented. Each program must contain in the
comments your name and section number, and the date. The purpose of the
program should be stated. Declared variables need to be explained with brief
comments; use meaningful identifiers. Comments should be used to clarify
obscure sections of code, but be careful - over-commenting can be worse than
not including comments at all. Blank lines should separate major
sections of the program. Indentation should make the program easy to read,
and it should be used consistently.
Refer to
Documentation Guidelines
for specific guidelines on how to document your programs for this course.
Deliverables
All homework assignments must be turned in electronically, using the
turnin program,
which is accessible from any CCC connection. To
submit your program for grading, follow the steps outlined below:
- Create a typescript file: A typescript file is a file which
contains a transcript of a session at the computer. The program which allows
you to create typescript files is called script. To use script
simply type
script hw1.script
This will cause all the text that appears on the screen after script
is started to be stored in a file called hw1.script. To stop the
script program type the command
exit
You are required to submit with all homeworks a typescript file that contains
a transcript of the homework being compiled and run. For this assignment
you should create your typescript file this way:
>script hw1.script
Script started, file is hw1.script
>g++ -Wall hw1.cxx
>a.out
...the execution of your program...
exit
- Create a documentation file: Several years ago the CS department
approved a documentation format to be used for the external
documentation of programs developed in introductory CS courses. All assignments for CS 1005 must be documented according
to this format, and the documentation file
must be submitted
when you use turnin. Name your documentation file README. The documentation standard is described
fully on the Web page found
here
For this class, you must complete the following sections of the
documentation format:
- [Author] (Your Name)
- [Date]
- [Version] (1.0)
- [Project ID] (HWx)
- [CS Class] (CS 1005)
- [Programming Language] (C++)
- [Problem Description]
- [Program Assumptions and Restrictions]
- [Interfaces] (just the User section; describe the
format of the input expected by the program)
- [Implementation Details] (just the Variables section)
- [How to build the program] (g++ -Wall hw1.cxx)
- [Additional Files] (there are none for HW1)
- [Program Source] (it is sufficient to say, ``accompanies this
document'')
- [Results] (``accompanies this document'')
- [Test Procedures] (describe the process you used to determine that the program calculates the correct results)
- [References] (books, websites, people from whom you received assistance - see Academic Honesty Policy)
All other sections should be completed by filling in ``N/A''. A sample of a
C program documented using this
format can be found
here .
A template of the documentation format can be found
here
.
This template can be copied to your home
directory, where you can edit it in preparation for submission to turnin.
Please note that turnin accepts ASCII text files only, so you should
use an editor (like emacs on Unix or Notepad on a PC), not a word processor, when you create your documentation file
(in particular, do NOT use Microsoft Word).
- Use the turnin program: All homework must be submitted using the turnin program. You may not turn in your program on disk, by email, or as
a printout. The turnin program copies files to a directory from which
they will be graded by the TA's. To use turnin to submit a
set of files type
/cs/bin/turnin submit cs1005 project file1 file2 ... filen
where project will be the name of the assignment you are turning in
(either hw1, hw2,... or lab1, lab2...) and where file1 through
filen are the files you wish to submit. Whenever a file is submitted
via turnin, it is copied to the cs1005 turnin directory and the date and time of
the turnin operation are noted in the files. Any attempts to resubmit the
files will overwrite the previously submitted files. If you turn in your homework prior to the due date and
realize that
the program you submitted had errors, you may correct the errors and use
turnin again to turn in the corrected program. The old file(s) will be
overwritten by the new ones and the date and time of the second turnin will be
noted. The grader will see just the last submitted copy. To use turnin
for this assignment type:
/cs/bin/turnin submit cs1005 hw1 hw1.cxx hw1.script README
A message stating ``done submitting files'' should appear. You may verify
that all your files were successfully submitted with the command
/cs/bin/turnin verify cs1005 hw1
If you are not sure that your files were correctly submitted, ask a TA for help. You will be responsible for
submitting all your files on time; don't wait until the last minute
to use turnin. This assignment is due at 11:59 pm on Tuesday, January 21.
Grading
This assignment will be graded on 100 points. Point
values will be allocated as follows:
- Code style (30 points) - follow the guidelines given in
Documentation Guidelines. Submit
the source file using turnin.
- Documentation standard (30 points) - complete and submit README as
described above
- Correctness and Testing (40 points) -
Make sure that the program will generate the correct results, for all allowable
inputs. The program output should be formatted exactly like that shown in
the sample execution. Evidence of successful compilation and at least one
sample run should be provided by submission of the script file.