Governor's Career & Technical Academy Arlington

CSC 215 Weekly Assignments: Week 15

CSC 215


Overview

I hope everyone had a restful Thanksgiving holiday and you've come back ready to start programming in C! After programming in binary, and then assembly langauge, I think you will greatly appreciate the usability and power that a higher level structured programming language like C gives us.

This will be an opportunity for those of you who struggled with the previous project to start fresh!

Friday, December 6th

Start of Class

Last Wednesday I said my homework was to investigate that problem I showed you with EOF not being found. It turns out that I had caused the problem by changing the type of the ch variable I was reading from int to char. This caused the problem because EOF is not a character! That link is to a wonderful blog post, by the way, well worth a quick reading.

We will discuss the problems assigned for homework, and then pair you up again and give you time to begin working on the new classwork / homework problems. A few programs I'd like to share include MYCOPY.C, PNUM.C, UCASE.C, and especially WRDLINE.C and WC.C.

I'll demo the last two of these and highly encourage you to study them!

Classwork / Homework / Evaluation

I ran the random pair program, which generated the following pairs for this next assignment:

Anfal and Ved
Turner and Trostin
Adonis and Cody
Caleb and Luis
Johan and Jamethiel
Anar and Marin
Parker and Issac
Akshay and Jeff (the fix was in on this one ;-)

We meet next on Tuesday, December 10th. Please come to class with working solutions to the following problems:

  1. Write a program in a file named CHRNUMS.Cto prepend each line of a text file with the number of characters in that line. Given a file named LINES.TXT with content:

    This is a file
    containing lines of
    different
    lengths.
    

    Running CHRNUMS LINES.TXT would print:

    15: This is a file
    20: containing lines of
    10: different
    8:  lengths.
    
  2. Complete Exercise 1-17 on page 28 of The C Programming Language. Use the reverse(s) function you complete in that exercise to write a program in a file named BACKWARD.C that takes a text file as a command line argument and prints out each line in the file backwards.

NOTE: Since I neglected to assign a due date to this, it will be evaluted (by commit history) along with the next assignment on Tuesday, December 10th.

Wednesday, December 4th

Classwork

As I started experimenting with more and more C programs, I quickly ended up with a mess of files on my I drive. I wanted to just run:

I>era *.*

to start fresh, but then I realized that this would remove all the files needed to compile C programs. And what if I wanted to work on drive J or drive D?

My familiarity with DOS files called batch files, which are similiar (if much less powerful) to Unix shell scripts led me to wonder if CP/M had something similar. It turns out it does. They are less powerful still than batch files (not surprisingly), but they can help us out here. They work with the SUBMIT command, and they use the file extention .SUB. Here is the source to CSTUFF.SUB:

PIP $1:=C:CC.COM
PIP $1:=C:CC2.COM
PIP $1:=C:CLINK.COM
PIP $1:=C:C.CCC
PIP $1:=C:DEFF.CRL
PIP $1:=C:DEFF2.CRL
PIP $1:=C:STDIO.H

Copy this file to your C drive. Then, if you want to use say drive J for compiling C programs, you can just run:

submit c:cstuff J

and it will copy the 7 files you need from drive C to J.

As I made my way through your repos this morning, I found the following programs we should share today: Parker and Caleb, Ved and Trostin, Cody (note: Cody does the checking for numeric string I was hoping for), Johan and Anar,

Far and away the top prize for best do it yourself solution goes to Jamethiel. Her's is the one you should study if you want to really learn C! My partner Akshay has another one you should review. Finally there is the one José Ejemplo wrote before I gave you this assignment.

It turns out file I/O is not very difficult after all. Using The Buffered File I/O Functions section on page 133 of the BDS C User's Guide, José Ejemplo was able to write MYCOPY.C. We will look over this in class before you begin work on your next assignment.

End of Classwork / Homework / Evaluation

Continue working with your same partner for this iteration. Complete as many of the following exercises as class time plus 90 minutes of homework time allow: Exercises 1-6, 1-7 and 1-8 on page 18, and 1-9, 1-10 and 1-11 on page 19 of The C Programming Language.

Your evaluation will be based on how well your git repo shows evidence of iterative development. A single commit of completed work will only earn you a D! This assignment is due at 11:59 pm on Thursday, December 5th so that I can evaluate it before class starts on Friday.

Monday, December 2nd

Classwork

The grade distribution for the assembly language programming projects was: A: 8, B: 3, and E: 4. I am fully aware how challenging it is to understand a computer at the level needed to write in assembly. Those of you who struggled will now get some welcome relief and an opportunity for a fresh start. Hopefully you at least gained an appreciation for the challenge. C provides enough abstraction of the machine that you will be able to write C programs without reference to the details of the hardware on which they are running.

We'll start class today by setting up a new development environment for learning C programming on CP/M using BDS C. I've created a tar zip file containing everything you'll need, and I developed step-by-step instructions for getting you through helloworld.c.

Read Hello World with BDS C and follow the steps until you have a running Hello, World! program.

Homework / Evaluation

I ran the random pair chooser, which gave us the following programming pairs for this first assignment:

Parker and Caleb
Johan and Anar
Issac and Anfal
Luis and Cody
Jamethiel and Turner
Ved and Trostin
Marin and Adonis
Akshay and Jeff

Your task is to write a program named CLISUM that takes a sequence of integer values at the CP/M command line and prints out their sum. An A submission should gracefully handle invalid input. Sample runs might include:

I>clisum 5 15 22 8
Sum is 50
I>clisum 1 1 1 1 1 1 1 
Sum is 7
I>clisum 5 15 icecream 8
OOPS! ICECREAM is not a number

In addition to the ARGS.C program I will share with you in class, you should use the ndigit discussion beginning on page 20, and the atoi discussion beginning on page 39 of The C Programming Language as resources.

This assignment is due before class starts on Wednesday! Pairs will have 5 minutes to present their solutions during the first part of class. Credit will only be earned if you have the presented source in your repo before class starts. Each of you must have it in your own repo to earn credit!