In: Computer Science
Program in C
Make both a SOURCE AND HEADER FILE WITH FUNCTIONS to run the program. Input data from csv file. Two files. grades.c and grades.h Thank you
data.csv file
Mark Prest,37468,36,113,In Person
Andy Joe,6785923,19,98,Online
Caden Miller,237741,20,70.1,In Person
Luke Jr,2347878,18,45.9,In Online
Ally Rogers,8467483,30,89.99,Online
Maya Jank,5674930,30,90,In Person
Expected output
Name: Mark Prest
ID: 37468
Age: 36
Grade: 113.00
Attending: In Person
Name: Andy Joe
ID: 6785923
Age: 19
Grade: 98.00
Attending: Online
Name: Caden Miller
ID: 237741
Age: 20
Grade: 70.10
Attending: In Person
Name: Luke Jr
ID: 2347878
Age: 18
Grade: 45.90
Attending: Online
Name: Ally Rogers
ID: 8467483
Age: 30
Grade: 89.99
Attending: Online
Name: Maya Jank
NUID: 5674930
Age: 30
Grade: 90.00
Attending: In Person
--------------
2
---- Grade Stats ----
A's: 3
B's: 1
C's: 1
D's: 0
F's: 1
Avg grade: 84.50
---- Enrollment Statistics ----
Number of in person: 5
Number of online: 1
Average age: 25.50
SOLUTION :
CONSIDERING THE CONDITIONS AND REQUIREMENTS FROM THE QUESTION.
HERE CODE
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fptr;
int count=0, agesum=0,gradesum=0,in=0, online=0; //the number of
entries
char filename[100], c, Name[],Attending[], extract[1000];
int ID[], Age[], Grade[], t=0, m=0, k=count-1;
printf("Enter the filename to open \n");
scanf("%s", filename);
// Open file
fptr = fopen(filename, "r");
if (fptr == NULL)
{
printf("Cannot open file \n");
exit(0);
}
// Read contents from file
c = fgetc(fptr);
while (c != EOF && c=='\n')
{
count+=1;
c = fgetc(fptr);
}
c = fgetc(fptr);
Name= new char [count];
Attending= new char [count];
ID= new int [count];
Age= new int [count];
Grade= new int[count];
while (c != EOF && m<5 && k>=0)
//storing values in seperate arrays Name, Attending, Age,
Grade
{ //m is used for keeping count of the no. of columns or array
names and k is used to keep count of the number of entries or rows
if(c=='\n')
m=0;
else{
do{
extract[t++]=c;
c = fgetc(fptr); }
while(c!=',');
if(m==0)
Name[count-1-k]=extract;
else if(m==1)
Attending[count-1-k]=extract;
else if(m==2)
ID[count-k]=extract;
else if(m==3)
Age[count-1-k]=(int) extract;
else if(m==4)
Grade[count-1-k]=(int) extract;
k-=1;
m+=1;
extract="";
}
}
for(int i=0; i<count ; i++)
{
printf("Name: %s", Name[i]);
printf("Attending: %s", Attending[i]);
if(Attending[i]=="Online")
online+=1;
else in+=1;
printf("ID: %s ", ID[i]);
printf("Age: %d", (int)Age[i]);
agesum+=Age[i];
printf("Grade: %f", (float)Grade[i]);
gradesum+=Grade[i];
}
printf("Number of in persons is %d", in);
printf("Number of online persons is %d", online);
printf("The average age is: %f", (agesum/count));
printf("The average grade is: %f",(gradesum/count));
fclose(fptr);
return 0;
}
NOTE : PLEASE UPVOTE ITS VERY MUCH NECESSARY FOR ME A LOT. PLZZZZ....A