Question

Program in C Student Data using Structs In this assignment you will create a program (using...

Program in C

Student Data using Structs

In this assignment you will create a program (using multiple .c files) to solve the following problem:

You have been hired by the university to create a program that will read in input from a .txt file. This input will contain a student name, student id #, their age and their current gpa. You should use the following struct for your student data:

struct Student{

                char name[50];

                int id;

                float gpa;

                int age;

};

Your job is to create a program that after it reads in all the student records in the .txt file ( there could be up to 100), prints out the average gpa, the name of the student with the highest gpa, the number of students with a gpa higher than the average and the average age of the students. Your program needs to run for any number of student records up to 100.

You will need to create a driver program to run your program. The driver program should create a file handle, open the file and send the file handle to a function in your program to read in the input. Nothing else will be accomplished in the driver program. The driver program will NOT print anything, it should contain a line of code that calls a function to start the execution of what is needed (this is where you send in the file handle). Remember to store the Struct declaration in your .h file!

Hint* you will need to write several functions to accomplish this goal. Remember, each function should do one thing only! When you call a function with a file handle, the receiving function must store it as a file pointer (FILE * file_ptr). Break the program down into smaller parts and accomplish each part separately.

Grading criteria (100 pts total):

  • Your program will receive no credit if it does not compile
  • Proper coding convention, indentation and meaningful identifiers (10 pts)
  • Correct output (60 pts)
  • Correct usage of multiple functions to accomplish goal (20 pts)
  • Correct usage of struct array to store student records (10 pts)

student_records.txt :

David 1234 4.0 44
Sally 4321 3.6 21
Bob 1111 2.5 20
Greg 9999 1.8 28
Heather 0000 3.2 22
Keith 3434 2.7 40
Pat 1122 1.0 31
Ann 6565 3.0 15
Mike 9898 2.0 29
Steve 1010 2.2 24
Kristie 2222 3.9 46
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

student.h

#include<stdio.h>

struct Student{

    char name[50];

    int id;

    float gpa;

    int age;

};

student_driver.c

#include<stdio.h>

#include<string.h>

#include "student.h"

void printAvgGPA(struct Student s[],int n)

{

    float total=0,avg;

    for(int i=0;i<n;i++)    

        total=total+s[i].gpa;

    

    avg=total/n;

    printf("\nAverage GPA is %f",avg);    

}

void printHighestGPAStudent(struct Student s[],int n)

{

    float highest=s[0].gpa;

    char name[100];

    strcpy(name,s[0].name);

    for(int i=0;i<n;i++)

    {

        if(s[i].gpa>highest)

        {

            highest=s[i].gpa;

            strcpy(name,s[i].name);

        }

    }

    printf("\nStudent with highest GPA is %s",name);

}

void studentWithHigherthanAvg(struct Student s[],int n)

{

    float total=0,avg;

    int higher=0;

    for(int i=0;i<n;i++)    

        total=total+s[i].gpa;

    

    avg=total/n;

    for(int i=0;i<n;i++)

    {

        if(s[i].gpa>avg)

            higher++;

    }

    printf("\nNumber of students with GPA higher than Average GPA is %d",higher);

}

void printAvgAge(struct Student s[],int n)

{

    int avgage=0;

    for(int i=0;i<n;i++)

        avgage=avgage+s[i].age;

    

    avgage=avgage/n;

    printf("\nAverage age of students is %d",avgage);

}

void readfile(FILE *fp)

{

    struct Student s[100];

    int i=0,n;

    while(!feof(fp)){

    fscanf(fp,"%s%d%f%d",s[i].name,&s[i].id,&s[i].gpa,&s[i].age);

    i++;

    }

    printAvgGPA(s,i);

    printHighestGPAStudent(s,i);

    studentWithHigherthanAvg(s,i);

    printAvgAge(s,i);

}

void main()

{

    FILE *fp;

    char inpfile[100];

    printf("Enter a file name:");

    scanf("%s",inpfile);

    fp=fopen(inpfile,"r");

    readfile(fp);

}

Output:

Add a comment
Know the answer?
Add Answer to:
Program in C Student Data using Structs In this assignment you will create a program (using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Write a program named lab3 2.app that contains a class named Student to store student...

    2. Write a program named lab3 2.app that contains a class named Student to store student information Information that will be relevant to store is first name, last name, id number, GPA, and major (1) Define a member function named set0, which allows you to set all member variables. This function has an empty parameter list, and its return type is void. So, within the function you'll prompt for information. Note: For entering major, if you need a space, use...

  • Visual C# Homework 2 You are to write a program which will create a class called...

    Visual C# Homework 2 You are to write a program which will create a class called Student Each student has a name age height and weight. These variables should be declared as private. Create the correct constructors and functions. In the main, you will create 5 students. Input the data for the 5 students from a file which already has information in it. Name the file “Information.txt”. After setting up all the data, it is time to sort based on...

  • Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing...

    Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing an array of structs to a function, and returning a struct as the value of a function. A function in the program should read several rows of data from a text file. (The data file should accompany this assignment.) Each row of the file contains a month name, a high temperature, and a low temperature. The main program should call another function which...

  • Question 4: C Programming (15 points) Create a program that asks the user for an integer...

    Question 4: C Programming (15 points) Create a program that asks the user for an integer number representing the number of students in a classroom. Your program will then malloc an array of struct students having the same number of cells as input by the user's integer number. The student struct will have only two fields: student name and gpa. Your program then opens a CSV file

  • In Language = C Concepts for this are (malloc/realloc, structs, and stdin/fgets/getc/scanf) Description Your program will...

    In Language = C Concepts for this are (malloc/realloc, structs, and stdin/fgets/getc/scanf) Description Your program will ask the user to type in the following information: First Name: Last Name: ID#: Email: The program will terminate when a single . is entered as a First Name. This information will be stored in the following structure type: struct student { int recordCount; char *firstName; char *lastName; char *id; char *email; } recordCount is a number assigned at the beginning of the program...

  • In c programming . Part A: Writing into a Sequential File Write a C program called...

    In c programming . Part A: Writing into a Sequential File Write a C program called "Lab5A.c" to prompt the user and store 5 student records into a file called "stdInfo.txt". This "stdInfo.txt" file will also be used in the second part of this laboratory exercise The format of the file would look like this sample (excluding the first line) ID FIRSTNAME LASTNAME GPA YEAR 10 jack drell 64.5 2018 20 mina alam 92.3 2016 40 abed alie 54.0 2017...

  • SC 111 - BMCC Exam Student Name: Type # 4 - 20 Points write a program...

    SC 111 - BMCC Exam Student Name: Type # 4 - 20 Points write a program that uses a structure named Student to store the following information about a Student: Name ID GPA Address The program should create three Student instances, store values, and pass all of them to a function that displays the information about the Student in a clearly formatted manner. The program also uses another function to calculate and display the average GPA of all three Students.

  • Write a modularized, menu-driven program to read a file with unknown number of records.

    ==============C++ or java================Write a modularized, menu-driven program to read a file with unknown number of records.Create a class Records to store the following data: first and last name, GPA , an Id number, and an emailInput file has unknown number of records; one record per line in the following order: first and last names, GPA , an Id number, and emailAll fields in the input file are separated by a tab (‘\t’) or a blank space (up to you)No error...

  • O Fit to page ID Page vi Programming assignment 6 Assume that the following student information...

    O Fit to page ID Page vi Programming assignment 6 Assume that the following student information is stored in a MATLAB structure student student name contains the full name of the student student..pa contains the GPA of the student student.standing contains whether the student is in good academic standing (true/fake) Write a function update(student, field, value) that does the following: Thes as an input a student structure, a student field name, and a value Epla 2. Returns a student structure...

  • You will create a class to keep student's information: name, student ID, and grade. The program...

    You will create a class to keep student's information: name, student ID, and grade. The program will have the following functionality: - The record is persistent, that is, the whole registry should be saved on file upon exiting the program, and after any major change. - The program should provide the option to create a new entry with a student's name, ID, and grade. - There should be an option to lookup a student from his student ID (this will...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT