CMSC 246 Systems Programming
Fall 2019
Assignment#1
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 add2.c
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: 4
Enter a number: 7
4 + 7 = 11
This program can be compiled with gcc -o add2 add2.c and run with ./add2
Computing an Amortization Table
Write a program to calculate (and display) a loan amortization table.
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
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 script.
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: exit
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.add2.c, amort.c)/home/gtowell/bin/submit -c 246 -p 1 -d a1This will package up everything in the directory a1 and submit it under your login name along with a timestamp of your submission date.