Lab 6

Week of 10/19/04-10/25/04

150 Points

Averages and Medians

Due in lab week of 11/2/04

 

Objectives:

  1. Experience with file input and output
  2. Experience with arrays
  3. Practice top down design
  4. Practice bottom up coding and testing

 

Task:

 

Open and read a file with student’s scores for a semester.  Display a chart with the average and median scores for each section and each lab.

 

Example: CS 111 this semester has 7 sections and 10 labs.  The output will be a chart with 7 rows and 20 columns.  Seven rows for sections 1 to 7.  Two columns (average and median) for each of the 10 labs.

 

Note: The average is rounded up to the nearest integer you must write your own function int myCeil(double n) that takes say 1.01 and returns 2 or takes 1.0 and returns 1

 

The input file:

 

Name: “in.txt” you must use the name in.txt

First line 2 integers:

  1. The number of sections in the class <= 10
  2. The number of lab assignments in the class,  NumLabs <= 10

For Each Section

First Line, 1 Integer:  N The number of students in the section <= 50

For each Student

Student Id  L1  L2  … LNumLabs

 

Student Id: 4 digit integer

Labs scores: Integers 0 to 100

 

Example: A small class with 3 sections and 4 labs.

The first section has 4 students, the second 5 and the third 4

 

3 4

4

8591 87 60 82 64

1881 95 63 75 94

6758 71 56 72 63

7541 65 95 84 87

5

3690 88 86 99 68

3515 78 60 98 53

1534 91 95 65 81

2459 86 69 79 50

7047 70 61 63 71

4

6204 89 98 56 69

6437 92 67 95 87

2012 67 97 66 54

8147 90 50 63 100

 

 

 

Lab

1

Lab

2

Lab

3

Lab

4

 

A

M

A

M

A

M

A

m

1

80

87

69

63

79

82

77

87

2

83

86

75

69

81

79

65

68

3

85

90

78

97

70

66

78

87

 

 

Rules:

  1. You may not use global variables.
  2. No functions can be longer than 24 lines of code.
    1. Break your program up into logical small modules, and
    2. test each separately.
  3. You must use two double dimension arrays,
    1. int section[10] [50];  Where the rows are the labs and the columns are each student’s score;
    2. And either

                                                               i.      int output[10][20];  Where the rows are the sections, and the columns are the averages and the medians for the labs.

OR

                                                             ii.      int output[10][10][2]; output[x][y][z]

1.      where x is the sections

2.      y is the labs

3.      z =0 is the average and z=1 is the median

  1. Sort and swap must be in separate functions.
  2. You must write your own ceiling function as defined above.

 

Documentation

Don’t forget the usual documentation requirements.   The overall program needs a clearly stated purpose.  The program must have a header identifying the assignment, due date, programmer, etc.   Functions need stated purpose and pre- and post- conditions.

 

Sample Data File

You can test your program on the data file in.txt .

 

Plagiarism Reminder

Be careful that you aren’t copying code from anyone or allowing anyone to view your own code.  Be careful with hard copy and electronic copy.  You would be amazed at the number of plagiarism and complicity charges that arise when one person “loans” copy to another to “get an idea how to do it” only to have the recipient copy and submit the coded directly.  Discussion of ideas about solutions is okay – just don’t code together.