1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
|
#include <stdio.h>
#include <stdlib.h>
/* NOTE you can't change my main */
const int MAX = 100;
const int ASSIGN_TOTAL = 7, QUIZ_TOTAL = 3, EXAMS_TOTAL = 2;
const int ASSIGN_MAX = 100, QUIZ_MAX = 25, EXAMS_MAX = 100, FINAL_MAX = 100;
char readName(char name[]);
float fillArray(int x[], int num, int k);
int goAgain();
int selectionSort(int myScore[], int total);
int findMedian(int myPapery[], int num);
int findMean(int myPaperx[], int num);
float calcPercentage(int papers[], int total, int max);
float readFinalScore();
float calcfinalPercentage(int exam, int max1);
float calcGrade(double assignsPerc, double quizzesPerc, double examsPerc, double finalPerc);
float calcClassPerc(double assignsPerc, double quizzesPerc, double examsPerc, double finalPerc);
displayResults(char name, double classPerc, double classGrade,
double assignsPerc, double quizzesPerc, double examsPerc, double finalPerc,
double assignsMean, double quizzesMean, double examsMean,
double assignsMedian, double quizzesMedian, double examsMedian);
int main()
{
char name[MAX];
int assigns[ASSIGN_TOTAL], quizzes[QUIZ_TOTAL], exams[EXAMS_TOTAL], finalExam;
double assignsMedian, assignsMean, assignsPerc;
double quizzesMedian, quizzesMean, quizzesPerc;
double examsMedian, examsMean, examsPerc, finalPerc, classPerc, classGrade;
do
{
readName(name);
fillArray(assigns, ASSIGN_TOTAL, "assignments");
selectionSort(assigns, ASSIGN_TOTAL);
assignsMedian = findMedian(assigns, ASSIGN_TOTAL);
assignsMean = findMean(assigns, ASSIGN_TOTAL);
assignsPerc = calcPercentage(assigns, ASSIGN_TOTAL, ASSIGN_MAX);
fillArray(quizzes, QUIZ_TOTAL, "quizzes");
selectionSort(quizzes, QUIZ_TOTAL);
quizzesMedian = findMedian(quizzes, QUIZ_TOTAL);
quizzesMean = findMean(quizzes, QUIZ_TOTAL);
quizzesPerc = calcPercentage(quizzes, QUIZ_TOTAL, QUIZ_MAX);
fillArray(exams, EXAMS_TOTAL, "exams");
selectionSort(exams, EXAMS_TOTAL);
examsMedian = findMedian(exams, EXAMS_TOTAL);
examsMean = findMean(exams, EXAMS_TOTAL);
examsPerc = calcPercentage(exams, EXAMS_TOTAL, EXAMS_MAX);
finalExam = readFinalScore();
finalPerc = calcfinalPercentage(finalExam, FINAL_MAX);
classPerc = calcClassPerc(assignsPerc, quizzesPerc, examsPerc, finalPerc);
classGrade = calcGrade(assignsPerc, quizzesPerc, examsPerc, finalPerc);
displayResults(name, classPerc, classGrade,
assignsPerc, quizzesPerc, examsPerc, finalPerc,
assignsMean, quizzesMean, examsMean,
assignsMedian, quizzesMedian, examsMedian);
}while(goAgain());
return 0;
}
//**************************************************************************************//
char readName(char name[])
{
printf("\nName: ");
gets(name);
return;
}
//**************************************************************************************//
float fillArray(int x[], int num, int k)
{
int i;
for(i = 0; i < num; i++)
{
printf("\nScore for %s %d: ", k, i+1);
scanf(" %d", &x[i]);
}
}
//**************************************************************************************//
int goAgain()
{
char answer;
printf("\nWould you like to calculate another set of scores (Y/N) ");
scanf(" %c", &answer);
if(answer != 'n' && answer != 'N')
{
return answer;
}
else
{
return 0;
}
}
//**************************************************************************************//
int selectionSort(int myScore[], int total)
{ int lim,
hole;
for ( lim = 1 ; lim < total ; lim++ ) //Credit Tim Rolfe
{ int save = myScore[lim]; //Lecture 02-12-2015 Chapter 23 Sorting Arrays
for ( hole = lim ;
hole > 0 && save < myScore[hole-1] ;
hole-- )
{ myScore[hole] = myScore[hole-1]; }
myScore[hole] = save;
}
}
//**************************************************************************************//
int findMedian(int myPapery[], int num)
{
int middle1, middle2, i;
float median, median2;
middle1 = num / 2;
middle2 = (num/2)-1;
if ((num % 2) == 0)
{
median = (myPapery[middle1] + myPapery[(middle2)]);
median = median /2;
}
else
{
median = myPapery[middle1 + 0] / 1;
}
return median;
}
//**************************************************************************************//
int findMean(int myPaperx[], int num)
{
int i, sum;
float sum1;
for(sum = i = 0; i < num; i++)
{
sum += myPaperx[i];
sum1 = (float)sum / num;
}
return sum1;
}
//**************************************************************************************//
float calcPercentage(int papers[], int total, int max)
{
int i, sum;
float perc;
for(sum = i = 0; i < total; i++)
{
sum += papers[i];
perc = (((float)sum/(total*max))*100);
}
printf(" SUM: %d\n", sum);
printf(" PERC: %f\n", perc);
return perc;
}
//**************************************************************************************//
float readFinalScore(int last)
{
printf("\nScore for Final Exam: ");
scanf(" %d", &last);
return last;
}
//**************************************************************************************//
float calcfinalPercentage(int exam, int max1)
{
float sum;
sum = (((float)exam/max1)*100);
printf("\n %f", sum);
return sum;
}
//**************************************************************************************//
float calcClassPerc(double assignsPerc, double quizzesPerc, double examsPerc, double finalPerc)
{
double grade1, grade2, grade3, grade4, overallGrade;
grade1 = (assignsPerc * 0.40);
grade2 = (quizzesPerc * 0.10);
grade3 = (examsPerc * 0.25);
grade4 = (finalPerc * 0.25);
overallGrade = (grade1 + grade2 + grade3 + grade4);
return overallGrade;
}
//**************************************************************************************//
float calcGrade(double assignsPerc, double quizzesPerc, double examsPerc, double finalPerc)
{
double grade, grade1, grade2, grade3, grade4, overallGrade, x, sum1, sum;
grade1 = (assignsPerc * 0.40);
grade2 = (quizzesPerc * 0.10);
grade3 = (examsPerc * 0.25);
grade4 = (finalPerc * 0.25);
overallGrade = (grade1 + grade2 + grade3 + grade4);
if (overallGrade >= 95)
{
grade = 4.0;
}
else
{
sum = 95 - overallGrade;
sum1 = sum/10;
grade = 4.0 - sum1;
}
return grade;
}
//**************************************************************************************//
displayResults(char name, double classPerc, double classGrade,
double assignsPerc, double quizzesPerc, double examsPerc, double finalPerc,
double assignsMean, double quizzesMean, double examsMean,
double assignsMedian, double quizzesMedian, double examsMedian)
{
printf("\nPercentage per category:");
printf("\n\nAssignments: %.0lf%%", assignsPerc);
printf("\n\nQuizzes: %.0f%%", quizzesPerc);
printf("\n\nExams: %.0f%%", examsPerc);
printf("\n\nFinal Exam: %.0f%%", finalPerc);
printf("\n %s:", name);
printf("\n\nYour weighted percentage is: %.0f%% ", classPerc);
printf("\n\nYour Grade point is %.1f", classGrade);
printf("\n\nFor assignments the average score was %.0lf and the median score was %.0lf\n", assignsMean, assignsMedian);
printf("\nFor quizzes the average score was %.0lf and the median score was %.0lf\n", quizzesMean, quizzesMedian);
printf("\nFor exams the average score was %.0lf and the median score was %.0lf\n", examsMean, examsMedian);
}
|