CMSC 246 Systems Programming
Code should follow the conventions described in https://cs.brynmawr.edu/Courses/fall2019/style.html
This document is written for Java. Adapt as necessary for C
Due Friday, September 13, 2019 before 11:59 PM
Create a directory Assignment1 in your cs246 directory. This is where you will create all your programs from this assignment.
Adding two numbers
Write a program in file
that asks the user for two numbers (just use
int variables) and then prints their sum. Here is an example session, with user-entered numbers in boldface:
Enter a number:
Enter a number:
4 + 7 = 11
This program can be compiled with
gcc -o add2 add2.c and run with
Computing an Amortization Table
Write a program to calculate (and display) a loan amortization table.
The program should ask users for 3 floats: the loan amount, the annual interest rate, and the monthly payment. Assume that payments are made on the last day of the month, interest accrues monthly, every month has exactly the same number of days and that a year has exactly 12 months.
For example, given a loan amout of $100, an annual interest rate of 10% and a monthly payment of $30, your amortisation table should look like:
pmnt pmnt Int Balance
Num amt Accru Remain
----- ------ ----- -------
0 0.00 0.00 100.00
1 30.00 0.83 70.83
2 30.00 0.59 41.42
3 30.00 0.35 11.77
4 11.87 0.10 0.00
The interest accrued in period N is equal to the balance in periond N-1 * annual interest rate / 12. So, in the above table, the interest in period 1 equals 100 * (10/100) / 12 = 0.83.
Note that the payment in the last period may (will probably) be less than the payment in the preceding periods.
Your program should check user inputs for validity (e.g., the loan amount should not be negative).
You program should never enter an infinite loop.
NB: When you use
scanf("%d",...), you will read only the number that the user types in, not the newline after the number. So if you read a character later on, you’ll read the newline by mistake. The solution is to put a space in the format string before the
%c. As the first bullet on page 45 of the King book explains, this space character instructs
scanf to skip any whitespace, including a newline.
Scripting in Linux
Once done, you will need to show some sample runs of the three programs. In order to record the runs, you can use the Linux command
Go to your Assignment1 directory and enter the command:
script FILENAME where FILENAME is some obvious name. For instance: add2_script1
You will get your command prompt back. Next, run each of the above programs as you normally would. Once done, enter the command:
This will end your script session. If you now look a the contents of the session file, you will see that the entire interaction has been recorded in it (as a script!).
What to hand in:
All submission will be done using the subit script. Before submitting collect all of the following in a single directory. There shoudl be NOTHING else in the directory.
Do not submit compiled code Be sure to delete any compiled code before following the directions below
When you have everything ready in this directory go to the directory containing the one with the information you want to submit. For instance, suppose that the 10(ish) files specified above are in /home/YOU/cs246/a1. Then you should go to /home/YOU/cs246.
- README file. This is a file literally named README. This file should follow the format of https://cs.brynmawr.edu/Courses/fall2019/README.txt
- The two programs you wrote. There are probably in files named (
- Scripts showing some runs of your program: Two for add, two for amortization. The amortization tables should have 5-12 payments.
- A script for one run of your amortization table program showing the longest table you could create.
- A text file named question.txt or a pdf named question.pdf with a short answer for the following: suppose you changes the terms of the loan make the payment due on the first day of the month rather than the last. How does this affect the length of the table. Provide statistical evidence for your answer.
- A short 1/2-paragraph reflection on your thoughts about this assignment (how this assignment went for you, what went wrong, etc.). Name this file someting obvious like reflection.txt
Use the submit program as follows:
/home/gtowell/bin/submit -c 246 -p 1 -d a1
This will package up everything in the directory a1 and submit it under your login name along with a timestamp of your submission date.
Back to CMSC246 Home page