SlideShare a Scribd company logo
C-Program: Custom Library, Header File, and Implementation Files
I have this main.c file:
#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(). ");
}
But, the only thing that prints is
Enter the data file name: grades.txt
There are 400 grades read.
Then the program just stops, it does not print the min, max, mean, variance, or histogram. Any
ideas? Am I using the custom library wrong, the implementation files (for min, max, mean,
variance, and histogram) all check out with no warnings or errors.
Here is 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
And here is the grades file:
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
Using standard libraries like stdio and sdtlib.h and using stats.h a.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
Question 1 has already been posted to Chegg and I am waiting for the.pdf
PDF
CMIS 102 HANDS-ON LAB WEEK 6 OVERVIEW THIS HANDS-ON LAB ALLOWS YOU TO FOLLOW ...
PDF
Reaction StatisticsBackgroundWhen collecting experimental data f.pdf
PDF
#include stdafx.h#include iostream#include string#incl.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.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
Question 1 has already been posted to Chegg and I am waiting for the.pdf
CMIS 102 HANDS-ON LAB WEEK 6 OVERVIEW THIS HANDS-ON LAB ALLOWS YOU TO FOLLOW ...
Reaction StatisticsBackgroundWhen collecting experimental data f.pdf
#include stdafx.h#include iostream#include string#incl.pdf

Similar to C-Program Custom Library, Header File, and Implementation FilesI .pdf (20)

PDF
Below is my code for C++- I keep getting an error 43 5 C--Progr.pdf
PDF
Write a C++ program to get input of a data set of 14 double valu.pdf
PDF
So basically I worked really hard on this code in my CS150 class and.pdf
PPTX
one dimentional array on programming with C
PDF
C- Programming Assignment 4 solution
DOCX
Investigatory Project for Computer Science
DOCX
Cs pritical file
DOC
Comp 122 lab 6 lab report and source code
DOC
~ Project-student report-card.cpp[1]
PDF
PPS SSSSHHEHESHSHEHHEHAKAKHEHE12131415.pdf
DOCX
Data structures
PPT
C Language Unit-3
PPT
Unit3 jwfiles
DOCX
#include iostream#include cmath#include fstream.docx
PDF
Pointers in real life
DOCX
-- Reminder that your file name is incredibly important- Please do not.docx
PDF
DOCX
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
PDF
Please help. C++ The program is an interactive program th.pdf
PDF
The solution manual of programming in ansi by Robin
Below is my code for C++- I keep getting an error 43 5 C--Progr.pdf
Write a C++ program to get input of a data set of 14 double valu.pdf
So basically I worked really hard on this code in my CS150 class and.pdf
one dimentional array on programming with C
C- Programming Assignment 4 solution
Investigatory Project for Computer Science
Cs pritical file
Comp 122 lab 6 lab report and source code
~ Project-student report-card.cpp[1]
PPS SSSSHHEHESHSHEHHEHAKAKHEHE12131415.pdf
Data structures
C Language Unit-3
Unit3 jwfiles
#include iostream#include cmath#include fstream.docx
Pointers in real life
-- Reminder that your file name is incredibly important- Please do not.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
Please help. C++ The program is an interactive program th.pdf
The solution manual of programming in ansi by Robin
Ad

More from herminaherman (20)

PDF
Write an equation for the height of the point P above the ground as .pdf
PDF
Wild-type (WT) mice are irradiated, destroying all of their bone marr.pdf
PDF
Which of the following is considered to be a distributed denial of s.pdf
PDF
Which of the folllowing statements about the solubility of 1- propan.pdf
PDF
What type of mutation that impacts splicing is a significant contrib.pdf
PDF
What data indicate that all three germ layers are specified in the b.pdf
PDF
Unlike RNA, DNA containsA. adenine.B. uracil.C. phosphate grou.pdf
PDF
Use provided HTML file.Create JavaScript file to validate user i.pdf
PDF
Two four-sided dice are rolled. One die has the letters A through D..pdf
PDF
The job of a CODEC (CoderDecoder) is to Convert an analog voice si.pdf
PDF
Question 4 Constructive retirement is when A. P buys Ss common stoc.pdf
PDF
Private and Public Health are working together through many program .pdf
PDF
Name the two standards that are supported by major DBMSs for distrib.pdf
PDF
Material Manufacturing Name 3 ways that the properties of thermosett.pdf
PDF
Mean can be computed for variables with ordinal-level measurements..pdf
PDF
Let u_1, u_2 be finite dimensional subspaces of a vector space V. Sho.pdf
PDF
IV. Which compound would have the higher water solubility, tetrahydro.pdf
PDF
Interseting discussion topic,want to chime inDescribe a symbol .pdf
PDF
IN JAVA Write a program to create a binary data file named RandomInt.pdf
PDF
I wanna add the shape creator like rectangular , square , circle etc.pdf
Write an equation for the height of the point P above the ground as .pdf
Wild-type (WT) mice are irradiated, destroying all of their bone marr.pdf
Which of the following is considered to be a distributed denial of s.pdf
Which of the folllowing statements about the solubility of 1- propan.pdf
What type of mutation that impacts splicing is a significant contrib.pdf
What data indicate that all three germ layers are specified in the b.pdf
Unlike RNA, DNA containsA. adenine.B. uracil.C. phosphate grou.pdf
Use provided HTML file.Create JavaScript file to validate user i.pdf
Two four-sided dice are rolled. One die has the letters A through D..pdf
The job of a CODEC (CoderDecoder) is to Convert an analog voice si.pdf
Question 4 Constructive retirement is when A. P buys Ss common stoc.pdf
Private and Public Health are working together through many program .pdf
Name the two standards that are supported by major DBMSs for distrib.pdf
Material Manufacturing Name 3 ways that the properties of thermosett.pdf
Mean can be computed for variables with ordinal-level measurements..pdf
Let u_1, u_2 be finite dimensional subspaces of a vector space V. Sho.pdf
IV. Which compound would have the higher water solubility, tetrahydro.pdf
Interseting discussion topic,want to chime inDescribe a symbol .pdf
IN JAVA Write a program to create a binary data file named RandomInt.pdf
I wanna add the shape creator like rectangular , square , circle etc.pdf
Ad

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Lesson notes of climatology university.
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
01-Introduction-to-Information-Management.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Chinmaya Tiranga quiz Grand Finale.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Cell Structure & Organelles in detailed.
GDM (1) (1).pptx small presentation for students
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Final Presentation General Medicine 03-08-2024.pptx
Pharma ospi slides which help in ospi learning
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Lesson notes of climatology university.
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
human mycosis Human fungal infections are called human mycosis..pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Final Presentation General Medicine 03-08-2024.pptx
Cell Types and Its function , kingdom of life
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
O5-L3 Freight Transport Ops (International) V1.pdf
01-Introduction-to-Information-Management.pdf

C-Program Custom Library, Header File, and Implementation FilesI .pdf