Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lab Session-11 CSIT 121 Fall 2003 Using arrays in functions Programming Exercise.

Similar presentations


Presentation on theme: "1 Lab Session-11 CSIT 121 Fall 2003 Using arrays in functions Programming Exercise."— Presentation transcript:

1 1 Lab Session-11 CSIT 121 Fall 2003 Using arrays in functions Programming Exercise

2 2 Using Arrays in Functions By default, arrays are passed by reference to functions In order to protect the arrays, we add the keyword const before the data type in the prototype and heading of the function In the calling program,name of the array is used as the argument and in prototype and heading, we add a blank pair of square brackets after the array name We must send the size of the array or the number of elements to be processed to the function

3 3 Programming Exercise Due Sec1 Nov 18 th, Sec2 Nov 20 th A professor has requested development of “exam score analysis” software. Scores will be entered by the user within a function for 16 students. All the scores are in the range of 0 through 10. Your program should call a function to count the frequency of occurrence of each score and record it in a frequency array. A separate function should be used to compute the class mean and mode scores.Finally, a function is called to send all the scores, histogram, mean and mode to a file.

4 4 Programming Exercise Due Sec1 Nov 18 th, Sec2 Nov 20 th Please note that All the results are recorded in a text file You must use switch~case for multiple choices Do not use any global variables except for the constant definition lines #define CSIZE 16 and #define FREQ 11 so that you do not have to send the array sizes separately Use void functions You should initialize frequency array to zeroes You must develop a multi-file project

5 5 Programming Exercise Following are the contents of the result file: Scores of all 16 students Histogram (Bar chart) for frequencies of all the scores Mean and Mode scores

6 6 Sample Results Following are the sample scores to test your program: 2 5 3 8 2 3 7 2 9 10 5 9 4 3 2 0

7 7 Sample Results Following are the contents of “results.txt” file: Following are the scores Student ID#: 1 Scored 2 Points Student ID#: 2 Scored 5 Points Student ID#: 3 Scored 3 Points Student ID#: 4 Scored 8 Points Student ID#: 5 Scored 2 Points Student ID#: 6 Scored 3 Points Student ID#: 7 Scored 7 Points Student ID#: 8 Scored 2 Points Student ID#: 9 Scored 9 Points Student ID#: 10 Scored 10 Points Student ID#: 11 Scored 5 Points Student ID#: 12 Scored 9 Points Student ID#: 13 Scored 4 Points Student ID#: 14 Scored 3 Points Student ID#: 15 Scored 2 Points Student ID#: 16 Scored 0 Points

8 8 Sample Results The class mean score is: 4.625 The most repeated score is: 2 Here is the Histogram of Class Performance Each Numerical Score is Followed on its Line by its Bar Chart ________________________________________ 0:* 1: 2:**** 3:*** 4:* 5:** 6: 7:* 8:* 9:** 10:*

9 9 Demo Check Points Multi-file project Switch~Case for frequency count No global variables Results file contents match the sample results shown on slides 7 and 8 (If any of the above is not fulfilled, project demo is recorded as “Partial”)


Download ppt "1 Lab Session-11 CSIT 121 Fall 2003 Using arrays in functions Programming Exercise."

Similar presentations


Ads by Google