1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
struct student
{
char Student_lastname[15];
int quiz1;
int quiz2;
int quiz3;
int quiz4;
int quiz5;
};
void sortArray(student grades[], int size, int entries);
//int binarySearch(char grades[].Student_lastname, int, int)
int main()
{
student grades[100];
const int size = 100;
double array[size];
int i = 0;
//open file
ifstream infile;
infile.open("StudentRec.txt", ios::in);
if (!infile.is_open())
{
exit(EXIT_FAILURE);
}
//read data file into structure
for (i = 0; i<5;i++)
{
infile >> grades[i].Student_lastname;
infile >> grades[i].quiz1;
infile >> grades[i].quiz2;
infile >> grades[i].quiz3;
infile >> grades[i].quiz4;
infile >> grades[i].quiz5;
cout << grades[i].Student_lastname << " " << grades[i].quiz1 << " " <<
grades[i].quiz2 << " " << grades[i].quiz3 << " " << grades[i].quiz4 << " " <<
grades[i].quiz5 << endl;
}
//sort array
alphabetical(5,size, 5);
//binary search
//int results;
//results = binarySearch(Student_lastname, size, );
//prompt user with sentinel loop
//close file
infile.close();
return 0;
}//main
void alphabetical(student grades[], int size, int entries =5)
{
for (int j=1; j<=entries;j++)
{
for(int i=1;i<=entries-j;i++)
{
if (strcmp(grade[i].Student_lastname >= grades[i+1].Student_lastname==1)
{
temp[i] = person[i+1];
grades[i+1]=grades[i];
grades[i]=temp[i];
flag=1
}
}//for i
}//for j
}
/*int binarySearch(char grades[].Student_lastname, int size, int value)
{
int first = 0,
last = size - 1,
middle,
position = 1;
bool found = false;
while(!found && first <= last)
{
middle = (first + last)/2;
if (array[middle] == value)
{
found = true;
position = middle;
}
else if (array[middle]>value)
last = middle -1;
else
first = middle + 1;
}
return position;
}*/
| |