In: Computer Science
Lab 1 Write a C program for a grade calculation to run on ocelot.
The source file should have your name & PantherID included in it and it should have an affirmation of originality stating something like: “I affirm that I wrote this program myself without any help form any other people or sources from the internet.”.
Code should be nicely indented using a consistent style and
commented appropriately.
An array should be used for each student, but it is not required as
long as all values are in variables.
Course is an array of characters.
Credits is an integer.
Grade is a floating point number.
Grade Points earned should be calculated as you print not stored in a variable.
There should be at least 6 courses listed.
There is no user input, all values should be hard coded in the
program Columns should be aligned as shown in the sample below.
Course column left justified.
Credits centered
Grade right justified
Grade Points Earned right justified
The grade points earned should be calculated in a formula with multiplication right while printing it out. It should not be stored as a variable.
Create a simple Makefile to compile your program into an executable called gpa.
You should submit the source code and your Makefile file compressed into a zip file named FirstNameLastNameL1.zip. The Makefile should be called Makefile with no extension. I should be able to type make at the command line to compile your program. Do not include any other files or folders in the zipfile. This applies even if you are a Mac user.
Programs that do not compile and do something useful when run will not earn any credit at all.
Sample Output:
Student Name: YourFirstName YourLastName Panther ID:
Course |
Credits |
Grade |
Grade Points Earned |
COP2210 |
3 |
4.00 |
12.00 |
ENC1101 |
3 |
2.67 |
8.01 |
CGS3095 |
3 |
3.00 |
9.00 |
Total |
9 |
29.01 |
Current GPA: 3.22
Find the C program Solution for the above question: You just need to makeFile to make it executable.
------------------------------------------------------------------------------------------------------------------------------------------------------
Program Below
#include <stdio.h>
#define COURSE_COUNT 6
struct StudentDetails {
char *course;
int credits;
float grade;
};
int main()
{
char firstName[15] = "YourFirstName", lastName[15] =
"YourLastName";
int pantherID = 1234;
int creditsSum = 0;
float gradePointsSum = 0;
/* ------------ Uncomment Below lines to take input from User
------------ */
// scanf("%s", firstName);
// scanf("%s", lastName);
// scanf("%d", pantherID);
printf("Student Name: %s %s", firstName, lastName);
printf("\nPanther ID: %d", pantherID);
/* ------------ Add Dummy Data Here ------------ */
struct StudentDetails student[] = {
{.course = "COP2210", .credits = 3, .grade = 4.00},
{.course = "ENC1101", .credits = 3, .grade = 2.67},
{.course = "CGS3095", .credits = 3, .grade = 3.00},
{.course = "SCP2210", .credits = 3, .grade = 5.00},
{.course = "MAP4610", .credits = 3, .grade = 3.50},
{.course = "SSP2910", .credits = 3, .grade = 4.50}
};
/* ---------------------------------Printing Starts
Here--------------------------------------- */
printf("\n%s \t%s \t%s \t%s\n", "Course", "Credits", "Grade",
"Grade Points Earned");
for(int i=0; i<COURSE_COUNT; i++)
{
float gradePointsEarned =
student[i].credits*student[i].grade;
creditsSum += student[i].credits;
gradePointsSum += gradePointsEarned;
printf("%s \t%d \t%.2f \t%.2f\n", student[i].course,
student[i].credits, student[i].grade, gradePointsEarned);
}
printf("%s \t\t%d \t \t%.2f", "Total", creditsSum,
gradePointsSum);
printf("\nCurrent GPA: %.2f", gradePointsSum/creditsSum);
return 0;
}