Question

In: Computer Science

GPA calculator in C language To understand the value of records in a programming language, write...

GPA calculator in C language

To understand the value of records in a programming language, write a small program in a C-based language that uses an array of structs that store student information, including name, age, GPA as a float, and grade level as a string (e.g., “freshmen,” etc.).

Note:Code and Output Screenshots

Solutions

Expert Solution

//c code for reading students information and computing GPA based on percentage

#include<stdio.h>
struct student
{
char name[20];
int age;
float percentage;
float GPA;
char gradelevel[20];
} s[3];//store information of 3 students
int main()
{
int i;
printf("Enter information of students:\n");
// storing information
for(i=0; i<3; ++i)
{
printf("Enter name: ");
scanf("%s",s[i].name);
printf("Enter Age: ");
scanf("%d",&s[i].age);
printf("Enter percentage: ");
scanf("%f",&s[i].percentage);
printf("Enter gradelevel: ");
scanf("%s",s[i].gradelevel);

//computing GPA
if(s[i].percentage>=94)
s[i].GPA=4.0;
else if(s[i].percentage>=90&&s[i].percentage<94)
s[i].GPA= 3.7;
else if(s[i].percentage>=87&&s[i].percentage<90)
s[i].GPA= 3.3;
else if(s[i].percentage>=83&&s[i].percentage<87)
s[i].GPA= 3.0;
else if(s[i].percentage>=80&&s[i].percentage<84)
s[i].GPA= 2.7;
else if(s[i].percentage>=77&&s[i].percentage<80)
s[i].GPA= 2.3;
else if(s[i].percentage>=73&&s[i].percentage<77)
s[i].GPA= 2.0;
else if(s[i].percentage>=70&&s[i].percentage<73)
s[i].GPA= 1.7;
else if(s[i].percentage>=67&&s[i].percentage<70)
s[i].GPA= 1.3;
else if(s[i].percentage>=60&&s[i].percentage<67)
s[i].GPA= 1.0;
else
s[i].GPA=0.0;
printf("\n---------------------------------\n");
}
  
printf("Displaying Information:\n\n");
// displaying information
for(i=0; i<3; i++)
{
printf ("\n--------student :%d---------",i+1);
printf("\nName: %s",s[i].name);
printf("\nAge: %d\n",s[i].age);
printf("\npercentage: %.2f",s[i].percentage);
printf("\nGPA : %.1f",s[i].GPA);
printf("GradeLevel : %s",s[i].gradelevel);
}
return 0;
}

program without input, storing two student records and prints GPA and gradelevel

#include<string.h>
#include<stdio.h>
struct student
{
char name[20];
int age;
float percentage;
float GPA;
char gradelevel[20];
} s[3];//store information of 3 students

int main()
{
int i;
strcpy(s[0].name,"Alice");
s[0].age=23;
s[0].GPA=4.0;
strcpy(s[0].gradelevel,"freshmen");


strcpy(s[1].name,"BOB");
s[1].age=24;
s[1].GPA=3.0;
strcpy(s[1].gradelevel,"junior");

for(i=0; i<2; i++)
{
printf("\n--------student-%d---------\n",i+1);
printf("\nGPA : %.1f\n",s[i].GPA);
printf("\nGradeLevel : %s\n\n",s[i].gradelevel);
}
return 0;
}


Related Solutions

C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
Programming in C language (not C++) Write a runction derinition for a function called SmallNumbers that...
Programming in C language (not C++) Write a runction derinition for a function called SmallNumbers that will use a while loop. The function will prompt the user to enter integers ine by one, until the user enters a negative value to stop. The function will display any integer that is less than 25. Declare and initialize any variables needed. The function takes no arguments and has a void return type.
In C programming language, write the program "3x3" in size, calculating the matrix "c = a...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a * b" by reading the a and b matrices from the outside and writing on the screen?
Code in C++ programming language description about lesson Calculator (multiple, sum, dived, sub) example.
Code in C++ programming language description about lesson Calculator (multiple, sum, dived,  sub) example.
In programming C language, write a program that creates a binary tree of words to be...
In programming C language, write a program that creates a binary tree of words to be used as a spell checking device for various text files. The list of words will come from a file “words.txt”. Your program is to read through the “words.txt” file and insert the word on that line into the tree in lexicographic order (also known as Dictionary order). Words in the file will be separated by spaces. Once this is done, your program should then...
C Language - Programming Write a function that takes an array of ints, and the size...
C Language - Programming Write a function that takes an array of ints, and the size of the array – another int. It also returns a double. Call this one ‘average.’ Return a double that is the average of the values in the array. Demonstrate that it works by finding the average of an array with these values {78, 90, 56, 99, 88, 68, 92} Write a function that takes one double parameter, and returns a char. The parameter represents...
In programming C language, write a program that creates a binary tree of words to be...
In programming C language, write a program that creates a binary tree of words to be used as a spell checking device for various text files. The list of words will come from a file “words.txt”. Your program is to read through the “words.txt” file and insert the word on that line into the tree in lexicographic order (also known as Dictionary order). Words in the file will be separated by spaces. Once this is done, your program should then...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
C++ programming language. Write a program that will read in id numbers and place them in...
C++ programming language. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please...
In C Programming Language Write a program to output to a text log file a new...
In C Programming Language Write a program to output to a text log file a new line starting with day time date followed by the message "SUCCESSFUL". Please screenshot the results.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT