C++ Function Assignment grade calculator - c++

my programming lecturer is teaching us how to write functions, terribly I might add, We are to make a program that calculates the grade of a students work. Here are the specs on it.
score 1 is weighted by 0.3,
score 2 is weighted by 0.5, and
score 3 is weighted by 0.2.
If the sum of the scores is greater than or equal to 85 then the Grade is an 'A'.
If the sum of the scores is greater than or equal to 75 then the Grade is a 'B'.
If the sum of the scores is greater than or equal to 65 then the Grade is a 'C'.
If the sum of the scores is greater than or equal to 50 then the Grade is a 'P'.
Otherwise the Grade is an 'F'.
So I wrote my code as follows:
#include <iostream>
using namespace std;
void calculateGrade() {
int score1, score2, score3;
int percentDec;
cin >>score1>>score2>>score3;
percentDec = (score1+score2+score3);
if (percentDec >= 85) {
cout << "The Course grade is: A";
}
else if (percentDec >= 75) {
cout << "The Course grade is: B";
}
else if (percentDec >= 65) {
cout <<"The Course grade is: C";
}
else if (percentDec >= 50) {
cout <<"The Course grade is: P";
}
else {
cout <<"The Course grade is: F";
}
} //end of calculateGrade()
int main() {
calculateGrade();
return 0;
}
Which works fine on my IDE but when I put it into the program which determines whether our answer is correct it doesn't work, that is because ordinarily we are asked only to put the stuff in main() but because it is a function and it's not in the main() it doesn't work like that. We are given this as an example and I'm about to throw something with how dumb this is. I don't know how to program it to work the way they want it.
cout << "The Course grade is: " << calculateGrade(90, 50, 99) << endl;
Cheers for any help.

This is not a forum for getting answers to your homework questions, although good job on showing what you have tried. Here are areas to look at:
1) The instructor is showing you that you can decompose code into functions. He/she wants you to wrtie a function calculateGrade that would work like this cout << "The Course grade is: " << calculateGrade(90, 50, 99) << endl;. Now every function declaration in C++ has three parts to it:
return_type functionName(param1_type param1, param2_type param2,...) {
// implementation
}
The functionName is what the function is referred to by (calculateGrade in this case), the parameters are the information you need to pass to the function for it to do its thing, and the return type is what the function will give back. In this case, your instructor is saying calculateGrade will take three integers as parameters and must return a string representing the grade of the student's scores. Thus your function should look like:
string calculateGrade(int score1, int score2, int score3) {
// ...
}
2) As the comments rightly pointed out, you aren't multiplying score1, score2, and score3 by their respective weights in the calculateGrade() method.
From your question and comments, I get the feeling your grasp of functions is not completely solid. Rather than complaining about your teacher (be it his/her fault or not), I suggest you read here about it. There are a plethora of online resources that will help you learn the basics of C++ programming.

You tutor is asking you to write a function which accept 3 parameter and return the grade.
char calculateGrade(int score1, int score2, int score3) {
char grade = 'F';
double percent = (0.3*score1 + 0.5*score2 + 0.2*score3);
if(...) {
grade = 'A/B/C/P'; // Depending upon condition, assign only value
}
else if(...) {
grade = 'A/B/C/P'; //Depending upon condition, assign only one value
}
// Add the condition in if else statements to get the actual grade.
return grade;
}
Note that the percent is of type double. You need to do all comparison in if else on double basis.

Related

New to C++ Looking for help revising a program by using arrays

I'm not expecting anyone to just hand me the answer, but I am looking for some guidance. For my C++ class we wrote a program last week where we had 5 judges each had a score that the user had to put in, then we needed to find the average without the highest and lowest score being used. I did this using loops and a lot of if statements.
Now my teacher asked us to go back and use arrays, and said we should be able to just modify the original code a bit, but to now have it so there can be 5 to 20 judges, the user should be able to input that number in. I'm just having a hard time figuring out which spots could be replaced with arrays.
I already have it where a person can put in the amount of judges, but I'm not sure how to put that in an array either, so judges is an unused variable at the moment.This is what my code looks like right now. Thanks in advance!
#include <iostream>
using namespace std;
//Function prototypes
void getJudgeData(double &x);
double findLowest(double ,double ,double ,double,double);
double findHighest(double,double,double,double,double);
void calcAverage(double,double,double,double,double);
double judges;
//Program begins with a main function
int main()
{
//Declare variables
double judgeScore1,judgeScore2,judgeScore3;
double judgeScore4,judgeScore5;
cout<<"Scores given by all five judges: \n\n";
//Function calls to get each judge data
cout<< "How many Judges are there? (Must be 5 to 20): ";
cin>> judges;
while(judges<5||judges>20){
cout<< "Sorry there must be 5 to 20 judges\n";
cout<< "How many Judges are there? (Must be 5 to 20): ";
cin>> judges;
getJudgeData(judgeScore1);
getJudgeData(judgeScore2);
getJudgeData(judgeScore3);
getJudgeData(judgeScore4);
getJudgeData(judgeScore5);
//Function call to obtain average
calcAverage(judgeScore1,judgeScore2,judgeScore3,
judgeScore4,judgeScore5);
//Pause the system for a while
}
}
//Method definition of getJudgeData
void getJudgeData(double &x)
{
//Prompt and read the input from the user and check //input validation
cout<<"Enter score of a Judge (you will do this 5 times): ";
cin>>x;
while (x < 0 || x > 10)
{
cout<<"ERROR: Do not take judge scores lower than 0 or higher than 10.Re-enter again: ";
cin>>x;
}
}
//Method definition of findLowest
double findLowest(double a,double b,double c, double d,double e)
{
double lowest;
lowest=a;
if (b<lowest)
lowest=b;
if (c<lowest)
lowest=c;
if (d<lowest)
lowest=d;
if (e<lowest)
lowest=e;
return lowest;
}
//Method definition of findHighest
double findHighest(double a,double b,double c, double d,double e)
{
double highest;
highest=a;
if (b>highest)
highest=b;
if (c>highest)
highest=c;
if (d>highest)
highest=d;
if (e>highest)
highest=e;
return highest;
}
void calcAverage(double a,double b,double c,double d, double e)
{
//Declare variables
double lowest;
double highest;
double sum;
double average;
//Function call to retrieve lowest score
lowest=findLowest(a,b,c,d,e);
//Function call to retrieve highest score
highest=findHighest(a,b,c,d,e);
//Calculate the total sum
sum=a+b+c+d+e;
//Subtract highest and lowest scores from the total
sum=sum-highest;
sum=sum-lowest;
//Calculate the average of the three number after
//dropping the highest and lowest scores
average=sum/3;
//Display output
cout<<"Highest score of five numbers:"<<highest<<endl;
cout<<"Lowest score of five numbers:"<<lowest<<endl;
cout<<"Average when highest and lowest scores are removed: "<<average<<endl;
}
Use an array to hold the scores of the judges rather than storing them in judgeScore1, ... , judgeScore5. The size of the array should be 20, which is the maximum number of judges:
double judgeScore[20];
The variable "judges" should be declared as "int", as it is the number of judges.
The functions should accept an array of double as parameter, rather than 5 double values. So, instead of:
double findLowest(double ,double ,double ,double,double);
the function becomes:
double findLowest(double s[]);
The body of the functions should use the variable "judges" as a limit of a "for" loop in order to perform the calculation.
Modify your functions to use arrays. For example, here's a get_max function for use in an array:
#include <iostream>
double get_max(double judge_scores[], int size)
{
double max = judge_scores[0];
for (int i = 0; i < size; ++i)
{
if (judge_scores[i] > min)
{
max = judge_scores[i];
}
}
return max;
}
Change all of your functions like that one. I coded up your problem and here's the main I got:
int main()
{
const int MAX_NUM_JUDGES = 20;
// make everything in the array 0
double judge_scores[MAX_NUM_JUDGES] = { 0 };
// make it return the "amount" of array you need- the number of judges
int num_judges = get_num_judges();
// fill the array up to that "amount"
// internally uses int get_judge_data() to get a score in the correct range
fill_score_array(judge_scores, num_judges);
// get the average. Internally, this
// - computes the sum
// - calls the max and min functions and subtracts those from the sum
// - divides that sum by (num_judges - 2)
// (because you're throwing away the max and min) and returns that.
double avg = calculate_curved_average(judge_scores, num_judges);
//print everything
std::cout << " Highest: " << get_max(judge_scores, num_judges) << std::endl;
std::cout << " Lowest: " << get_min(judge_scores, num_judges) << std::endl;
std::cout << " Avg when highest and lowest scores are removed: " << avg << std::endl;
// If you're not on Windows, don't use this :)
system("PAUSE");
}

Do while Loops not working

I've been recycling an assignment to further practice and develop my programming skills in my class and I'm having an issue with 3 DO WHILE loops within another Do While loop.
I'm trying to deny Test scores for test1, 2 and 3 that are less than 1 and greater than 100.
I'm encountering that the loops are not processing what I am inputting for Test1/2/3. It's allowing values out of the while range to pass through. Is there anyone who can suggest or see what I might be doing wrong? Thanks ahead of time guys!
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
double computeavg (int a, int b, int c);
char lettergrade (double z);
int main ()
{
double test1, test2, test3, average; //test1/2/3, test scores, Average: average of test scores
double tottest1=0, tottest2=0, tottest3=0, avg1, avg2, avg3; //tottest# - sum of test grades collected for that number test, avg# average for first second or third test
int student=0, avgvar; //average variable, Student number
char grade, ans; // Holds a letter grade, holds a response to a question
do{
student=student+1;
cout<<"Hello Student #"<<student<<endl;
do{
cout<<"Please input test 1 Grade ";
cin>> test1;
}
while(test1>=1||test1<=100);
do{
cout<<"Please input test 2 Grade ";
cin>> test2;
}
while(test2>=1||test2<=100);
do{
cout<<"Please input test 3 Grade ";
cin>> test3;
}
while(test3>=1||test3<=100);
average=computeavg (test1, test2, test3);
cout<<setprecision(0)<<fixed;
cout<<"Your Average is: "<<average<<endl;
tottest1=tottest1+test1;
tottest2=tottest2+test2;
tottest3=tottest3+test3;
grade = lettergrade(average);
cout << "Your grade is " << grade << endl;
cout<<"Do you want to grade another student? (y/n)";
cin>>ans;
cout<<"\n";
} while(ans=='y');
I think you need to change do while as below:
do{
cout<<"Please input test 1 Grade ";
cin>> test1;
}
while(test1<1||test1>100);
Your conditions are backward. Look carefully: while(test3>=1||test3<=100). All numbers satisfy at least a portion of the condition. For example, −4 is not greater than or equal to 1, but it is less than or equal to 100, and since your conditions are joined with the || operator, which is the or operator, the condition evaluates to true.
You need to change the condition. This is homework, so I won't tell you precisely what condition you should use instead.
You can use a debugger to discover this problem yourself. You can also discover it by carefully walking through your program by hand. Get a pencil and some paper, and write down the current values of your variables. Keep track of which instruction you're on, and then work your way through the program. When a variable changes, cross out its old value and write down the new one. Eventually, you'll be able to do that in your head, but while you're learning, it helps to just write it down.

Easy Grade Code with parameters

I am trying to make a function that has a int input parameter of a numerical grade and returns a letter grade with either a -, a +, or neither. I know how to do this without the use of reference parameters, but I am trying to use parameters and I am having some difficulty doing so.
One output parameter is the letter grade and the second output parameter is the + or - (+ if missed next grade by 1 or 2 points and - if just made the grade. Here is what I have:
#include <iostream>
using namespace std;
void letterGrade (int, float&, float&);
int main(){
int score;
float letter;
float sign;
cout << "Please input your grade (0-100): ";
cin >> score;
cout << endl;
if (score >=90 && score <=100){
letter == "Letter grade: A";
if (score == 90 ||
score == 91) {
sign = "-";
}
else if (score == 99 ||
score == 98) {
sign == "+";
}
else {
sign == " ";
}
}
letterGrade(score, letter, sign);
return 0;
}
If someone could point me in the right direction that still uses the parameters that would be very helpful. I think my main problem is I can't figure out how you make something = to a float within the if statement.
Thank you for any help or advise you might have!
You need to pass in the location at which the results will be stored.
So the minimal change to the current code would be to pass in an additional reference to a string that stores the results.
void letterGrade (int, float&, float&, std::string&);
Then when you call the function:
std::string results;//results are stored in here
letterGrade(score, letter, sign, results);//results are passed by reference here
Then in the letterGrade function you want to change whatever you were returning to be instead written to the results reference you passed in.
Additionally you are comparing floats with equality. Given that floats are not completely accurately stored in the computer this might end up not giving the behavior you wanted. If you compiled your code with all warnings enabled the compiler would have warned you about this. In future it's a good idea to compile with all warnings as you will quickly get feedback about potential issues. A quick way to fix your code would be to compare with less than and greater than operators. Read this for more info about the floats: https://ece.uwaterloo.ca/~dwharder/NumericalAnalysis/02Numerics/Double/paper.pdf

Declaring functions part two

Guys please help me again with my program. I changed the order of codes in it. Please check what is wrong with my codes. It runs but it doesn't perform the task it should do. It should compute the total of the grades inputted by the user and show the corresponding remarks. Unfortunately, it doesn't work :( please help me
#include<iostream>
#include<conio.h>
using namespace std;
void computePG(int& PG);
void Remark(int PG);
int x, y, z, w, p;
int prelimGrade,yourRemark,PG;
int preliminaryGrade;
int main()
{
int pGrade;
cout<<"Programmed by: Katrina G. Gozo, 1ISC";
cout<<endl<<"\nDate: Aug. 23,2013";
cout<<endl<<"\nThis program intends to compute the PG and make the necessary remarks";
cout<<"\n\nPlease enter your score on quiz 1 ";
cin>>x;
cout<<"\nPlease enter your score on quiz 2 ";
cin>>y;
cout<<"\nPlease enter your score on quiz 3 ";
cin>>z;
cout<<"\nPlease enter your score on prelims ";
cin>>p;
computePG(pGrade);
Remark(pGrade);
getch();
}
void computePG(int& PG)
{
PG = x/30 * 20 + y/50 * 20 + z/40 * 20 + w/100 * 40;
cout << "\nYour prelim grade is " << PG;
}
void Remark(int PG)
{
if (PG>=90)
cout<<"A." <<endl;
else if (PG>=80)
cout<<"B."<<endl;
else if (PG>=70)
cout<<"C."<<endl;
else if (PG>=60)
cout<<"D."<<endl;
else
cout<<"E."<<endl;
}
You're most likely running afoul of integer arithmetic. Note: when dividing an integer by another integer, you get an integer result (rounded towards zero).
So you'll want to use double as the type of PG and pGrade, and make the constants in computePG floating points numbers as well, by writing them as 30.0, 20.0, etc.
You should probably use a double for your variable "PG," that way you'll have adequate decimal accuracy.
Also, you may want to avoid global variables in the future, because I'm guessing it's how you made this error - you never assign a value to w before using it, which means it is assigned the value 0 by the compiler and may be what is screwing up your result.

Sorting Array's of Structs

I am working on an assignment for my C++ class (the assignment is pasted at the bottom of my test.cpp file). I implemented everything correctly up until the last requirement (using a sort_name function, sort the student structures based on their last names and for each student, sort the classes he or she is taking based on class title. Display the sorted list of students using the display function by calling it from main). I have attempted to implement my sort function by sorting just the students at first, but I keep getting errors and getting stuck(The current error is: Unhandled exception at 0x777a15de in 839a4 Vasilkovskiy.exe: 0xC00000FD: Stack overflow). Any help would be greatly appreciated.
NOTE: I understand that vectors are much more useful for sorting, but our professor does not want us to use them.
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <iomanip>
using namespace std;
struct Class
{
string title;
int units;
char grade;
};
struct Student
{
string name;
double gpa;
Class classes[500];
};
int const SIZE = 50;
void initStudent(Student[], int);
void readStudent(Student[], int, int&);
void gpaCalculate(Student&);
void print(Student[], int);
void sort_name(Student[], int);
void swapStus(Student&, Student&);
void stringToCharArray(string, char[]);
int locactionOfFirstName(Student[], int, int);
int main()
{
int numberOfStudents = 0;
Student students[SIZE];
initStudent(students, SIZE);
readStudent(students, SIZE, numberOfStudents);
for(int i = 0; students[i].name != "";i++)
gpaCalculate(students[i]);
print(students, numberOfStudents);
sort_name(students, numberOfStudents);
system("pause");
return 0;
}
void initStudent(Student st[], int s)
{
for(int i = 0; i < s; i++)
{
st[i].gpa = 0.0;
}
}
void readStudent(Student st[], int s, int& nStus)
{
for(int i = 0; i < s; i++)
{
string tmpName;
cout << "Enter student name: ";
getline(cin, tmpName);
if(tmpName == "")
break;
st[i].name = tmpName;
nStus++;
for(int j = 0; j < 500; j++)
{
string tmpTitle;
cout << "Enter class title: ";
getline(cin, tmpTitle);
if (tmpTitle == "")
break;
st[i].classes[j].title = tmpTitle;
cout << "Enter units for " << st[i].classes[j].title << ": " ;
cin >> st[i].classes[j].units;
cout << "Enter grade for " << st[i].classes[j].title << ": " ;
cin >> st[i].classes[j].grade;
cin.ignore();
}
}
}
void gpaCalculate (Student& s)
{
double unitsByPoints = 0;
double totalUnits = 0;
for (int i = 0; s.classes[i].title != ""; i++)
{
int grade = 0;
char ltrGrade = s.classes[i].grade;
switch (ltrGrade)
{
case 'A':
grade = 4;
break;
case 'B':
grade = 3;
break;
case 'C':
grade = 2;
break;
case 'D':
grade = 1;
break;
case 'F':
grade = 0;
break;
}
unitsByPoints += s.classes[i].units*grade;
totalUnits += s.classes[i].units;
}
s.gpa = unitsByPoints/totalUnits;
}
void print(Student st[], int size)
{
for (int i = 0; i < size; i++)
{
cout << "Student's name: " << st[i].name << endl;
for (int j = 0; st[i].classes[j].title != ""; j++)
{
cout << st[i].classes[j].title << "," << st[i].classes[j].grade << endl;
}
cout << fixed << setprecision(2) << "GPA: " << st[i].gpa << endl;
}
}
//void sort_name(Student st[], int size)
//{
// for(int i = 0; i < size; i++)
// {
// int smallest = locactionOfFirstName(st, i, size);
// swapStus(st[i], st[smallest]);
// }
//
//}
void swapStus(Student& s1, Student& s2)
{
Student tempStu;
tempStu = s1;
s1 = s2;
s2 = tempStu;
}
void stringToCharArray(string s, char c[])
{
char tempCharArray[50];
for(int i = 0; s[i] != '\n'; i++)
{
tempCharArray[i] = s[i];
}
char * space = strstr(tempCharArray," ");
strcpy(c,space);
}
bool lastNameCompare(string l1, string l2)
{
char lName1[50];
char lName2[50];
stringToCharArray(l1, lName1);
stringToCharArray(l2, lName2);
return (strcmp(lName1, lName2) >=0);
}
int locactionOfFirstName(Student st[],int start, int size)
{
char lName1[50];
char lName2[50];
stringToCharArray(st[0].name, lName1);
int i;
for(i = start; i < size;)
{
stringToCharArray(st[i].name, lName2);
if(strcmp(lName1, lName2) >= 0 )
{
stringToCharArray(st[i].name, lName1);
}
}
return i;
}
void InsertItem(Student values[], int startIndex, int endIndex)
{
bool finished = false;
int current = endIndex;
bool moreToSearch = (current != startIndex);
while (moreToSearch && !finished)
{
if (lastNameCompare(values[current-1].name, values[current].name))
{
swapStus(values[current], values[current-1]);
current--;
moreToSearch = (current != startIndex);
}
else
finished = true;
}
}
void sort_name(Student values[], int numValues)
{
for (int count = 0; count < numValues; count++)
InsertItem(values, 0, count);
}
/*
Define a structure called Class (with uppercase C) with the following data:
title, units and grade.
Define a structure called Student with the following data:
name (full name), gpa, and classes which is an array of Class structures (all the classes the student has taken so far).
Write an initialize function that receives an array of Student structures and its size and sets the gpa of all to 0.0.
In main, create 50 Students and call the above function to initialize the gpa for all 50 Students to 0.0.
Then, pass the array of student structures and its size to a read function that will read student data from the user and store the entered data in the array of student structures. The user will enter student name followed by the class title, units and grade received for each class he or she has taken. When finished entering class information for a student, the user will just press Enter (an empty string) and to end entering more students, he or she will do the same for the student name.
Example:
Enter student name: Maria Gomez
Enter class title: English 101
Enter units for English 101: 3
Enter grade for English 101: A
Enter class title: Math 201
Enter units for Math 201: 4
Enter grade for Math 201: B
Enter class title: [User enters RETURN to indicate no more classes]
Enter student name: Kevin Duran
Enter class title: Poly Sci 101
Enter units for Poly Sci 101: 3
Enter grade for Poly Sci 101: A
Enter class title: Math 201
Enter units for Math 201: 4
Enter grade for Math 201: B
Enter class title: [User enters RETURN to indicate no more classes]
Enter student name: [User enters RETURN to indicate no more students]
Once all Studnets have been entered, pass each element of the array of Student structures (element by element) to a gpa function which will compute and return the gpa for each Student using the classes array within each Student structure which contains the units and grade for each class taken by the student. Store the gpa returned by the above function in the gpa member of the Student structures. GPA is calculated by multiplying the number of units for each class by the points received for that class, and then adding all these products together and dividing it by total number of units. The points received for a class is based on the grade: for A, it's 4; for B, it's 3; for C, it's 2; for D it's 1; and for F it's 0. For example, if a student has take 3 classes with 3, 4, and 3 units and has received A, B, and C for these classes, respectively, then, the GPA will be 3 x 4 + 4 x 3 + 3 x 2 / 10 = 3.0.
Print all students showing name, followed by all classes taken, the grade received and the gpa using a display function which receives the array and its size as parameters.
Then, using a sort_name function, sort the student structures based on their last names and for each student, sort the classes he or she is taking based on class title. Display the sorted list of students using the display function by calling it from main.
For example:
Kevn Duran
Poly Sci 101, A
Math 150, B
GPA: 3.0
Maria Gomez:
English 101, A
Math 201, C
GPA: 2.9
Robert Small
Comp Science 801, C
Comp Science 802, D
GPA: 1.9
Tom Wang
Comp Science 808, A
Comp Science 839, B
GPA: 3.5
Then, sort the students based on their GPA's using a sort_gpa function and print the list again using the display function.
Then, ask what to search for - name or gpa. If name is selected, read a student name from the user and, using a binary search function that takes the array, its size and the name to search for, finds the student and displays all of his or her information (name, gpa, units and list of classes taken).
Example:
Enter a student name: Robert Small
Robert Small:
Comp Science 801, C
Comp Science 802, B
GPA: 2.5
If GPA is selected, read a GPA and using another binary search find the student with the given GPA by passing the students array, its size and the GPA to search for. Display the name of the student with the specified GPA in main.
Example:
Enter GPA to search for: 2.5
Robert Small was found with the GPA of 2.5
If the name or GPA is not found, tell the user it was not found; e.g.: There was no student with a GPA of 2.5; or Robert Small was not found.
Then, pass the array of student atructures and the size to a stats function which will return the average of the GPA's of all students and through two reference parameters will output the student structures that have the minimum and maximum GPA's. Print the average GPA, as well as the names of the students who have the minimum and maximum GPA in main, like so:
Average GPA = 3.17
Robert Small has the minimum GPA of 2.5.
Tom Wang has the maximum GPA of 3.5.
Finally, read a maximum and minimum GPA from the user and pass the array of student structures and its size, as well as two other arrays of student structures of the same size to a function which will store all students with a GPA of above the minimum in the highGPA array and all those with a GPA below the maximum in the lowGPA array. Display the students stored in these two arrays by passing them each from main to the display function. In other words, the highlow function receives two uninitalized arrays of student structures and populates them based on the GPA criteria passed to it (minimum GPA and maximum GPA). Then, upon return to main, main passes each of these arrays to the display function to display them. For example, if the user enters 2.0 for the maximum GPA, the lowGPA array gets filled out with all those students who have a GPA of less than 2.0. Likewise, if the minimum GPA is 3.5, the highlow function populates the highGPA array with those students who have a GPA of 3.5 or higher.
Example:
Enter maximum GPA: 2.0
Enter minimum GPA: 3.5
Students with a GPA of lower than 2.0:
Robert Small 1.9
Students with a GPA of 3.5 or higher:
Tom Wang 3.5
When writing the highlow function, take advantage of the fact that the array elements are sorted based on the GPA, so to find all the students with a GPA of equal to or higher than the minimum GPA, it doesn't make sense to start from the first element in the array. Instead you can start from the midpoint. If the midpoint is lower than the minimum GPA, you can increment the index until the midpoint is no longer smaller and then all the GPA's from that point on will be larger and part of the high GPA's. For low GPA's of course, you'd want to start from the beginning of the array and compare and store each that's lower than the maximum until they are no longer lower.
Functions you must write for this assignment (in addition to main):
initialize, read, display, sort_name, sort_gpa, search-name, search_gpa, stats, highlow.
Upload your cpp and exe files using the Browse and Upload buttons below and click Finish once both have been uploaded to the site.*/
I debugged it for you.
The problem is in your stringToCharArray(string s, char c[]).
My index i arrived to 104 before getting "segmentation fault". Since all your strings have length 50 you are clearly going out of bounds.
Another problem is in srtstr that returns NULL, but this is related to the first problem.
A quick look to your sort_name and InsertItem didn't show up anything wrong, at least in the field of "segmentation error", since it's not so clear what you are trying to do, but at least you are performing the right index checks.