In this assignment, we will develop an algorithm to calculate the final grade fo
ID: 3561600 • Letter: I
Question
In this assignment, we will develop an algorithm to calculate the final grade for a class of 25 students. There are 10 assignments (20 points each) as well a midterm and a final (100 points each). Another 20 points are for in-class participation.
All the assignments and tests contribute to the final grade equally. Additionally, the in-class participation (either thru Discussions or in real-time) is also a part of the final grade.
This is a fairly simple assignment and we will use it to get into the habit of following good design and coding practices.
First, we analyze the problem (perhaps break it into a couple of pieces), develop a flow-chart or pseudocode. Include the pseudocode in your program as comments.
Next, we code the algorithm in Python along with comments and documentation, and make sure it runs successfully. For the code, we define a MAIN program (or driver) as well as a few functions and methods (e.g. get_grades, cumulate_total_points, determine_final_grade, ....) These should be invoked by the driver via function calls and with arguments passed back and forth.
In the end we display all the students net-ID and their final grade in a table format.
Since this is an interactive program, make sure we display meaningful headings and instructions/prompts to the end-user. Also please up load the .py file for me to execute.
Please let me know if you have further question
Explanation / Answer
#include <stdio.h>
#include <ctype.h>
#define NAME_LEN 50
#define STUD_LEN 25
int read_line(char str[], int n);
int find_students(int students);
struct test_result {
char name[NAME_LEN+1];
int number;
int assignment;
int midterm;
int final;
float numeric;
}studen[STUD_LEN];
void insert(void);
void print(void);
int num_students = 0;
int main(void)
{
struct test_result test;
printf("Enter the student's name: ");
read_line(test.name, NAME_LEN);
printf("Enter the student's points for 10 assignment: ");
scanf("%d", &test.assignment);
printf("Enter the student's points for midterm: ");
scanf("%d", &test.midterm);
printf("Enter the student's points for final: ");
scanf("%d", &test.final);
test.numeric = (((test.assignment * 0.5) + (test.midterm * 1) + (test.final * 1));
printf("%s's numeric score for the entire course is %.1f ", test.name, test.numeric);
char code;
for (;;)
{
printf(" ");
printf("Would you like to enter another student record? y(yes) or n(no)?");
scanf(" %c", &code);
while (getchar() != ' ') /* skips to end of line */
;
switch (code) {
case 'y': insert();
break;
case 'n': print();
return 0;
default: printf("Invalid entry. Try again. ");
return 0;
}
}
}
int find_students(int students)
{
int i;
for (i = 0; i < num_students; i++)
if (studen[i].number == students)
return i;
return -1;
}
void insert(void)
{
int part_number;
if (num_students == STUD_LEN) {
printf("Sorry, cannot enter any more students. ");
return;
}
studen[num_students].number = part_number;
printf("Enter the student name: ");
read_line(studen[num_students].name, NAME_LEN);
printf("Enter the student's points for assignment: ");
scanf("%d", &studen[num_students].assignment);
printf("Enter the student's points for midterm: ");
scanf("%d", &studen[num_students].midterm);
printf("Enter the student's points for final: ");
scanf("%d", &studen[num_students].final);
studen[num_students].numeric =
(((studen[num_students].assignment * 0.5) + (studen[num_students].midterm * 1) + (studen[num_students].final * 1));
printf("%s's numeric score for the entire course is %.1f ", studen[num_students].name, studen[num_students].numeric);
num_students++;
}
void print(void)
{
printf("The score on assignment is ");
printf("The score on midterm is ");
printf("The score on the final is ");
printf("The score for the entire course is ");
}
int read_line(char str[], int n)
{
int ch, i = 0;
while(isspace(ch = getchar()))
;
str[i++] = ch;
while ((ch = getchar()) != ' ') {
if (i < n)
str[i++] = ch;
}
str[i] = '';
return i;
}