/* ------------------------------------------------------------
Programmer : Bill Gates
Date : April 30, 2020
Description : This program performs several functions with
an array of Student records. This program
should work with any size array
------------------------------------------------------------ */
//#define_CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
using namespace std;
const int ARRAY_SIZE = 12; //there are 12 records in the file
const int NAME_SIZE = 25; //all names are < 25 chars
struct Student
{
char studentName[NAME_SIZE];
unsigned int test1, test2, test3, test4;
float average;
bool passing;
};
void getData(Student[]); //loads the array with data from file
void print(Student[], Student); //show results
void findAverages(Student[]); //gets each student's avg based on 4 tests
void determinePassing(Student[]); //passing is an average >= 60
void getHighestStudent(Student[], Student&); //finds student with highest average
int main()
{
Student theClass[ARRAY_SIZE];
Student highest = { {"Nobody"}, 0,0,0,0,0,0 }; //this strucure will hold top student's info
getData(theClass);
findAverages(theClass);
determinePassing(theClass);
getHighestStudent(theClass, highest); //NOTE: highest is a REFERENCE parameter!
print(theClass, highest);
}
/* ------------------------------------------------------------
Function name: getData(Student theClass[])
Description: This function is used to read the data from the student_data.txt and store it into theClass [] array of structure
Receives: Array of structure of Student
Returns: It stores the data into Student structure array
Requires: The input file,Student structure array
------------------------------------------------------------ */
void getData(Student theClass[])
{
ifstream infile;
char temp[NAME_SIZE];//temporary array to read in names
infile.open("student_data.txt");
if (infile)
{
for (int x = 0; x < ARRAY_SIZE; x++)
{
infile.getline(temp, NAME_SIZE);//workaround to read in array of chars
strcpy(theClass[x].studentName, temp);// instead of a string
infile>>theClass[x].test1;
infile>>theClass[x].test2;
infile>>theClass[x].test3;
infile>>theClass[x].test4;
infile.ignore();
}
infile.close();
}
else
cout<<"Error opening file"<
}
/* ------------------------------------------------------------
Function name : findAverages(Student theClass[])
Description : it is used to find average of the test marks of student
Receives: Array of structure of Student
Returns: It stores the data into Student Array
Requires: Student structure array should contain data
------------------------------------------------------------ */
void findAverages(Student theClass[])
{
float average;
for(int i =0;i
{
average = theClass[i].test1+theClass[i].test2+theClass[i].test3+theClass[i].test4;
average = average/4;
theClass[i].average = average;
}
}
/*Assembly Code
__Z12findAveragesP7Student:
LFB2253:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
subl $32, %esp
movl $0, -4(%ebp)
L5:
cmpl $11, -4(%ebp)
jg L6
movl -4(%ebp), %eax
imull $52, %eax, %edx
movl 8(%ebp), %eax
addl %edx, %eax
movl 28(%eax), %edx
movl -4(%ebp), %eax
imull $52, %eax, %ecx
movl 8(%ebp), %eax
addl %ecx, %eax
movl 32(%eax), %eax
leal (%edx,%eax), %ecx
movl -4(%ebp), %eax
imull $52, %eax, %edx
movl 8(%ebp), %eax
addl %edx, %eax
movl 36(%eax), %eax
addl %eax, %ecx
movl -4(%ebp), %eax
imull $52, %eax, %edx
movl 8(%ebp), %eax
addl %edx, %eax
movl 40(%eax), %eax
addl %ecx, %eax
movl %eax, -32(%ebp)
movl $0, -28(%ebp)
fildq -32(%ebp)
fstps -8(%ebp)
flds -8(%ebp)
flds LC2
fdivrp %st, %st(1)
fstps -8(%ebp)
movl -4(%ebp), %eax
imull $52, %eax, %edx
movl 8(%ebp), %eax
addl %edx, %eax
flds -8(%ebp)
fstps 44(%eax)
addl $1, -4(%ebp)
jmp L5
L6:
nop
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
LFE2253:
.def ___tcf_0; .scl 3; .type 32; .endef
___tcf_0:
LFB2753:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
subl $8, %esp
movl $__ZStL8__ioinit, %ecx
call __ZNSt8ios_base4InitD1Ev
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
LFE2753:
.def __Z41__static_initialization_and_destruction_0ii; .scl 3; .type 32; .endef
__Z41__static_initialization_and_destruction_0ii:
LFB2752:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
subl $24, %esp
cmpl $1, 8(%ebp)
jne L10
cmpl $65535, 12(%ebp)
jne L10
movl $__ZStL8__ioinit, %ecx
call __ZNSt8ios_base4InitC1Ev
movl $___tcf_0, (%esp)
call _atexit
L10:
nop
leave
.cfi_restore 5
.cfi_def_cfa 4,...