Question

Assignment 12 The program to write in this assignment is a program that calculates score statistics and manages the grades of in C porgraming . use #include〈stdio.h〉
#include〈stdlib.h〉
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

typedef struct Student{
    char student_id[11];
    char student_name[20];
    int score;
    char grade;
} Student;

typedef struct Node{
    Student s;
    struct Node *next;
} Node;

//Function to add to linked list
Node* add(Node *list, Student s){
    Node *newNode = (Node*)malloc(sizeof(Node));
    newNode->s = s;
    newNode->next = NULL;

    if(list == NULL)
        list = newNode;
    else {
        Node *ptr = list;
        while (ptr->next != NULL)
            ptr = ptr->next;
        ptr->next = newNode;
    }
    return list;
}

//Function to return grade based on score
char getGrade(int score){
    if(score >= 90)
        return 'A';
    else if(score >= 80)
        return 'B';
    else if(score >= 70)
        return 'C';
    else if(score >= 60)
        return 'D';
    else
        return 'F';
}

//Function to read data from file into linked list
Node* readFromFile(Node *list){
    FILE *f = fopen("student.dat", "r");//Open file in read mode
    if(f == NULL){
        printf("Error: Unable to open file\n");
        exit(EXIT_FAILURE);
    }
    Student s;
    while(!feof(f)){
        fscanf(f, "%s %s %d", s.student_id, s.student_name, &s.score);//Read a record
        s.grade = getGrade(s.score);//Get grade based upon score
        list = add(list, s);
    }
    fclose(f);//Close file
    return list;
}

//Function to return mean of student scores
double getMean(Node *list){
    Node *ptr = list;
    int n = 0;
    double mean = 0.0;
    while(ptr != NULL){
        mean += ptr->s.score;
        n++;
        ptr = ptr->next;
    }
    mean = mean/n;
    return mean;
}

//Function to return standard deviation of student scores
double getStandardDeviation(Node *list){
    Node *ptr = list;
    double mean = getMean(list);
    double sd = 0;
    int n = 0;
    while(ptr != NULL){
        sd += pow(ptr->s.score - mean, 2);
        n++;
        ptr = ptr->next;
    }
    sd = sqrt(sd/(n - 1));
    return sd;
}

//Function to search linked list for student with student id
void searchWithStudentID(Node *list, char *student_id){
    Node *ptr = list;
    while(ptr != NULL){
        if(strcmp(ptr->s.student_id, student_id) == 0){
            printf("student_id\tstudent_name\tscore\tgrade\n");
            printf("%s\t%s\t\t%d\t%c\n", ptr->s.student_id, ptr->s.student_name, ptr->s.score, ptr->s.grade);
            return;
        }
        ptr = ptr->next;
    }
    printf("No such student!\n");
}

//Function to change student score by searching linked list using student id
void changeScore(Node *list, char *student_id){
    Node *ptr = list;
    int score;
    while(ptr != NULL){
        if(strcmp(ptr->s.student_id, student_id) == 0){
            printf("Enter new score: ");
            scanf("%d", &score);
            ptr->s.score = score;
            ptr->s.grade = getGrade(score);
            return;
        }
        ptr = ptr->next;
    }
    printf("No such student!\n");
}

int main(){
    Node *list = NULL;//Create an empty list

    list = readFromFile(list);

    printf("Mean of student scores: %f\n", getMean(list));
    printf("Standard deviation of student scores: %f\n", getStandardDeviation(list));

    printf("\nSearching for student with id 2011710088:\n");
    searchWithStudentID(list, "2011710088");

    printf("\nSearching for student with id 2011710095:\n");
    searchWithStudentID(list, "2011710095");

    printf("\nChanging score of student with id 2011710088:\n");
    changeScore(list, "2011710088");

    printf("\nChanging score of student with id 2011710095:\n");
    changeScore(list, "2011710095");

    return 0;
}

Sample student.dat file:

| student.dat Notepad File Edit Format View Help 2011710086 Jack 77 2011710087 Abel 88 2011710088 Cain 83 2011710089 Eve 96 2

Sample terminal output:

CAUsers\Shubham\Desktop\readSquare.exe Mean of student scores: 82.500000 Standard deviation of student scores: 8.549854 Searc

FOR ANY HELP JUST DROP A COMMENT

Add a comment
Know the answer?
Add Answer to:
in C porgraming . use #include〈stdio.h〉 #include〈stdlib.h〉 Assignment 12 The program to write in this assignment...
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
  • please use the c language Assignment 12 The program to write in this assignment is a...

    please use the c language Assignment 12 The program to write in this assignment is a program that calculates score statistics and manages the grades of the students. First, the student list and are given in a file named "student.dat" as in the following: 이성우 77 홍길동 88 scores 201 1710086 2012700091 This program reads the input file "student.dat" and keeps this data in a linear linked list. Each node must be a struct which contains the following: student id...

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • C++ Write a program that reads the number of students in the class, then reads each...

    C++ Write a program that reads the number of students in the class, then reads each student's name and his/her test score. Print out each student name, test score and grade, and the average score of the whole class. The program must use vectors and loops for the implementation. The grades are determined as follows: A >= 90; 80 <= B < 90; 70 <= C < 80; 60 <= D < 70; F < 60.

  • codeblock c++ language Write a program that reads students test scores in the range 0-200 from...

    codeblock c++ language Write a program that reads students test scores in the range 0-200 from a file until end of file (use e of() to check if ifstream reaches the End of File Stream) and store those scores in an array. It should then determine the number of students having scores in each of the following ranges: 0-24, 25-49, 50-74, 75-99, 100- 124, 125–149, 150-174, and 175–200. Finally, the program outputs the total number of students, each score range...

  • C++ program that reads students' names followed by their test scores (5 scores) from the given...

    C++ program that reads students' names followed by their test scores (5 scores) from the given input file, students.txt. The program should output to a file, output.txt, each student's first name, last name, followed by the test scores and the relevant grade. All data should be separated by a single space. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, an array of testScores of type int...

  • THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA...

    THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA that reads students’ names followed by their test scores from "data.txt" file. The program should output "out.txt" file where each student’s name is followed by the test scores and the relevant grade, also find and print the highest test score and the name of the students having the highest test score. Student data should be stored in an instance of class variable of type...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • Write a c++ program which uses a structure having the indicated member names to store the...

    Write a c++ program which uses a structure having the indicated member names to store the following data: Name (student name) IDnum (student ID number) Tests (an array of three test scores) Average (average test score) Grade (course grade) The program will keep a list of three test scores for one student. The program may prompt the user for the name, ID number, and test scores, or these may be assigned within the program. The average test score will be...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • Please help me with this program.You are to write a C++ program that will read in...

    Please help me with this program.You are to write a C++ program that will read in up to 15 students with student information and grades. Your program will compute an average and print out certain reports. Format: The information for each student is on separate lines of input. The first data will be the student�s ID number, next line is the students name, next the students classification, and the last line are the 10 grades where the last grade is...

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
ADVERTISEMENT