CS1101C Lab 2 (Odd Week)

Simultaneous Equations

The deadline for this lab question is Friday 05 October 2007, 23:59:59 hours.

The name of your C program file must be called eqn1.c, files with any other name will not be marked.

Preliminary

For this lab, you will be asked to used your deductive and inference skills. We will present a sample data file (text input file) and a sample run on the data file. Study both the sample data file and sample run carefully, and write an equivalent working program which reads the data from the sample data file and produces the required output as shown in the sample run.

Data File

Assume that the sample data file (text input file) is always called eqn1.txt. The following are the contents of this sample data file. Study it carefully.

-2 -18 -12
16 15 -1
-4 17 0
17 -23 2
1 2 10
3 4 15
-5 -2 -17
10 5 -15
4 -6 7
8 -12 -18
1 2 3
-6 -12 -18

Sample Run

Assuming that the executable is eqn1, a sample run of the program is shown below. User input is denoted in bold. Follow the sample run precisely. Study the sample run carefully in relation to the sample data file given above.

$ gcc -Wall -lm eqn1.c -o eqn1

$ ./eqn1

Solving the following Simultaneous Equations:
    -2x -18y = -12
    +16x +15y = -1
The Non-integer solutions are: x = -0.767, y = 0.752.

Solving the following Simultaneous Equations:
    -4x +17y = +0
    +17x -23y = +2
The Non-integer solutions are: x = 0.173, y = 0.041.

Solving the following Simultaneous Equations:
    +1x +2y = +10
    +3x +4y = +15
The Non-integer solutions are: x = -5.000, y = 7.500.

Solving the following Simultaneous Equations:
    -5x -2y = -17
    +10x +5y = -15
The Integer solutions are: x = 23, y = -49.

Solving the following Simultaneous Equations:
    +4x -6y = +7
    +8x -12y = -18
There are no solutions.

Solving the following Simultaneous Equations:
    +1x +2y = +3
    -6x -12y = -18
There are infinitely many solutions.

$

Note and Ponder

  1. Assume that all user input is valid. No error checking is required.

  2. The data file always contains an even number of lines, with three integers on each line. The number of lines is unknown but it is always at least two, and it is always an even number. Assume that the first two integers in each line are always non-zero. Your program must work for other data files.

  3. The rint function found in <math.h> rounds a floating-point number to the nearest whole number. The function prototype is given as:
          double rint(double x);

  4. To compare floating-point values to the value zero, use the “close to zero” definition given in the lecture notes and the textbook, i.e. a value is “close to zero” if its absolute value is < 0.0001.

  5. If your program does not work as you expect (logical errors), use extra printf statements to print out all the values of your variables to aid in your debugging.

  6. Most importantly, have lots of fun programming!


This document, index.html, has been accessed 20 times since 25-Jun-24 11:57:13 +08. This is the 1st time it has been accessed today.

A total of 12 different hosts have accessed this document in the last 445 days; your host, 216.73.216.39, has accessed it 1 times.

If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.