Category Description of Violation # Points Deducted Comments: No block comment a
ID: 3638125 • Letter: C
Question
Category
Description of Violation
# Points Deducted
Comments:
No block comment at beginning of program/your name not in comment.
-10
Vague, non-descriptive comments.
-2 for each
No block comments in code.
-10
Variables:
Non-descriptive variable names
(except for loop-control variables.)
-3 for each
Variables declared, but not used.
-3 for each
Unnecessary initialization of variables during declaration.
-3 for each
Global Variables - DO NOT USE
-10 for each
goto statements - DO NOT USE
-10 for each
Inefficient code (subjectively determined by instructor)
-5 for each
Indentation:
Not following indentation standards.
-3 for each
Inconsistent indentation.
-3 for each
Block Marker alignment (i.e. not same indent for begin/end markers { and })
-3 for each
Correctness:
Program does not produce correct results.
-5 to -15
Prompts not formatted as assigned.
-2 to -15
Program output not formatted as assigned.
-2 to -15
Miscellaneous - at the instructors discretion
-3 to -10 for each
Use of // comments – Avoid
-2 for each
Misc:
goto statements - DO NOT USE
-10 for each
Inefficient Code
-5 for each
Other (at instructors discretion).
-1 to -10
Program does not conform to ANSI standards
-10
Program uses statements not yet introduced
-5 for each occurrence
Use fflush(stdin); after each scanf
-2 for each not used
Misc. mistakes: not following instructions, program naming, etc.
-2 to -10 each
Late Assignments
-5 first day then
-1 per day afterwards
PROGRAMMING ASSIGNMENT #1
Write a C program that determines the minimum grade, maximum grade, median grade and class average of an exam. Your program should first prompt for how many grades, then each of the grades. Your program should test that each value entered is valid (i.e., between 0 and 100). If the grade entered is not valid, the program should issue an error message as shown below, and re-prompt for a correct grade. Once all grades are entered, your program should calculate the minimum grade, maximum grade, and class average, and median for that exam. It will then print the grades listed in Ascending order (sorted). The program without the sort will be worth 90 points.
Your program should store all the grades entered in integer array: grades[100].
The dialog with the user must look exactly like:
Welcome to the Grade Calculator
Enter the number of grades to process (0 - 100): 10
Enter grade for student #1: 80
Enter grade for student #2: 90
Enter grade for student #3: 100
Enter grade for student #4: 85
Enter grade for student #5: 172
*** Invalid grade entered. Please enter 0 - 100. ***
Enter grade for student #5: 72
Enter grade for student #6: 65
Enter grade for student #7: 96
Enter grade for student #8: 70
Enter grade for student #9: 73
Enter grade for student #10: 100
The minimum grade is 65
The maximum grade is 100
The class average is 83
The median grade is 82.5
The 10 Grades entered were:
65, 70, 72, 73, 80, 85, 90, 96, 100, 100
Note: The coral text represents the "output" from your program and is shown for clarity only here. It is not required that your output be in this color. (Do not even attempt to try!). Also note that what the user types in is indicated by the blue area above. Again, for clarity only. Once the user enters a valid number of grades to process, the program should run as described above, but prompt for ONLY the number of grades entered by the user. If the user chooses to enter 0 (or fewer) grades, the program should simply end (appropriate exit message of your choice). Do not use the qsort() function from the Standard C Library.
*** Sample Algorithm for Assignment #1 ***
Note: This assignment can be solved many different ways. This algorithm simply illustrates one possible solution. Please feel free to ignore this algorithm and use your own design to solve this problem if desired.
1. Trap loop to prompt for number of grades(min 0 max 100)
2. Initialize stuff:
2.1 Set “minimum” equal to zero.
2.2 Set “maximum” equal to zero.
2.3 Set “sum” equal to zero.
3. Trap LOOP for each grade (grades[0] – grades[n]) with edits.
{
Keep running total of “sum” of grades:
Add each (good) grade to “sum” of grades.
}
4. Calculate average as:
“sum” of grades divided by number of grades.
5. Sort the stored array in ascending order with a bubble sort.
6. Display results:
6.1 Display minimum grade.
6.2 Display maximum grade.
6.3 Display class average.
7. Calculate the median.
7.1 If odd number entered grade[(n+1)/2]
7.2 if even number entered, (grade[n/2] + grade[n/2+1])/2
7.3 Display median
8. Print loop to print the sorted array.
code
#include <stdio.h>
#define NUM_GRADES 10
main()
{
int grades[NUM_GRADES], num, max = 0, min = 105, sum = 0, x, s, temp;
float average,med;
printf("Welcome to the Grade Calculator ");
printf("Enter the number of grades to process (0 - 100): ");
scanf("%i", &num);
fflush(stdin);
if(num > 100)
{
printf(" *** Error: Number of grades is invalid *** ");
printf("Enter the number of grades to process (0 - 100): ");
scanf("%i", &grades);
fflush(stdin);
}
printf(" ");
for(x = 0; x < num; x++)
{
do
{
printf("Enter grade for student #%i: ", x + 1);
scanf("%i", &grades[x]);
fflush(stdin);
if(grades[x] < 0 || grades[x] > 100)
printf(" *** Invalid grade entered. Please enter 0 - 100. *** ");
}while(grades[x] < 0 || grades[x] > 100);
sum = sum + grades[x];
if(grades[x] > max)
max = grades[x];
if(grades[x] < min )
min = grades[x];
}
printf(" ");
average = (float)sum / num;
printf("The minimum grade is %d ", min);
printf("The maximum grade is %d ", max);
printf("The class average is %f ", average);
for(x=0;x<num-1;x++)
for(s=x+1;s<num;s++)
if(grades[x]>grades[s])
{temp=grades[s];
grades[s]=grades[x];
grades[x]=temp;
}
if(NUM_GRADES % 2 == 0)
med = (grades[x/2] + grades[x/2+1])/2.;
else
med = grades[(x + 1)/ 2];
printf("The median grade is %.1f ", med);
printf("The %d Grades entered were: ",num);
for(x = 0; x < num; x++)
printf("%i ", grades[x]);
printf(" ");
getch();
return 0;
}
Explanation / Answer
please rate - thanks
my opinion and I've been teaching and coding for 40 years
Category
Description of Violation
# Points Deducted
Comments: you have none-I have added some as an example
No block comment at beginning of program/your name not in comment.
-10
Vague, non-descriptive comments.
-2 for each
No block comments in code.
-10
Variables: I'm not crazy about x and s for loop indeces, generally i, and j are used, but if that's what you learned, that's what you use
Non-descriptive variable names
(except for loop-control variables.)
-3 for each
Variables declared, but not used. looks good
-3 for each
Unnecessary initialization of variables during declaration. looks good
-3 for each
Global Variables - DO NOT USE
-10 for each
goto statements - DO NOT USE
-10 for each
Inefficient code (subjectively determined by instructor)
-5 for each
Indentation: this has to be fixed, I fixed it to how I would do it, but follow your professors standards
Not following indentation standards.
-3 for each
Inconsistent indentation.
-3 for each
Block Marker alignment (i.e. not same indent for begin/end markers { and })
-3 for each
all this I'd be okay with
Correctness:
Program does not produce correct results.
-5 to -15
Prompts not formatted as assigned.
-2 to -15
Program output not formatted as assigned.
-2 to -15
Miscellaneous - at the instructors discretion
-3 to -10 for each
Use of // comments – Avoid
-2 for each
Misc:
goto statements - DO NOT USE
-10 for each
Inefficient Code
-5 for each
Other (at instructors discretion).
-1 to -10
Program does not conform to ANSI standards
-10
Program uses statements not yet introduced
-5 for each occurrence
Use fflush(stdin); after each scanf
-2 for each not used
Misc. mistakes: not following instructions, program naming, etc.
-2 to -10 each
/*
name:
class:
date:
purpose of program:
*/
#include <stdio.h>
#include <conio.h>
#define NUM_GRADES 10
main()
{/*declacations and initializations
*/
int grades[NUM_GRADES], num, max = 0, min = 105, sum = 0, x, s, temp;
float average,med;
/*get number of grades
and check for validity.
if a number is entered that is out of range
keep asking for a new number
*/
printf("Welcome to the Grade Calculator ");
printf("Enter the number of grades to process (0 - 100): ");
scanf("%i", &num);
fflush(stdin);
if(num > NUM_GRADES||num<0)
{printf(" *** Error: Number of grades is invalid *** ");
printf("Enter the number of grades to process (0 - 100): ");
scanf("%i", &grades);
fflush(stdin);
}
printf(" ");
for(x = 0; x < num; x++)
{do
{printf("Enter grade for student #%i: ", x + 1);
scanf("%i", &grades[x]);
fflush(stdin);
if(grades[x] < 0 || grades[x] > 100)
printf(" *** Invalid grade entered. Please enter 0 - 100. *** ");
}while(grades[x] < 0 || grades[x] > 100);
sum = sum + grades[x];
if(grades[x] > max)
max = grades[x];
if(grades[x] < min )
min = grades[x];
}
printf(" ");
/*
if there are no numbers entered
all the values will be 0
*/
if(num==0)
{min=0;
max=0;
average=0;
med=0;
}
else
/*
if there are numbers entered
calculate average
sort the numbers
and find the mean
*/
{average = (float) sum / num;
for(x=0;x<num-1;x++)
for(s=x+1;s<num;s++)
if(grades[x]>grades[s])
{temp=grades[s];
grades[s]=grades[x];
grades[x]=temp;
}
if(NUM_GRADES % 2 == 0)
med = (grades[x/2] + grades[x/2+1])/2.;
else
med = grades[(x + 1)/ 2];
}
/*
output all information
*/
printf("The minimum grade is %d ", min);
printf("The maximum grade is %d ", max);
printf("The class average is %.1f ", average);
printf("The median grade is %.2f ", med);
printf("The %d Grades entered were: ",num);
for(x = 0; x < num; x++)
printf("%i ", grades[x]);
printf(" ");
getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.