Part a: Analysis of the C Programming Language
Using a word processor (required), write a short (2-3 pages) essay evaluating the C programming language. Present a section of one or two paragraphs for each of the following areas that we have been using to compare different programming languages:
You can, of course, add additional sections if you would like to address an aspect of the language that does not easily fall into one of the above categories. Each section should provide a brief summary of the facilities available in C, and then some critique and/or comparison of these facilities to those of other languages. There are a couple books on C in the library on reserve and on the internet; feel free to consult them but make sure that you clearly reference your sources.
|
and argue about the correctness of your answers, but of course you should write up your own answers. |
Part b: Required Programming Problem
In this problem, you will write a C program that reads in data from a text file, stores the data in a two-dimensional array, analyzes the data and places the results of this analysis in two one-dimensional arrays, and finally writes the results to a new text file.
The input data file was created using SimpleText and has the following contents:
1 30.0 60.0 50.0
2 20.0 70.0 40.0
3 40.0 100.0 60.0
4 30.0 50.0 60.0
5 20.0 50.0 40.0
6 50.0 80.0 60.0
7 30.0 100.0 40.0
8 20.0 60.0 50.0
9 30.0 70.0 50.0
10 100.0 80.0 80.0
11 30.0 50.0 50.0
12 20.0 70.0 50.0
13 40.0 70.0 100.0
14 40.0 50.0 60.0
15 30.0 50.0 40.0
16 50.0 80.0 70.0
17 100.0 50.0 40.0
18 20.0 60.0 40.0
19 40.0 70.0 50.0
20 40.0 90.0 100.0
A copy of this file can be downloaded from the CS file server on Celeste ( in the Science Center zone under the Chooser). On the file server, there is folder named CS 251, and inside this folder is the above SimpleText file, named data.txt. You should place this file inside the same folder that contains your C project and code.
Imagine that the above data was obtained from 20 subjects who participated in a psychological experiment. Each subject made three responses in the task, which are listed in the three columns of the file as floating point numbers in the range from 0.0 to 100.0. Only the responses in the range from 0.0 to 90.0 are valid responses -- the appearance of a 100.0 in the data file indicates an invalid response in the task that should not be included in the analysis of the data.
Your code should include at least three different procedures: (1) read_data(), which reads data from the text file into a two-dimensional array and records the number of lines of data in the file, (2) analyze_data(), which processes the data to produce results that are stored in two one-dimensional arrays, and (3) write_data(), which writes the data and results to a new output file. Finally, you will need a main() procedure that calls these three procedures.
You should place the following include statements at the top of your program:
#include <stdio.h>
#include <stdlib.h>
For simplicity, you can declare the three arrays and the total number of data lines in the input file as global variables at the top of your program (after the include statements, and before the procedure definitions). The two-dimensional data array should have a second dimension of size 3, for the 3 columns of data, and a first dimension that is sufficiently large to accommodate any reasonable data file. The two one-dimensional arrays will store the average of each row of data, and the average of each column of data, respectively. The following are some further constraints on how you should construct the three procedures:
read_data() should prompt the user for the name of a file to be used as the input data file. The loop for reading in the data should be constructed so that it can accommodate any number of lines of data in the file (i.e. it should not assume that the file contains exactly 20 lines of data). The loop should keep track of the number of data lines, and set the global variable storing this information to the appropriate value when the reading of the data file is complete.
analyze_data() should process the data in the data array to obtain the average of each row of data and average of each column. When a value of 100.0 is encountered, it should not be included in the averages. The resulting average should be placed in the two one-dimensional arrays described above.
write_data() should write the data and results into a new text file so that it appears roughly in the following format:
subject reply1 reply2 reply3 average
0 30.0 60.0 50.0 46.67
1 20.0 70.0 40.0 43.33
2 40.0 100.0 60.0 50.00
3 30.0 50.0 60.0 46.67
4 20.0 50.0 40.0 36.67
5 50.0 80.0 60.0 63.33
6 30.0 100.0 40.0 35.00
7 20.0 60.0 50.0 43.33
8 30.0 70.0 50.0 50.00
9 100.0 80.0 80.0 80.00
10 30.0 50.0 50.0 43.33
11 20.0 70.0 50.0 46.67
12 40.0 70.0 100.0 55.00
13 40.0 50.0 60.0 50.00
14 30.0 50.0 40.0 40.00
15 50.0 80.0 70.0 66.67
16 100.0 50.0 40.0 45.00
17 20.0 60.0 40.0 40.00
18 40.0 70.0 50.0 53.33
19 40.0 90.0 100.0 65.00
average 32.22 64.44 51.67
As you can see, the original data is replicated in the output file, and the row and column averages are added, along with some text labels. The write_analysis() procedure should prompt the user for the name of a file to use -- this file will be placed in the same folder as the project and code, and can be viewed later with SimpleText.
When the main() procedure has finished its analysis, it should print a message to the user indicating that the processing is complete.
Hand in a hard copy of your C code file, and also drop off your entire folder (containing the code, project and text files) electronically. In the CS 251 folder on Celeste, there is a folder named drop where you can copy your solutions. You will see a belt on the drop folder -- just drag your solution folder onto the icon. A message will appear indicating that you do not have access privileges to see files inside the folder -- just click on ok, and your file will be dropped off.
Optional Programming Problem (for Extra Credit)
Write a C program that defines a new variable type that is a structure containing two components: a name string and a phone number. Also define a type that allows you to create a linked list of these structures. Construct a loop that continually prompts the user for a new name and phone number tobe added to the list, until the user indicates that they are done. After the user enters each name/phone number pair, a new structure containing this information should be added to the list. The malloc function should be used to allocate space dynamically for this new structure. After the user has finished entering all the names and phone numbers, the program should loop through the list and print out all of its contents in the output window.