Question

Problem 2. Calculate Grades (35 points) Arrays can be used for any data type, such as int and char. But they can also be usedPlz help!! The programming language is C and could you write comments as well?

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

#include <stdio.h>

#include <stdlib.h> //For using the malloc() function

#include <math.h> //For using sqrt() and floor() functions

struct Grades      //Creating the structure Grades

{

                int attendance;

                float final_grade;

                int test_grades[4]; //For storing the four test grades

               

};

struct Student   //Creating the structure Student

{

    int UIN;

    struct Grades grades;

};

void inputStudent(struct Student *s) //For inputting the information of student

{

    scanf("%d",&s->UIN);

    scanf("%d",&s->grades.attendance);

    scanf("%d",&s->grades.test_grades[0]);

    scanf("%d",&s->grades.test_grades[1]);

    scanf("%d",&s->grades.test_grades[2]);

    scanf("%d",&s->grades.test_grades[3]);

}

void calculateGrades(struct Student class[],int nStudents) //For calculating the grades of each student

{

    int i,attendance,max_attendance=25,avg_grades;

    float final_grade;

   

    for(i=0;i<nStudents;i++)

    {

        avg_grades=(class[i].grades.test_grades[0]+class[i].grades.test_grades[1]+class[i].grades.test_grades[2]+class[i].grades.test_grades[3])/4;

       

        attendance=class[i].grades.attendance;

       

        final_grade=floor(10 * sqrt(avg_grades*0.95 + (attendance/max_attendance)*5));

       

        class[i].grades.final_grade=final_grade;

    }

}

void printGrades(struct Student class[],int nStudents) //For printing the information about each student

{

    int i;

    for(i=0;i<nStudents;i++)

    {

        printf("\nUIN= %d ",class[i].UIN);

        printf("final_grade=%.2f ",class[i].grades.final_grade);

       

        if(class[i].grades.final_grade >=50 )

            printf("PASS");

        else

            printf("FAIL");

    }

}

int main()

{

    int nStudents,i;

    struct Student *class;   //Declaring the pointer variable which will work as a array

   

    printf("Number of Students: ");

    scanf("%d",&nStudents);

   

    class = (struct Student *) malloc(sizeof(struct Student)*nStudents); //Allocating memory to the pointer variable

   

    for(i=0;i<nStudents;i++) //Looping through the no of students for inputting the information

        inputStudent(&class[i]);

   

    calculateGrades(class,nStudents); //Calling the function to calculate final_grade of each studennt

   

    printGrades(class,nStudents); //Calling the function to print the UIN, final_grade and PASS/FAIL

   

    return 0;

}

I C Computer Science question | Che Online C Compiler -online editor+ С https://www.onlinegdb.com/online_c.compiler Run O Deb

Add a comment
Know the answer?
Add Answer to:
Plz help!! The programming language is C and could you write comments as well? Problem 2....
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...

  • C programming. 1.Create a program that does the following - Creates three pointers, a character pointer...

    C programming. 1.Create a program that does the following - Creates three pointers, a character pointer professor, and two integer pointers student_ids, grades - Using dynamic memory, use calloc to allocate 256 characters for the professor pointer - Prompts the professor for their name, and the number of students to mark. - Stores the professor’s name using the professor pointer and in an integer the number of students to mark. - Using dynamic memory, use malloc to allocate memory for...

  • C++ Assignment on Search and Sort for Chapter 8 Problem: Modify the student grade problem to...

    C++ Assignment on Search and Sort for Chapter 8 Problem: Modify the student grade problem to include the following: •   Write a Search function to search by student score •   Write a Search function to search by student last name •   Write a Sort function to sort the list by student score •   Write a Sort function to sort the list by student last name •   Write a menu function that lets user to choose any action he/she want to...

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

  • use c++ Weighted GPA Calculator2 Many schools factor in the number of credits each course is...

    use c++ Weighted GPA Calculator2 Many schools factor in the number of credits each course is worth, meaning a 4-credit class has more value than a 2-credit class when calculating students GPA Suppose the following were the grades for a student CreditsGrade lass Pre-Calculus History Chemistry Physical Education 1 Letter grades are assigned as follows Letter grades are worth these points 0-60 F 61 -70 D 71 80 C 81 -90 B 91 -100 A Class Pre-Calculus History Chemistr)y Physical...

  • using C++ language!! please help me out with this homework In this exercise, you will have...

    using C++ language!! please help me out with this homework In this exercise, you will have to create from scratch and utilize a class called Student1430. Student 1430 has 4 private member attributes: lastName (string) firstName (string) exams (an integer array of fixed size of 4) average (double) Student1430 also has the following member functions: 1. A default constructor, which sets firstName and lastName to empty strings, and all exams and average to 0. 2. A constructor with 3 parameters:...

  • 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++ The programming language is c++ our program using the following data Mary Smith Green walley...

    C++ The programming language is c++ our program using the following data Mary Smith Green walley Thul Bool Gauteng ) Please key is the n ot your Ter in your mark for Mathematics Ey in your mark for use orientation Key in your mark for watory Wer in your work for Computer literacy Te in r for at e Jobs Africa School: King College 9/11 - Average Year Wark53.67 with label and code The T a QUESTION 2: (40) Suppose...

  • Using C programming For this project, you have been tasked to read a text file with student grade...

    Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...

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