Question

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#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 2Sample terminal output:CAUsers\Shubham\Desktop\readSquare.exe Mean of student scores: 82.500000 Standard deviation of student scores: 8.549854 Searc

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

    in C porgraming . use #include〈stdio.h〉 #include〈stdlib.h〉 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 scores are given in a file named "student.dat" as in the following: 이성우 77 홍길동 88 2011710086 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,...

  • 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...

  • 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...

  • 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.

  • 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...

  • 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...

  • C++ Write a program that reads students’ names followed by their test scores from the given...

    C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...

  • In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a tes...

    In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...

  • 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...

  • [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:...

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