Write a complete C++ program using an array of structs to do the following: Read
ID: 3621577 • Letter: W
Question
Write a complete C++ program using an array of structs to do the following:Read an arbitrary but fixed number “n” of input records from the text file survey.dat each containing survey results consisting of a unique integer identifier for a customer followed by a single integer rating in the range 1-10 inclusive representing that customer's rating for a newly-marketed product. After all values have been read and stored, sort the table of values by customer ID and print to the text file results.out the following information:
(a) the table contents sorted by customer ID suitably labeled.
(b) the arithmetic mean of the ratings, suitably labeled.
(c) the harmonic mean of the ratings, suitably labeled.
(d) the median value of the ratings, suitably labeled (the array of survey information will need to be re-sorted prior to determining the median value, this time using the rating as the sort key).
(e) the mode of the ratings, suitably labeled, followed by a list of cus- tomer IDs whose ratings were equal to that mode value.
Hint: Set the value of "n" in your program to 30
Explanation / Answer
Dear, /Header file section #include #include const int n=30; struct custInfo { int custId; int rating; }; int main() { FILE *ifp, *ofp; struct custInfo month_info[n]; int i, arith_mean, harm_mean, median, mode; float arithmeticMean(struct custInfo arr[], int size); float harmonicMean(struct custInfo arr[], int size); if ((ifp=fopen("survey.dat", "r"))==NULL) { fprintf(stderr, "Can't open survey.dat for input. "); return 0; } if ((ifp=fopen("results.dat", "w"))==NULL) { fprintf(stderr, "Can't open results.dat for output. "); return 2; } for (i=0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.