In C LAB ASSIGNMENT 4 OBJECTIVE Compute a students percenta

In C

LAB ASSIGNMENT # 4

OBJECTIVE:  
Compute a student\'s percentage grade and then assign the appropriate letter grade. Perform the computations for up to 30 students and produce a report ( to a file ) in the format shown in the sample below
Use an array of structs to hold the student data. Must allow reports to be generated to the screen or file that sort by Name or by Percent Grade. Also write the data to a binary file with a name passed in with argv. Provide logic to allow the program to open the data file it previously saved and display/add to the data file.

INPUT:

Student Name
8 labs
3 exams
1 final

COMPUTATIONS:

The percentage grade is equal to the sum of:

-- the average of 8 labs with a 40% weight
-- the average of 3 exams with a 40% weight
-- the final exam with a 20% weight

LOGIC:
94-100 A
85-93 B
75-84 C
65-74 D
BELOW 65 F

OUTPUT:

GRADE REPORT

NAME    % GRADE LETTER GRADE


Jim Dandy    93 B
Sally Sue 78 C
Handay Andy 59 F

DELIVERABLES:

1. Title Page
2. Narrative
3. Defining Diagram
4. Hierarchy Chart
5. Nassi-Schneidermen Charts
6. Program Output
7. Source Code

Solution

title:student data

contains array of structs to hold the student data

#include<stdio.h>
#include<stdlib.h>
#define _CRT_SECURE_NO_WARNINGS
typedef struct STUDENT
{
char FirstName[15];
char LastName[20];
float PercentGrade;
char LetterGrade;
}STUDENT;

#define MAX 7
void writeStudents(void);
void displayArray(STUDENT []);
void sortStudentsByFirstName(STUDENT []);
void sortStudentsByLastName(STUDENT []);
void sortStudentsByPercentGrade(STUDENT []);
void sortStudentsByLetterGrade(STUDENT []);
void enterStudents(void);
main()
{
int choice;
do
{
printf(\"\ \ \ Enter Students or 0 to exit\ \ \");
printf(\"\ 1. Display By Name To Screen\");
printf(\"\ 2. Display By GPA To Screen\");
printf(\"\ 3. Write By Name To File\");
printf(\"\ 4. Write By GPA To File\");
printf(\"\ \ Enter you selection ==> :\");
fflush(stdin);
scanf(\"%d\", &choice);
switch(choice)
{

case 1 : printf(\"\ Display By Name\");
break;
case 2 : printf(\"\ Display By GPA\");
break;
case 3 : printf(\"\ Write By Name\");
break;
case 4 : printf(\"\ Write By GPA\");
break;
case 0 : break;
default: printf(\"\ Your options are 0-4\");
printf(\"\ Press <Enter> to try again\");
fflush(stdin);
getchar();
}
} while(choice);

return(0);
}
void enterStudents(void)
{
printf(\"\ Display By Name\");
printf(\"\ Display By GPA\");
printf(\"\ Write By Name\");
printf(\"\ Write By GPA\");
}
STUDENT mixed[15];
int i;
FILE * fptr;
writeStudents();
fptr = fopen(\"Students.dat\", \"rb\");
if(fptr ==NULL)
{
printf(\"\ Grade Report Today!\");
fflush(stdin);getchar();
exit(0);
}
i=0;

fread(&mixed[i],sizeof(STUDENT), 1, fptr);
while(!feof(fptr))
{
printf(\"\ %s\", mixed[i].FirstName);
i++;
fread(&mixed[i], sizeof(STUDENT), 1, fptr);
printf(\"\ %s\", mixed[i].LastName);
i++;
fread(&mixed[i], sizeof(STUDENT), 1, fptr);
printf(\"\ %s\", mixed[i].PercentGrade);
i++;
fread(&mixed[i], sizeof(STUDENT), 1, fptr);
printf(\"\ %s\", mixed[i].PercentGrade);
i++;
fread(&mixed[i], sizeof(STUDENT), 1, fptr);

}
fclose(fptr);
return(0);
}
void writeStudents(void)
{
STUDENT mixed[MAX]= {
{\"Tom\", \"Thumb\", 105.00, \'*\'},
{\"Jim\", \"Bean\", 95.00, \'A\'},
{\"Sippy\", \"Cup\", 85.00, \'B\'},
{\"Green\", \"Giant\", 75.00, \'C\'},
{\"Dead\", \"Aunt\", 65.00, \'D\'},
{\"Speed\", \"Racer\", 55.00, \'F\'},
{\"Hide\", \"NSeek\", -10.00, \'*\'},
};
FILE * fptr;
int i;
fptr = fopen(\"Students.dat\", \"wb\");
if(fptr == NULL)
{
priintf(\"\ Grade Report Today!\");
fflush(stdin);getchar();
exit(0);
}
for(i=0; i<MAX; i++)
{
fwrite(&mixed[i], sizeof(STUDENT),1, fptr);
}
displayArray(mixed);
sortStudentsByFirstName(mixed);
sortStudentsByLastName(mixed);
sortStudentsByPercentGrade(mixed);
sortStudentsByLetterGrade(mixed);
displayArray(mixed);
fclose(fptr);
}
void displayArray(STUDENT mixed[])
{
int i;
for(i=0; i<MAX; i++)
{
printf(\"\ %s %.2f %c\", mixed[i].FirstName,mixed[i].LastName,mixed[i].PercentGrade,mixed[i].LetterGrade);
}
printf(\"\ \");

}
void sortStudentsByFirstName(STUDENT mixed[])
{
STUDENT temp;
int i;
int x;
for(x-0; x < MAX-1; x++)
{
for(i=0; i < MAX-1-x; i++)
{
if( strcmp(mixed[i].FirstName, mixed[i+1].FirstName)> 0)
{
temp = mixed[i];
mixed[i] = mixed[i+1];
mixed[i+1] = temp;
}
}
}
}

void sortStudentsByLastName(STUDENT mixed[])
{
STUDENT temp;
int i;
int x;
for(x-0; x < MAX-1; x++)
{
for(i=0; i < MAX-1-x; i++)
{
if( strcmp(mixed[i].LastName, mixed[i+1].LastName)> 0)
{
temp = mixed[i];
mixed[i] = mixed[i+1];
mixed[i+1] = temp;
}
}
}
}
void sortStudentsByPercentGrade(STUDENT mixed[])
{
STUDENT temp;
int i;
int x;
for(x-0; x < MAX-1; x++)
{
for(i=0; i < MAX-1-x; i++)
{
if(mixed[i].PercentGrade > mixed[i+1].PercentGrade)
{
temp = mixed[i];
mixed[i] = mixed[i+1];
mixed[i+1] = temp;
}
}
}
}
void sortStudentsByLetterGrade(STUDENT mixed[])
{
STUDENT temp;
int i;
int x;
for(x-0; x < MAX-1; x++)
{
for(i=0; i < MAX-1-x; i++)
{
if(mixed[i].LetterGrade > mixed[i+1].LetterGrade)
{
temp = mixed[i];
mixed[i] = mixed[i+1];
mixed[i+1] = temp;
}
}
}
}

/* float percentGrade;
float labs;
float exams;
float final;

labs = calcLabs();

exams = calcExams();

final = calcFinal();

percentGrade = labs + exams + final;
return percentGrade;*
return calcLabs() + calcExams() + calcFinal();
}
float calcLabs(void)
{
float labs = 0;
float oneLab;
int i;
for(i =0; i<NUMBER_OF_LABS; i++)
{
printf(\"\ Enter lab %d: \", i+1);
fflush(stdin);
scanf(\"%f\", &oneLab);
labs=oneLab;
}
labs = (labs/NUMBER_OF_LABS)*0.40f;
return labs;
}
float calcExams(void)
{
float exams = 0;
float oneExam;
int i;
for(i =0; i<NUMBER_OF_EXAMS; i++)
{
printf(\"\ Enter Exams %d: \", i+1);
fflush(stdin);
scanf(\"%f\", &oneExam);
exams+=oneExam;
}
exams = (exams/NUMBER_OF_EXAMS)*0.40f;
return exams;
}
float calcFinal(void)
{
float final;
printf(\"\ Enter Final: \");
fflush(stdin);
scanf(\"%f\", &final);
final = final *0.20f;
return final;
}
char calcLetterGrade(float percentGrade)
{
/* char letterGrade = \'X\';
if(percentGrade > 100 || percentGrade < 0)
{
letterGrade = \'*\';
}
else
{
if(percentGrade >= 94)
{
letterGrade = \'A\';
}
else
{
if(percentGrade >= 84)
{
letterGrade = \'B\';
}
else
{
if(percentGrade >= 74)
{
letterGrade = \'C\';
}
else
{
if(percentGrade >= 65)
{
letterGrade = \'D\';
}
else
{
letterGrade = \'F\';
}
}
}
}
}
return letterGrade;
if(percentGrade > 100 || percentGrade < 0)
{
return \'*\';
}
else
{
if(percentGrade >= 94)
{
return \'A\';
}
else
{
if(percentGrade >= 84)
{
return \'B\';
}
else
{
if(percentGrade >= 74)
{
return \'C\';
}
else
{
if(percentGrade >= 65)
{
return \'D\';
}
else
{
return \'F\';
}
}
}
}
}
return \'X\';
}

In C LAB ASSIGNMENT # 4 OBJECTIVE: Compute a student\'s percentage grade and then assign the appropriate letter grade. Perform the computations for up to 30 stu
In C LAB ASSIGNMENT # 4 OBJECTIVE: Compute a student\'s percentage grade and then assign the appropriate letter grade. Perform the computations for up to 30 stu
In C LAB ASSIGNMENT # 4 OBJECTIVE: Compute a student\'s percentage grade and then assign the appropriate letter grade. Perform the computations for up to 30 stu
In C LAB ASSIGNMENT # 4 OBJECTIVE: Compute a student\'s percentage grade and then assign the appropriate letter grade. Perform the computations for up to 30 stu
In C LAB ASSIGNMENT # 4 OBJECTIVE: Compute a student\'s percentage grade and then assign the appropriate letter grade. Perform the computations for up to 30 stu
In C LAB ASSIGNMENT # 4 OBJECTIVE: Compute a student\'s percentage grade and then assign the appropriate letter grade. Perform the computations for up to 30 stu
In C LAB ASSIGNMENT # 4 OBJECTIVE: Compute a student\'s percentage grade and then assign the appropriate letter grade. Perform the computations for up to 30 stu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site