Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are given names, last then first (each at most 30 characters long), and one

ID: 3629927 • Letter: Y

Question

You are given names, last then first (each at most 30 characters long), and one integer (represents grade). You expect no more than 100 records. Sort these using an insertion sort (sorted by last name, then by first name when the last names are the same) and display. Also display a histogram and class average (integer arithmetic).

SAMPLE INPUT: SAMPLE OUTPUT:
frog freddie 60 List of names sorted:
duck donald 65 65 duck donald
mouse minnie 95 60 frog freddie
mouse mickey 73 71 ghost casper
ghost casper 71 85 mouse abby
mouse abby 85 73 mouse mickey
95 mouse minnie

Histogram of grades:
0--> 9:
10--> 19:
20--> 29:
30--> 39:
40--> 49:
50--> 59:
60--> 69: **
70--> 79: **
80--> 89: *
90--> 99: *
100--> 100:
Average grade: 74
**************************************************************************************************
This is what I have so far:

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

int const MAXSIZE = 100; // maximum number of records in total
int const MAXLENGTH = 31; // maximum string length
int const MAXGRADE = 100; // highest possible grade
int const LOWGRADE = 0; // lowest possible grade
int const HISTOGRAMSIZE = (MAXGRADE-LOWGRADE)/10 + 1; // grouped in tens

struct StudentType { // information of one student
int grade; // the grade of the person
char last[MAXLENGTH]; // last name (MAXLENGTH-1 at most)
char first[MAXLENGTH]; // first name (MAXLENGTH-1 at most)
};

//------------------------------- main ----------------------------------------
int main() {
StudentType students[MAXSIZE]; // list of max of MAXSIZE number of students
int size = 0; // total number of students
int histogram[HISTOGRAMSIZE]; // grades grouped in tens
int average = 0; // average exam score, truncated

// creates file object and opens the data file
ifstream infile("data1.txt");
if (!infile) {
cout << "File could not be opened." << endl;
return 1;
}

// read and sort input by last then first name
bool successfulRead = sortInput(infile, students, size);

I NEED HELP WITH THE INSERTION SORT CODE AND CREATING AND DISPLAYING THE HISTOGRAM IN C++. Thanks in Advance

Explanation / Answer

Hi, You need the insertion part only? by using std::functions it should be like this: for (auto j = students.first(); j != students.last(); ++j) std::rotate(std::upper_bound( students.first(), j, *j), j, j+1); If you want my code that I did 3 months ago I would send you as a private message. It is different than your code but works.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote