SEMM 1013 - Project 1 - Wan Abdul Hadi

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

SEMM 1013

PROJECT 1

Name: Wan Abdul Hadi bin Kamarol Zaman


Matrix card number: SX210190EMMHS01

ANSWER:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define NAME 35

#define ID 10

int main(void)

float test[3];

float hw[4];

float prj[1];

int line, t, h, p, fmark;

FILE *file_in = fopen("Project1.dat", "r");

FILE *file_out = fopen("ProjectOutput.dat", "w");

if (file_in == NULL || file_out == NULL)

printf("Error! Could not open file\n");

exit(1);

fprintf(file_out, "SEMM 1013\n\nSemester 1\n\nNumber of student: 68\n\nAverage final


mark: 51/100\n\nAverage grade: C\n\n");

fprintf(file_out, "Name\t\t\t\t\t\t\t ID\t\tFinal Mark\tGrade\n\n");

const unsigned MAX_LENGTH = 1000;

char buffer[MAX_LENGTH];
while (fgets(buffer, MAX_LENGTH, file_in) != NULL)

line == 0;

char name[NAME];

fgets(name, NAME, file_in);

fprintf(file_out, "%s", name);

char id[ID];

fgets(id, ID, file_in);

fprintf(file_out, "%s", id);

fscanf(file_in, "%f %f %f %f %f %f %f %f", &test[1], &test[2], &test[3], &hw[1], &hw[2],


&hw[3], &hw[4], &prj[1]);

fmark =
((test[1]/5)+(test[2]/5)+(test[3]/5))+((hw[1]+hw[2]+hw[3]+hw[4])/(4))+((prj[1])/(3.333333
33333333));

fprintf(file_out, "%d/100\t\t", fmark);

if(fmark >= 90)

fprintf(file_out, "A+\n");

else if(fmark >= 80 && fmark < 90)

fprintf(file_out, "A\n");

else if(fmark >= 75 && fmark < 80)

fprintf(file_out, "A-\n");

else if(fmark >= 70 && fmark < 75)

fprintf(file_out, "B+\n");
}

else if(fmark >= 65 && fmark < 70)

fprintf(file_out, "B\n");

else if(fmark >= 60 && fmark < 65)

fprintf(file_out, "B-\n");

else if(fmark >= 55 && fmark < 60)

fprintf(file_out, "C+\n");

else if(fmark >= 50 && fmark < 55)

fprintf(file_out, "C\n");

else if(fmark >= 45 && fmark < 50)

fprintf(file_out, "C-\n");

else if(fmark >= 40 && fmark < 45)

fprintf(file_out, "D+\n");

else if(fmark >= 35 && fmark < 40)

fprintf(file_out, "D\n");

else if(fmark >= 30 && fmark < 35)


{

fprintf(file_out, "D-\n");

else

fprintf(file_out, "E\n");

line++;

fprintf(file_out, "\nGrade Distribution Plot\n\n20| | | | | | | | | | | | | |\n19| | |


| | | | | *| | | | | |\n18| | | | | | | | *| | | | | |\n17| | | | | | | | *| | | | |
|\n16| | | | | | | | *| | | | | |\n15| | | | | | | | *| | | | | |\n14| | | | | | |
| *| | | | | |\n13| | | | | | | *| *| | | | | |\n12| | | | | | | *| *| | | | | |\n11|
| | | | | | *| *| | | | | |\n10| | | | | | | *| *| | | | | |\n9 | | | | | | *| *| *| *|
| | | |\n8 | | | | | | *| *| *| *| | | | |\n7 | | | | | | *| *| *| *| *| | | |\n6 | | | |
| | *| *| *| *| *| | | |\n5 | | | | | | *| *| *| *| *| *| | |\n4 | | | | | | *| *| *| *| *| *|
| |\n3 | | | | | | *| *| *| *| *| *| | |\n2 | | | | | *| *| *| *| *| *| *| | |\n1 | | | | *|
*| *| *| *| *| *| *| *| *|\n0 |A+|A |A-|B+|B |B-|C+|C |C-|D+|D |D-|E |");

fclose(file_in);

fclose(file_out);

return 0;

You might also like