SlideShare a Scribd company logo
Using standard libraries like stdio and sdtlib.h and using stats.h and stats.c and other files like
min.c max.c etc. along with an external file grades.txt
along with these pictures is an output file for reference. Description Your task is to create a
personal library to implement a statistic package on any given data (assume that the data is
always of type float). To do this you must create: 1. a header file (stats h) with 5 function
prototypes: maximum() minimum. 0 equation: x yxij mean N-1 variance equation: o histogram0
2. five (5) implementation files with each of functions listed above min. c, max. c, mean C
variance C and histogram .c You will then write C code (main.c that asks the user for the data
file he/she wishes to compute the statistics for and displays the results to the user. YoU WILL
NOT WRITE ANY STATISTICS FUNCTIONS IN main.c you will simply call the functions
prototyped in stats h and coded in min. c max.c, mean C variance C and histogram. c Procedure:
Refer to textbook pg 669-6770 1. Create the header file stats.h a. Start with a block comment
summarizing the purpose of the header file b. define any constant that you need for the header
file (NOT YOUR CODE) c. Individual function prototypes (with introductory comments stating
purpose of each function) d. Save e. Below is the template for stats.h
Solution
//stats.h
#ifndef STATS_H
#define STATS_H
float minimum(float grades[], int Size); // NOTE: You need to complete the prototypes
float maximum(float grades[], int Size);
float mean(float grades[], int Size);
float variance(float grades[], int Size);
void histogram(float grades[], int ArrayCount[], int Size);
#endif // STATS_H
//min.c
#include
#include
#include "stats.h"
float minimum(float grades[], int Size)
{
int min = grades[0];
for (int i = 0; i < Size; ++i)
{
if(grades[i] < min)
min = grades[i];
}
return min;
}
//max.c
#include
#include
#include "stats.h"
float maximum(float grades[], int Size)
{
int max = grades[0];
for (int i = 0; i < Size; ++i)
{
if(grades[i] > max)
max = grades[i];
}
return max;
}
//mean.c
#include
#include
#include "stats.h"
float mean(float grades[], int Size)
{
float sum = 0;
for (int i = 0; i < Size; ++i)
{
sum = sum + grades[i];
}
return sum/Size;
}
//variance.c
#include
#include
#include "stats.h"
float variance(float grades[], int Size)
{
float sum = 0;
for (int i = 0; i < Size; ++i)
{
sum = sum + grades[i];
}
float avg = sum/Size;
sum = 0;
for (int i = 0; i < Size; ++i)
{
sum = sum + (grades[i] - avg)*(grades[i] - avg);
}
return (sum/Size);
}
//histogram.c
#include
#include
#include "stats.h"
void histogram(float grades[], int ArrayCount[], int Size)
{
for (int i = 0; i < Size; ++i)
{
if(grades[i] > 0)
{
if(grades[i] > 10)
{
if(grades[i] > 20)
{
if(grades[i] > 30)
{
if(grades[i] > 40)
{
if(grades[i] > 50)
{
if(grades[i] > 60)
{
if(grades[i] > 70)
{
if(grades[i] > 80)
{
if(grades[i] > 90)
{
ArrayCount[9]++;
}
else
ArrayCount[8]++;
}
else
ArrayCount[7]++;
}
else
ArrayCount[6]++;
}
else
ArrayCount[5]++;
}
else
ArrayCount[4]++;
}
else
ArrayCount[3]++;
}
else
ArrayCount[2]++;
}
else
ArrayCount[1]++;
}
else
ArrayCount[0]++;
}
}
}
// main.c
#include
#include
#include "stats.h"
int readGrades(char fileName[], float grades[]);
//Include this function prototype
void WelcomeToTheProgram();
int main()
{
///Declare Variables
char fileName[30];
float grades[1000]; //to store grades
int i, ArrayCount[10] = {0}; //to store histogram counts
/* Rewrite this line */
int num_grades; //for # of grades in file
///Call Intro Comment
WelcomeToTheProgram();
///Enter Filename
printf("   Enter the data filename: ");
scanf("%s", fileName);
//Get # of grades in file
num_grades = readGrades(fileName, grades); //get # of grades in file
///Print Results
printf("There are %d grades read ", num_grades);
printf("Mean = %f ", mean(grades, num_grades));
printf("Variance = %f  ", variance(grades, num_grades));
printf("Maximum = %f  ", maximum(grades, num_grades));
printf("Minumum = %f  ", minimum(grades, num_grades));
//Call histogram
histogram(grades, ArrayCount, num_grades);
//Print the histogram
printf("Grade Histogram ");
for (i = 0; i < 10; i++)
{
if (i != 9)
{
printf(" %d %% - %d %%: %d ", i * 10, ((i + 1) * 10) - 1, ArrayCount[i]);
}
else
{
printf(" 90 %% - 100 %%: %d ", ArrayCount[i]);
}
}
return 0;
}
///Reads all grades from the file to array
int readGrades(char fileName[], float grades[])
{
FILE *fpin = fopen(fileName, "r");
int num_scores = 0;
float value;
if (fpin == NULL)
{
printf("Cannot open the file ");
exit(0);
}
while ((fscanf(fpin, "%f", &value)) != EOF)
{
grades[num_scores] = value;
num_scores++;
}
return num_scores;
}
void WelcomeToTheProgram()
{
printf("***Welcome to the Program Which Involves a Custom Library***");
printf(" The program finds the minimum value, maximum value, mean,");
printf("variance, and a histogram of the grades of data by calling");
printf("implementation files min(), max(), mean(), variance(), and histogram(). ");
}
/*
compile: cc main.c min.c max.c variance.c mean.c histogram.c
run ./a.out
grades.txt
60.2
84.9
57.4
70.2
68.4
55.3
42.3
55.4
54.1
65.9
60.2
66.5
67.6
62.1
37.5
73.7
53.4
77.4
52.0
57.6
51.3
47.0
78.5
46.4
58.1
87.7
49.0
32.3
50.4
80.8
75.9
70.7
54.1
74.2
33.5
57.3
41.1
72.7
57.5
55.8
46.4
47.1
47.5
60.7
37.7
54.1
67.0
34.6
76.6
59.4
80.8
72.5
72.2
57.4
71.4
90.5
31.9
66.4
47.5
46.8
77.9
46.9
34.7
50.9
58.3
63.3
50.1
68.4
79.6
69.1
61.4
68.1
75.2
33.4
62.9
64.3
49.2
57.6
41.9
55.7
55.8
35.2
45.1
54.2
43.4
45.6
73.5
57.5
67.2
62.8
45.0
47.9
63.5
80.7
70.9
49.5
49.6
80.9
64.0
60.7
70.4
46.1
59.4
76.9
46.4
68.1
50.8
36.7
58.3
60.5
75.2
71.9
53.9
62.5
54.4
55.3
74.6
63.1
71.9
73.5
69.9
60.2
64.7
63.4
62.3
74.4
66.7
69.9
15.1
39.2
56.6
42.8
55.7
30.2
75.2
76.0
56.2
78.0
73.1
54.0
76.6
94.8
58.5
46.0
73.8
58.1
44.5
56.2
62.8
55.3
78.8
64.7
63.3
83.7
58.4
44.6
83.0
57.0
49.3
72.1
61.0
49.2
73.2
44.1
56.9
40.7
61.9
65.6
86.5
52.5
73.5
48.4
46.1
49.3
46.2
90.2
74.6
71.5
60.4
49.1
67.3
62.9
77.0
66.5
62.7
46.8
69.2
63.9
68.8
82.8
53.1
31.6
35.2
84.9
75.5
77.7
81.7
52.3
38.8
70.9
63.2
84.7
65.0
51.2
54.0
71.9
67.5
67.5
62.0
85.3
59.7
57.0
52.2
56.9
96.7
50.4
57.1
54.4
56.3
62.9
60.2
52.9
29.9
39.7
88.3
69.5
63.3
82.4
51.2
64.1
50.9
64.9
70.3
81.3
50.0
67.5
88.4
40.8
39.8
77.6
100.0
67.6
51.0
51.1
39.9
45.9
74.1
54.0
64.9
62.7
57.3
52.7
62.0
64.1
55.6
54.1
49.8
51.8
69.3
58.0
46.5
66.3
58.3
69.4
55.7
72.6
42.9
44.8
69.6
56.0
60.1
62.1
66.5
72.4
25.2
44.9
56.3
56.7
68.0
52.2
68.0
62.6
37.4
55.3
81.6
60.5
74.6
29.3
57.8
34.6
56.3
79.2
56.1
64.9
43.0
64.3
69.1
67.6
62.9
47.2
44.8
73.9
63.7
73.0
50.5
61.1
61.8
0.8
37.2
67.3
88.1
76.3
70.6
61.7
70.6
78.6
78.3
58.9
46.1
71.6
52.5
56.1
53.6
72.7
48.6
31.4
66.3
59.0
66.6
55.7
62.2
49.2
30.9
37.7
46.3
49.6
51.9
55.8
48.3
72.7
41.3
75.5
67.1
53.7
67.7
55.8
63.2
60.6
83.5
74.5
40.5
59.3
55.5
0.0
49.1
52.1
91.7
51.0
66.9
48.9
64.9
61.7
62.6
51.5
47.8
78.3
61.2
41.4
53.9
59.9
51.5
61.7
53.1
58.9
56.1
84.8
71.9
69.2
64.3
61.0
46.5
79.8
73.3
51.1
74.6
52.4
77.2
57.4
67.3
55.4
81.8
63.0
68.2
62.8
66.0
60.4
83.8
67.5
21.3
57.8
output:
***Welcome to the Program Which Involves a Custom Library***
The program finds the minimum value, maximum value, mean,variance, and a histogram of the
grades of data by callingimplementation files min(), max(), mean(), variance(), and histogram().
Enter the data filename: grades.txt
There are 400 grades read
Mean = 60.022758
Variance = 204.935898
Maximum = 100.000000
Minumum = 0.000000
Grade Histogram
0 % - 9 %: 2
10 % - 19 %: 1
20 % - 29 %: 4
30 % - 39 %: 24
40 % - 49 %: 59
50 % - 59 %: 105
60 % - 69 %: 108
70 % - 79 %: 67
80 % - 89 %: 24
90 % - 100 %: 6
*/

More Related Content

PDF
C-Program Custom Library, Header File, and Implementation FilesI .pdf
PDF
Background Sometimes the standard C libraries (stdio.h, stdlib.h, e.pdf
PDF
Program 1 (Practicing an example of function using call by referenc.pdf
DOCX
#include PA3Header.h#include stdafx.h Function r.docx
PDF
Write a C++ program to get input of a data set of 14 double valu.pdf
PDF
CMIS 102 HANDS-ON LAB WEEK 6 OVERVIEW THIS HANDS-ON LAB ALLOWS YOU TO FOLLOW ...
PDF
Question 1 has already been posted to Chegg and I am waiting for the.pdf
PDF
Reaction StatisticsBackgroundWhen collecting experimental data f.pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdf
Background Sometimes the standard C libraries (stdio.h, stdlib.h, e.pdf
Program 1 (Practicing an example of function using call by referenc.pdf
#include PA3Header.h#include stdafx.h Function r.docx
Write a C++ program to get input of a data set of 14 double valu.pdf
CMIS 102 HANDS-ON LAB WEEK 6 OVERVIEW THIS HANDS-ON LAB ALLOWS YOU TO FOLLOW ...
Question 1 has already been posted to Chegg and I am waiting for the.pdf
Reaction StatisticsBackgroundWhen collecting experimental data f.pdf

Similar to Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf (20)

PDF
#include stdafx.h#include iostream#include string#incl.pdf
DOC
Comp 122 lab 6 lab report and source code
DOCX
Cs pritical file
PDF
The solution manual of programming in ansi by Robin
PPTX
one dimentional array on programming with C
PDF
Educational Objectives After successfully completing this assignmen.pdf
PDF
Below is my code for C++- I keep getting an error 43 5 C--Progr.pdf
PDF
PPS SSSSHHEHESHSHEHHEHAKAKHEHE12131415.pdf
PPTX
Csci101 lect08a matlab_programs
PPT
C Language Unit-3
PPT
Unit3 jwfiles
PDF
PDF
C- Programming Assignment 4 solution
PDF
C programs Set 3
PDF
codes.txt.pdf code presentation engineering
PPTX
Csci101 lect08b matlab_programs
PDF
Develop a system flowchart and then write a menu-driven C++ program .pdf
DOCX
Data structures
PPT
Vectors Intro.ppt
DOCX
program in c
#include stdafx.h#include iostream#include string#incl.pdf
Comp 122 lab 6 lab report and source code
Cs pritical file
The solution manual of programming in ansi by Robin
one dimentional array on programming with C
Educational Objectives After successfully completing this assignmen.pdf
Below is my code for C++- I keep getting an error 43 5 C--Progr.pdf
PPS SSSSHHEHESHSHEHHEHAKAKHEHE12131415.pdf
Csci101 lect08a matlab_programs
C Language Unit-3
Unit3 jwfiles
C- Programming Assignment 4 solution
C programs Set 3
codes.txt.pdf code presentation engineering
Csci101 lect08b matlab_programs
Develop a system flowchart and then write a menu-driven C++ program .pdf
Data structures
Vectors Intro.ppt
program in c

More from fashiongallery1 (20)

PDF
For this lab you will complete the class MyArrayList by implementing.pdf
PDF
Discuss the character and impact of the economic and legal revouluti.pdf
PDF
Discrete Math -Use induction to prove. The city of Inductionapolis.pdf
PDF
Describe polarization and why it is important to WLANs.Solution.pdf
PDF
Describe the four basic elements of most communication systems.So.pdf
PDF
Can someone please help me figure out how to do this Required Resou.pdf
PDF
Assume that the Current Assets for Shine Co. as of Decebmer 31, 2011.pdf
PDF
All computer are configured for TCPIP connectivity. This exercise i.pdf
PDF
4. At what temperature will a solution of 8.27 g CaCl2 in 45.0 g H2.pdf
PDF
Briefly Explain all these points belowA. Marketing channels VS cha.pdf
PDF
Write a class that implements the BagInterface. BagInterface should .pdf
PDF
write an equation for the transformation of the graph of y =f(x) tra.pdf
PDF
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
PDF
Why are helper T-cells called helper cellsThey help pathogens i.pdf
PDF
Which of the following is NOT true of the Sons of Liberty a. New Yor.pdf
PDF
What made the Later Roman Economy so unstable (Bennette, Medieval E.pdf
PDF
What data would illustrate whether these underlying problems are occ.pdf
PDF
1. What are distinct characteristics of baby boomers, generation X, .pdf
PDF
VERSION The cells denoted by the letter Ain the figure to.pdf
PDF
The __________ is the preeminent organization for developing and pub.pdf
For this lab you will complete the class MyArrayList by implementing.pdf
Discuss the character and impact of the economic and legal revouluti.pdf
Discrete Math -Use induction to prove. The city of Inductionapolis.pdf
Describe polarization and why it is important to WLANs.Solution.pdf
Describe the four basic elements of most communication systems.So.pdf
Can someone please help me figure out how to do this Required Resou.pdf
Assume that the Current Assets for Shine Co. as of Decebmer 31, 2011.pdf
All computer are configured for TCPIP connectivity. This exercise i.pdf
4. At what temperature will a solution of 8.27 g CaCl2 in 45.0 g H2.pdf
Briefly Explain all these points belowA. Marketing channels VS cha.pdf
Write a class that implements the BagInterface. BagInterface should .pdf
write an equation for the transformation of the graph of y =f(x) tra.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
Why are helper T-cells called helper cellsThey help pathogens i.pdf
Which of the following is NOT true of the Sons of Liberty a. New Yor.pdf
What made the Later Roman Economy so unstable (Bennette, Medieval E.pdf
What data would illustrate whether these underlying problems are occ.pdf
1. What are distinct characteristics of baby boomers, generation X, .pdf
VERSION The cells denoted by the letter Ain the figure to.pdf
The __________ is the preeminent organization for developing and pub.pdf

Recently uploaded (20)

PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Institutional Correction lecture only . . .
PDF
Complications of Minimal Access Surgery at WLH
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
Classroom Observation Tools for Teachers
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Computing-Curriculum for Schools in Ghana
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
O7-L3 Supply Chain Operations - ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
A systematic review of self-coping strategies used by university students to ...
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
VCE English Exam - Section C Student Revision Booklet
Institutional Correction lecture only . . .
Complications of Minimal Access Surgery at WLH
Supply Chain Operations Speaking Notes -ICLT Program
Chinmaya Tiranga quiz Grand Finale.pdf
01-Introduction-to-Information-Management.pdf
Classroom Observation Tools for Teachers
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
RMMM.pdf make it easy to upload and study
Computing-Curriculum for Schools in Ghana
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf

Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf