Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write C programs myrecord.h and myrecord.c to load record data from a mark data file, process the data by computing simple statistics, and then report

Write C programs myrecord.h and myrecord.c to load record data from a mark data file, process the data by computing simple statistics, and then report the processed information. The mark records are given by comma-separated values (CSV) format in file marks.txt. Processing the mark data is to compute the record count, the average, standard deviation, median of the mark score values, and letter grades. Reporting is to output results to a file like record_report.txt. It requires to use a sorting function of Q1 of your choice to compute the median. Specifically, myrecord.h contains the structure and function specs as follows, myrecord.c contains the implementation of the functions.

/* 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), and float median. */ /* 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 retrieves and stores all record entries in the RECORD array passed by records, and returns the number of record count. */ int import_data(char *infilename, RECORD *records); /* This function takes the RECORD array passed by records and the number of record count as input, computes the average score, standard deviation, median of the score values of the record data, and returns the results in STATS type. */ STATS process_data(RECORD *records, int count); /* This function takes output file name passed by outfilename, RECORD array passed by records, and STATS value passed by stats, and output stats information, and processed record data to files in required format. It returns 0 if all operations are successful, otherwise 0. */ int report_data(char *outfilename, RECORD *records, STATS stats);

myrecord.h

#ifndef MYRECORD_H #define MYRECORD_H typedef struct { char name[40]; float score; } RECORD; typedef struct { int count; float mean; float stddev; float median; } STATS; char letter_grade(float score); int import_data(char *infilename, RECORD *records); STATS process_data(RECORD *records, int count); int report_data(char *outfilename, RECORD *records, STATS stats); #endif

myrecord.c

 #include  #include  #include  #include  #include "mysort.h" #include "myrecord.h" #define MAX_LINE 100 char letter_grade(float s){ // your implementation } STATS process_data(RECORD *dataset, int n) { // your implementation } int import_data(char *infilename, RECORD *records) { // your implementation } int report_data(char *outfilename, RECORD *records, STATS stats) { // your implementation }

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] = "record_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(infilename, dataset);

if (record_count >=1) { STATS stats = process_data(dataset, record_count); printf("stats:value "); printf("count:%d ", stats.count); printf("mean:%.1f ", stats.mean); printf("stddev:%.1f ", stats.stddev); printf("median:%.1f ", stats.median);

printf(" name:score,grade "); int i; for (i = 0; i < record_count; i++) { printf("%s:%.1f,%c ", dataset[i].name, dataset[i].score, letter_grade(dataset[i].score)); } report_data(outfilename, dataset, stats); } else printf("no record"); return 0; }

marks.txt

Myrie,76.7

Hatch,66.5

Costa,45.1

Dabu,74.4

Sun,67.7

Chabot,80.4

Giblett,59.1

Suglio,85.7

Smith,60.1

Bodnar,93.6

Allison,67.7

Koreck,77.4

Parr,92.5

Lamont,98.1

Peters,82.3

Wang,98.1

Eccles,77.8

Pereira,80.3

He,85.7

Ali,88.0

output:

stats:value count:20 mean:77.9 stddev:13.5 median:79.1 name:score,grade Myrie:76.7,B Hatch:66.5,C Costa:45.1,F Dabu:74.4,B Sun:67.7,C Chabot:80.4,A Giblett:59.1,D Suglio:85.7,A Smith:60.1,C Bodnar:93.6,S Allison:67.7,C Koreck:77.4,B Parr:92.5,S Lamont:98.1,S Peters:82.3,A Wang:98.1,S Eccles:77.8,B Pereira:80.3,A He:85.7,A Ali:88.0,A

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

Why can't car dealerships simply keep paying based on past systems?

Answered: 1 week ago

Question

What online recruitment methods are available?

Answered: 1 week ago