Question

In: Computer Science

Program in C Make both a SOURCE AND HEADER FILE WITH FUNCTIONS to run the program....

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

Solutions

Expert Solution

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


Related Solutions

Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
......C++ PROGRAM.... Teacher would like us to split this program into a header file(filename.h), and a...
......C++ PROGRAM.... Teacher would like us to split this program into a header file(filename.h), and a .cpp file(filename.cpp). He gave us all the code, we just need to split it up. I do not quite understand how to do it. Please send output screenshot to show validation. #include <iostream> using namespace std; //public class class Account{ public: //instance variables double amount;    //creates account and sets amount with users account set-up value Account(double a){ amount = a; }    //adds...
**C++ program** Please provide a header file(bubble_sort.h) and a program file(bubble_sort.cpp). Also include notes to explain...
**C++ program** Please provide a header file(bubble_sort.h) and a program file(bubble_sort.cpp). Also include notes to explain code and output screenshots. Please use Bubble Sort code provided. Write a program for sorting a list of integers in ascending order using the bubble sort algorithm. Requirements Implement the following functions: Implement a function called readData int readData( int *arr) arr is a pointer for storing the integers. The function returns the number of integers. The function readData reads the list of integers...
Given the header file (grid.h) and the source file,(grid.cpp) create the file trap.cpp. Here are the...
Given the header file (grid.h) and the source file,(grid.cpp) create the file trap.cpp. Here are the requirements for trap.cpp: Write a main program in a file called trap.cpp that solves the following scenario, using your Grid class: Giant Mole People have risen from their underground lairs and are taking over the world. You have been taken prisoner and placed in an underground jail cell. Since the Mole People are blind and don't know how to build doors, your cell has...
Write a C++ program that implements a simple scanner for a source file given as a...
Write a C++ program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described below. You may assume that the input is syntactically correct. Optionally, your program can build a symbol table (a hash table is a good choice), which contains an entry for each token that was found in the input. When all the input has been read, your program should produce a summary report that includes a...
Write a C++ program that implements a simple scanner for a source file given as a...
Write a C++ program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described below. You may assume that the input is syntactically correct. Optionally, your program can build a symbol table (a hash table is a good choice), which contains an entry for each token that was found in the input. When all the input has been read, your program should produce a summary report that includes a...
Write a C++ program that implements a simple scanner for a source file given as a...
Write a C++ program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described below. You may assume that the input is syntactically correct. Optionally, your program can build a symbol table (a hash table is a good choice), which contains an entry for each token that was found in the input. When all the input has been read, your program should produce a summary report that includes a...
Write a C program to run on unix to read a text file and print it...
Write a C program to run on unix to read a text file and print it to the display. It should count of the number of words in the file, find the number of occurrences of a substring, and take all the words in the string and sort them (ASCII order). You must use getopt to parse the command line. There is no user input while this program is running. Usage: mywords [-cs] [-f substring] filename • The -c flag...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT