Assignment #4, C Language Applications, Due Feb 26, ‘08

1.

At http://www.phanderson.com/morgan/ there is a file of numerical grades for a large class.  Copy this and then paste into a file on your PC; say g:\grades.txt.  Note that there are nominally 50 – 55 values.

 

Develop a function to open this file, read the numerical grades into an array and returns the number of grades;

 

     Int get_grades(float g[]);  // note this returns the number of fetched grades

 

Develop functions to calculate the arithmetic mean and the RMS_average.

 

     float calc_arithmetic_avg(float g[], int num_grades);

     float calc_RMS_avg(float g[], int num_grades);

 

Develop code which determines the number of ‘A’, ‘B’, ‘C’, ‘D’ and ‘F’ grades.  Note that this does not need to be a function.

 

2.

 

The arctan of a value can be expressed as;

 

\arctan x = \sum^{\infin}_{n=0} \frac{(-1)^n}{2n+1} x^{2n+1}\quad\mbox{ for } \left| x \right| \leq 1

 

 

Use this to calculate 25 angles for x = 0.0 to 0.707  to two, three, four and five terms.

 

Write this to a text file with a format;  

 

Angle(rads)        Two Terms   Three Terms    Four terms   Five Terms  Using  the Arctan function

 

Please pass in a copy of this text file.

 

Offer any conclusions you may have.

 

 

3.   Histogram.  Write a function which will simulate the rolling of dice the specified number of times and return a histogram in array form.

 

void roll_dice(int histogram[13], int number_of_rolls);

 

Write a function which calculates the fraction of rolls for each value;

 

void calc_fract(int histogram[], float proportion[], int num_vals);