Please follow the instructions on the Homework and Documentation Guidelines.
The files you must submit are "h1p1.c", "h1p2.c" and "h1p3.c" for the first, second and third problems respectively. You must also submit script files for each program, namely "h1p1.scr", "h1p2.scr" and "h1p3.scr", which will contain your source code (display source code in the script with the "cat" program) and test runs of that code. These test runs must contains runs on our data files for the first two programs (see below), but you may also include additional tests of your own.
The purpose of this assignment is to acquaint you with the basics of using CSA, and to get you started writing simple C programs.
The terminal room is in B24 of MCS at 111 Cummington Street. Or, you can use the public terminal room down the hall in the same building.
There is a very nice on-line emacs tutorial which can be accessed by
typing the UNIX command "emacs" then Ctrl-h t
.
If you have a personal computer or primarily use another machine, you are welcome to work on programs on that machine. However we cannot help you with PC/Mac problems. I will use CSA to communicate with you and provide data for programs; you must be familiar with it and log on frequently to read messages and collect mail. Whatever you write must run on CSA so we can check your work.
We suggest that you try to write and run a couple of the programs from the book first just to get started. Or, if you like, you can do Part 1 below. Then, do the three programs in Part 2. They are the assignment that is to be turned in.
Perform the following tasks on CSA. (You will need to run "new" to request an account and wait for the account to be activated before you can proceed.)
/* * File name: age.c * Name: Steve Homer * Login name: homer * BUID: U123456789 * Assignment: 1 * Problem: 0 * Date: Jan 1, 1999 * * age.c calculates your age, using the current year and * the year of your birth. * */ /* * Inclusions */ #include <stdio.h> int main(void) { int birth_year, current_year = 1999; printf("\nIn what year were you born?\n"); scanf("%d", &birth_year); printf("\nSo you will have birthday number %d in %d.\n", current_year - birth_year, current_year); return 0; }
/cs/course/cs113/current/hw1
.
So, for example, if the input is 3800 seconds the output would be 1 hour, 3 minutes and 20 seconds.Notes: What do you do if one of these is 0 ? And how do you handle the plurals (e.g., second vs. seconds) in your output ? (See our sample outputs)
Note: Your program should loop through all the data until a -1 is found, signaling the end of the program. You should be able to input the data from a file which you create or just type it in at a terminal. You can find the data in the file /cs/course/cs113/current/hw1/data1.
You must submit source code file h1p1.c
and script file
h1p1.scr
for this problem.
The program should input each of these facts in the order shown, calculate the new balance and determine if it is negative, and print the account number and the new balance. If the new balance is negative then the program should also display the message "Your account is overdrawn."
Your program should enter a loop reading data, and should stop when a -1 is given as an account number. All amounts are given as whole dollar amounts, and thus, are integers. You can find the data in the file /cs/course/cs113/current/hw1/data2.
Note: Are debits and credits represented by positive or negative numbers (or both)? (See our sample inputs)
You must submit source code file h1p2.c
and script file
h1p2.scr
for this problem.
11001101.1011 = 1 * 2^7 + 1 * 2^6 + 0 * 2^5 + 0 * 2^4 + 1 * 2^3 + 1 * 2^2 + 0 * 2^1 + 1 * 2^0 + 1 * 2^-1 + 0 * 2^-2 + 1 * 2^-3 + 1 * 2^-4 = 205.6875
Your program should read the binary number as an integer (whole number
part) and a string (fractional part). Use the format "%d.%s",
with a dot between the %d and the %s (the %s refers to
a string variable). The fractional part is tricky and there is a set of hints discussing it.
The program only has to read in and convert one binary number. There
is no data file for this one. You should run your program on the
binary numbers 1011.001, 110110.0 , 11010.11111, 100.101, and 11011010.001101 and show
the answers your program gets in the script file.
Hint: Use division and modulus operations to extract the bits from the integer part of the number read.
You must submit source code file h1p3.c
and script file
h1p3.scr
for this problem.
Do not allow your work to be used by others:
Warning: If someone cheats by using your work, you will also be penalized.