Question

Write a program in C language that reads scores and id numbers from a file, finds...

Write a program in C language that reads scores and id numbers from a file, finds the average score, and assigns each student a grade based on the following rules:

Each score > average + 20 gets an A
Each score between average + 10 and average + 20 gets a B
Each score between average - 10 and average + 10 gets a C
Each score between average - 20 and average - 10 gets a D
Each score < average - 20 gets an F.

The main program has been completed. I need to convert each stub to a working module. Here are the remaining stubs:

double findAverage(double s[], int num)
{
//Another stub.  Re-write this so that it finds the average of the
//doubles stored in the first num locations of s[], and returns
//that average
  printf("You successfully called findAverage.\n");
  return 50.0;
}
void assignGrades(double s[], char g[], int num, double average) 
{
//Yet another stub.  Re-write it so that it fills the array g[] with
//grades using the rules defined at the start of this page
  printf("You successfully called assignGrades.\n");
}


void  printSummary(double s[], int ids[], char g[], int numScores, double average) 
{
//The last stub.  Re write it so that it prints a table.  The first
//column should be id numbers. The second column should be the corresponding
//scores.  The third column the amount by which the score differs from the
//average.  The final column should be the corresponding letter grade.
  printf("You successfully called printSummary.\n");
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the C code I hope that i have provided sufficient comments for your better understanding Note that I have done proper indentation but this code is automatically left alligned on this interface


double findAverage(double s[], int num)
{
int i;
double sum = 0.0, average;
for(i = 0; i < num; ++i)
{
sum += s[i]; //Add every element
}
average = sum / num;
printf("You successfully called findAverage.\n");
return average;
}
void assignGrades(double s[], char g[], int num, double average)
{
int i;
for(i = 0; i < num; ++i)
{
//Assign grades as specified
if(s[i]>average+20)
g[i]='A';
else if(s[i]>average+10)
g[i]='B';
else if(s[i]>average-10)
g[i]='C';
else if(s[i]>average-20)
g[i]='D';
else
g[i]='F';
}
printf("You successfully called assignGrades.\n");
}
void printSummary(double s[], int ids[], char g[], int numScores, double average)
{
int i;
for(i=0;i<numScores;i++)
{
printf("%d\t%lf\t%lf\t%c\n",ids[i],s[i],s[i]-average,g[i]);
}
printf("You successfully called printSummary.\n");
}

I have tried to explain it in very simple language and I hope that i have answered your question satisfactorily.Leave doubts in comment section if any

Add a comment
Know the answer?
Add Answer to:
Write a program in C language that reads scores and id numbers from a file, finds...
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
  • Write a program that dynamically allocates an array in the freestore large enough to hold a...

    Write a program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another function the array should be passed to a function that finds the lowest score. Another function should be called that calculates the average score. The program should show the highest, lowest and average scores. Must use...

  • Write a program that dynamically allocates an array in the freestore large enough to hold a...

    Write a program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another function the array should be passed to a function that finds the lowest score. Another function should be called that calculates the average score. The program should show the highest, lowest and average scores. Must use...

  • C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you...

    C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you can. Level 1: (20 points) Write FUNCTIONS for each of the following: a) Validate #students, #scores. b) Compute letter grade based on average. c) Display student letter grade. d) Display course average. Level 2: (15 points) Use ARRAYS for each of the following. e) Read a student's scores into array. f) Calculate the student's average based on scores in array. g) Display the student's...

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

  • Given the following program: #include <stdio.h> struct student { int id; char name[20]; char grade; };...

    Given the following program: #include <stdio.h> struct student { int id; char name[20]; char grade; }; void func(struct student stud); int main() { struct student astud; astud.id=9401; strcpy(astud.name, "Joe"); astud.grade = 'A'; func(astud); return 0; } Abdelghani Bellaachia, CSCI 1121 Page: 16 void func(struct student astud) { printf(" Id is: %d \n", astud.id); printf(" Name is: %s \n", astud.name); printf(" Grade is: %c \n", astud.grade); } Modify this program to include the address of a student as a separate structure....

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

  • Write a C Program that inputs an array of integers from the user along-with the length...

    Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...

  • ASSIGNMENT #3 ** using System; namespace GradeCalculatorNew {    class MainClass    {        public...

    ASSIGNMENT #3 ** using System; namespace GradeCalculatorNew {    class MainClass    {        public static void Main (string[] args)        {            int test1,test2,test3;            double average,average2;            char letterGrade;            Console.WriteLine("Enter test score1");            test1=Convert.ToInt32(Console.ReadLine());            Console.WriteLine("Enter test score2");            test2=Convert.ToInt32(Console.ReadLine());            Console.WriteLine("Enter test score3");            test3=Convert.ToInt32(Console.ReadLine());            average=(test1+test2+test3)/3.0;            average=(int)(average+0.5);           ...

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

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