Question: Write a C program named myrecord.h to process and report mark records. The mark records are given by comma-separated values (CSV) format in file marks.txt.
Write a C program named myrecord.h to process and report mark records. The mark records are given by comma-separated values (CSV) format in file marks.txt. Compute the average, standard deviation, median of the scores, and letter grades, output results to a file named report.txt. myrecord.h contains the following:
/* Define a structure named RECORD to hold a person's name of 20 characters and the score of float type. */ /* Define a structure named STATS containing fields int count, float mean, float stddev (standard deviation). */ /* This function converts a float score to a letter grade according to ranges S=[90, 100], A=[80, 90), B=[70, 80), C=[60, 70), D=[50,60), F=[0,50), and returns the letter grade. */ char letter_grade(float score); /* This function imports record data from file of name passed by infilename, and stores all record entries in an array of RECORD dataset[], and returns the number of records. */ int import_data(RECORD dataset[], char *infilename); /* This function takes RECORD array dataset[] and number of records count, and outfilename. It computes the average score, standard deviation, median of the score values of dataset[], and returns the results by the STATS type. It also outputs name and letter grade to file of name passed by outfilename, using format "%s,%c " */ STATS report_data(RECORD dataset[], int count, char *outfilename);
Use the provided test program myrecord_main.c to your myrecord.c the screen output is like the following, the screen output is like the following, the output is like this report.txt. You are allowed to add auxiliary functions in myrecord.c such such as sorting function to compute the median.
Public test
gcc myrecord.c myrecord_main.c -o q2 q2 count:20 mean:77.9 stddev:13.5 median:79.1
myrecord.h
// your program signature #ifndef MYRECORD_H #define MYRECORD_H typedef struct { // your design } RECORD; typedef struct { // your design } STATS; char letter_grade(float score); int import_data(RECORD dataset[], char *filename); STATS report_data(RECORD dataset[], int n, char *filename); #endif myrecord.c
// your program signature #include #include #include #include #include "myrecord.h" #define MAX_LINE 100 char letter_grade(float s){ // your implementation } int import_data(RECORD dataset[], char *filename) { // your implementation } STATS report_data(RECORD dataset[], int n, char *filename) { STATS report = {}; if (n < 1) return report; // your implementation return report; } myrecord_main.c
#include
#include
#include
#include
#include "myrecord.h"
#define MAX_REC 100
int main(int argc, char *args[]) {
char infilename[40] = "marks.txt"; //default input file name
char outfilename[40] = "report.txt"; //default output file name
if (argc > 1) {
if (argc >= 2) strcpy(infilename, args[1]);
if (argc >= 3) strcpy(outfilename, args[2]);
}
RECORD dataset[MAX_REC]; // declare array of RECORD to store record data
int record_count = import_data(dataset, infilename);
if (record_count >=1) {
STATS stats = report_data(dataset, record_count, outfilename);
printf("count:%d ", stats.count);
printf("mean:%.1f ", stats.mean);
printf("stddev:%.1f ", stats.stddev);
printf("median:%.1f ", stats.median);
} else
printf("no data is found");
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
