#include #include #include #include #include const Lengths[6] = {21, 30, 42, 55, 65, 81}; // Cursor lengths /* GLOBAL VARIABLES BEGIN */ char Student[35][20]; // 35 Students max, 20 characters each int Fields[4][35][30]; // [Tests, Quizzes, HW, misc] for each student // Maximum of 30 of each int GradeNums[4][35]; // Number of grades actually given for each field // for each student (averages with missing grades) int Percs[4][35][30]; // Percentages for each individual grade int PercTotl[4]; // Percentages for each topic int ScreenX, ScreenY; // Screen X and Y cursor variables int TopName; // Name at top of screen char FileName[12]; // Used for file name FILE *datafile; // File variable /* GLOBAL VARIABLES END */ void defstuff() { // Set default program stuffs ScreenX = 1; ScreenY = 1; // Set default screen variables TopName = 1; int a, b; for(a = 0; a < 35; a++) for(b = 0; b < 20; b++) Student[a][b] = ' '; // Fill name arrays with blankness for(a = 0; a < 4; a++) PercTotl[a] = 25; }; void data(int X, int Y) { // Function to show data int a, b, c = 0, d, e = 0, f, total = 0; gotoxy(Lengths[X-1], Y + 1); a = Lengths[X] - Lengths[X-1]; // Make a blank line for(b = 1; b <= a; b++) putch(' '); a = (Lengths[X] - Lengths[X-1]) / 2; d = TopName + Y - 2; // Certain Student selected gotoxy(Lengths[X-1]+a, Y + 1); // Move to center of line if (X != 5) { // If getting a normal topic's average if (GradeNums[X - 1][d] != 0) { // If there is more than 0 grades for(b = 0; b < GradeNums[X - 1][d]; b++) { c = c + ((Fields[X-1][d][b] * 100) / Percs[X-1][d][b]); e = e + 1; } cout << c / e; // Divide by total, print it if it }; // can exist } else { if (!((GradeNums[0][d]==0) && (GradeNums[1][d]==0) && (GradeNums[2][d]==0) && (GradeNums[3][d]==0))) { for(a = 0; a < 4; a++) { c = 0; f = 0; if (GradeNums[a][d] != 0) { // If grade for topic exists for(b = 0; b < GradeNums[a][d]; b++) { c = c + ((Fields[a][d][b] * 100) / Percs[a][d][b]); f = f + 1; // Keep track of grade totals }; c = c / f; // Average topic grade }; total = total + ((c * PercTotl[a]) / 100); }; // Calculate grade based on assigned %s cout << total; // Display total average grade if (total >= 94) cout << " A"; else { // Display if (total >= 87) cout << " B"; else { // Warren if (total >= 79) cout << " C"; else { // County if (total >= 70) cout << " D"; // Grade else cout << " F"; }; }; }; }; }; }; void dispnames() { // Displays student names int a, b = 1, c; textbackground(11); textcolor(15); for(a = TopName - 1; (b < 24); a++) { gotoxy(1, b+1); // Go to left hand side for(c = 0; c < 20; c++) putch(Student[a][c]); // Print the 20 characters for name b = b + 1; // Move to next line }; textbackground(0); textcolor(15); }; void dispdata() { int a, b; // Displays data on entire graph for (a = 0; a < 23; a++) for (b = 0; b < 5; b++) data(b+1, a+1); }; void dispscreen() { clrscr(); gotoxy(1, 1); textbackground(0); // Displays top bar cprintf(" "); textbackground(11); textcolor(0); cprintf(" Tests Quizzes Homework Misc. Totals "); textbackground(0); textcolor(15); gotoxy(1, 25); cout << "N - Name O - Sort L - Load S - Save Q - Quit: "; }; void dispgrades(int topic, int e) { // Display all grades for a student int b; switch(topic) { case 0: cout << "Tests\n\n"; break; case 1: cout << "Quizzes\n\n"; break; case 2: cout << "Homework\n\n"; break; case 3: cout << "Misc\n\n"; break; }; e = TopName + ScreenY - 2; for (b = 0; b < 15; b++) { if (b < GradeNums[topic][e]) { // Print only if (b < 9) cout << " "; cout << (b+1); // existing grades cout << ". " << Fields[topic][e][b] << " \\ " << Percs[topic][e][b] << "\n"; }; if (b + 15 < GradeNums[topic][e]) { gotoxy(41, b+3); // Print only cout << (b + 16) << ". " // existing grades << Fields[topic][e][b+15] << " \\ " << Percs[topic][e][b] << "\n"; }; }; }; void dispall() { dispscreen(); dispnames(); dispdata(); textcolor(0); textbackground(15); data(ScreenX, ScreenY); textbackground(0); textcolor(15); }; int getpercinfo(int a) { int c = -1; while ((c < 0) || (c > 100)) { gotoxy(22, a + 1); cin >> c; }; return c; }; void percents() { int a, b = 0; // Loop until 100% while ((a != 100) || (b = 0)) { int c = 0; a = 0; b = 1; // Used to get grades at least once clrscr(); cout << "Test percentage : %\n"; cout << "Quiz percentage : %\n"; cout << "Homework percentage: %\n"; cout << "Misc. percentage : %\n"; cout << "Total percentage : %\n"; for (c = 0; c < 4; c++) { PercTotl[c] = getpercinfo(c); a = PercTotl[c] + a; gotoxy(22, 5); cout << a; }; }; dispall(); }; void swap(int a, int b) { int c, d, temp; char tempc; for(c = 0; c < 20; c++) { tempc = Student[a][c]; // Swap Names Student[a][c] = Student[b][c]; Student[b][c] = tempc; }; for(c = 0; c < 4; c++) for(d = 0; d < 30; d++) { temp = Fields[c][a][d]; // Swap grades Fields[c][a][d] = Fields[c][b][d]; Fields[c][b][d] = temp; }; for(c = 0; c < 4; c++) { temp = GradeNums[c][a]; // Swap Total Grade Numbers GradeNums[c][a] = GradeNums[c][b]; GradeNums[c][b] = temp; }; for(c = 0; c < 4; c++) for(d = 0; d < 35; d++) { temp = Percs[c][a][d]; Percs[c][a][d] = Percs[c][b][d]; Percs[c][b][d] = temp; }; }; void sort() { int a, b, c; char d = ' '; gotoxy(1, 25); cout << "Keep spaces? [Y/N]: "; gotoxy(21, 25); // Ask for space keeping while ((d != 78) && (d != 110) && (d != 89) && (d != 121)) d = getch(); for(a = 0; a < 35; a++) { // Simple selection sort c = a; if ((d == 78) || (d == 110)) { // If you don't want spacing... for(b = a + 1; b < 35; b++) { if ((stricmp(Student[c], Student[b]) > 0) && (Student[c][0] != ' ') && (Student[b][0] != ' ')) // If both don't have spaces and one c = b; // is higher, swap. else { if ((Student[b][0] != ' ') && (Student[c][0] == ' ')) c = b; // If your index has a space and }; // your checking one doesn't, swap. }; swap(a, c); } else { // For spacing.... for(b = a+1; b < 35; b++) // Do simple selection sort if ((stricmp(Student[c], Student[b]) > 0) && (Student[b][0] != ' ')) c = b; swap(a, c); } }; dispall(); }; void cursor(int funt) { int Ref; textbackground(0); data(ScreenX, ScreenY); switch (funt) { case 1: if (ScreenY != 1) // Up ScreenY = ScreenY - 1; // Move cursor up one else if (TopName != 1) { TopName = TopName - 1; // If you're not at Ref = 1; // the first name, move up the list one }; // and refresh the names break; case 2: if (ScreenX != 1) ScreenX = ScreenX - 1; // Left break; case 3: if (ScreenX != 5) ScreenX = ScreenX + 1; // Right break; case 4: if (ScreenY != 23) { // Up ScreenY = ScreenY + 1; // Move cursor down one } else if (TopName + 22 != 35) { TopName = TopName + 1; // If you're not at Ref = 1; // the last name, move down the list one }; // and refresh the names break; }; if (Ref == 1) { dispnames(); // Refresh names if needed dispdata(); // Refresh data if needed }; textcolor(2); textbackground(15); data(ScreenX, ScreenY); // Display cursor data textcolor(15); textbackground(0); }; void grademenu(int topic) { // Displays menu to add/delete/edit grades int end = 0; while (end == 0) { clrscr(); int e, f; e = TopName + ScreenY - 2; dispgrades(topic, e); // Display all grades for a student if (GradeNums[topic][e] == 0) { gotoxy(1, 19); // Check to see if grades exist cprintf("No grades found"); }; gotoxy(1, 20); cout << "1. Add Grade\n2. Delete Grade\n3. Edit Grade\n4. Exit\n" << "Enter selection: "; char c = 0; while ((c < 49) || (c > 52)) c = getch(); switch(c) { case 49: if (GradeNums[topic][e] == 30) { // Add Grades gotoxy(18, 24); cout << "No more room for grades."; // If too many grades, delay(1000); // let user know gotoxy(18, 24); cout << " "; } else { gotoxy(1, 19); cout << " "; GradeNums[topic][e] = GradeNums[topic][e] + 1;// Add if (GradeNums[topic][e] < 16) // Grade gotoxy(1, GradeNums[topic][e] + 2); // Go to else // correct gotoxy(41, GradeNums[topic][e] % 16 + 3); // spot if (GradeNums[topic][e] < 10) cout << " "; cout << GradeNums[topic][e] << ". "; cin >> Fields[topic][e][GradeNums[topic][e] - 1]; if (GradeNums[topic][e] < 15) gotoxy(10, GradeNums[topic][e] + 2); else gotoxy(48, GradeNums[topic][e] + 2); cout << " \\ "; cin >> Percs[topic][e][GradeNums[topic][e] - 1]; }; // Gets Grade gotoxy(51, 24); break; case 50: if (GradeNums[topic][e] == 0) { gotoxy(18, 24); cout << "No grades to delete."; // If no grades, delay(1000); // let user know gotoxy(18, 24); cout << " "; gotoxy(18, 24); } else { gotoxy(1, 24); cout << "Choose grade to delete (0 to quit): "; f = -1; while ((f < 0) || (f > GradeNums[topic][e])) { gotoxy (37, 24); cin >> f; }; if (f != 0) { for(; f<30; f++) { // Delete grade.. space all up. Fields[topic][e][f-1] = Fields[topic][e][f]; Percs[topic][e][f-1] = Percs[topic][e][f]; }; GradeNums[topic][e] = GradeNums[topic][e] - 1; }; }; break; case 51: if (GradeNums[topic][e] == 0) { gotoxy(18, 24); cout << "No grades to edit."; // If no grades, delay(1000); // let user know gotoxy(18, 24); cout << " "; gotoxy(18, 24); } else { gotoxy(1, 24); cout << "Choose grade to edit (0 to quit): "; f = -1; while ((f < 0) || (f > GradeNums[topic][e])) { gotoxy (37, 24); cin >> f; }; if (f > 15) gotoxy(45, (f % 16) + 2);// else gotoxy(5, 2 + f); // Choose cout << " "; // correct if (f > 15) gotoxy(45, (f % 16) + 2);// spot to else gotoxy(5, 2 + f); // edit. cin >> Fields[topic][e][f - 1]; // }; break; case 52: end = 1; break; }; c = 0; // Reset c; }; // End while }; void enter() { int a, b = 1; char c; while (b == 1) { textbackground(0); textcolor(15); clrscr(); // Blank screen for (a = 0; a < 20; a++) putch(Student[TopName+ScreenY-1][a]); cout << "\nGrades:\n\n"; cout << "1. Tests\n2. Quizzes\n3. Homework\n4. Misc\n5. Quit" << "\n\nEnter a category: "; // Give edit prompt while ((a < 0) || (a > 5)) { c = getch(); switch(c) { case 49: a = 0; break; case 50: a = 1; break; // Find what table to edit case 51: a = 2; break; case 52: a = 3; break; case 53: a = 4; break; }; }; if (a != 4) { grademenu(a); // Pull up correct grade menu } else b = 0; // End menu while }; dispall(); }; void newname() { // Used to put new names on chart int a; unsigned char c; gotoxy(1, ScreenY+1); textbackground(11); textcolor(15); cprintf(" "); // Clear current name gotoxy(1, ScreenY+1); for(a = 0; a < 20; a++) { gotoxy(a+1, ScreenY+1); // Get name routine c = getch(); if (c == 0) c = getch(); switch(c) { // Backspace case 8: Student[TopName+ScreenY-2][a-1] = ' '; a = a - 2; gotoxy(a+2, ScreenY+1); cprintf(" "); break; case 13: a = 20; break; // Enter - ends routine default: putch(c); Student[TopName + ScreenY - 2][a] = c; }; // Put character into data and screen if (a < 0) a = -1; }; }; void save() { gotoxy(1, 25); cout << "Enter file name to save: "; gotoxy(26, 25); gets(FileName); if ((datafile = fopen(FileName, "wt")) == NULL) { gotoxy(1, 25); cout << "Cannot save as this file. "; delay(1000); } else { int a, b, c; for(a = 0; a < 35; a++) for(b = 0; b < 20; b++) // Save student names fputc(Student[a][b], datafile); for(a = 0; a < 4; a++) for(b = 0; b < 35; b++) // Save student grades for(c = 0; c < 30; c++) { fputc(Fields[a][b][c] / 256, datafile); fputc(Fields[a][b][c] % 256, datafile); }; for(a = 0; a < 4; a++) for(b = 0; b < 35; b++) { fputc(GradeNums[a][b] / 256, datafile); // Save number of grades fputc(GradeNums[a][b] % 256, datafile); // for each student }; for(a = 0; a < 4; a++) for(b = 0; b < 35; b++) for(c = 0; c < 30; c++) { fputc(Percs[a][b][c] / 256, datafile); // Save percentages fputc(Percs[a][b][c] % 256, datafile); }; }; dispall(); }; void load() { gotoxy(1, 25); cout << "Enter file name to load: "; gotoxy(26, 25); gets(FileName); if ((datafile = fopen(FileName, "rt")) == NULL) { gotoxy(1, 25); cout << "Cannot load this file. "; delay(1000); } else { int a, b, d, e; for(a = 0; a < 35; a++) for(b = 0; b < 20; b++) { Student[a][b] = fgetc(datafile); //Get all student names from file }; for(a = 0; a < 4; a++) //Get current saved grades. for(b = 0; b < 35; b++) for(d = 0; d < 30; d++) { e = fgetc(datafile) * 256; Fields[a][b][d] = e + fgetc(datafile); }; for(a = 0; a < 4; a++) for(b = 0; b < 35; b++) { // Get number of grades d = fgetc(datafile) * 256; GradeNums[a][b] = d + fgetc(datafile); }; for(a = 0; a < 4; a++) for(b = 0; b < 35; b++) for(d = 0; d < 30; d++) { e = fgetc(datafile) * 256; // Get Percentage Info Percs[a][b][d] = b + fgetc(datafile); }; }; dispall(); }; int quit() { char c = 0; gotoxy(1, 25); // Prompt for save before quit cout << "Save? [Y/N]: "; gotoxy(14, 25); while ((c != 78) && (c != 110) && (c != 89) && (c != 121)) c = getch(); if ((c == 89) || (c == 121)) save(); clrscr(); // Used for returning to DOS... makes it look nice. :) return 1; }; void main(void) { int end = 0; char c; textmode(C80); textcolor(15); textbackground(0); // Used for initial screen (cout) clrscr(); defstuff(); // Set some defaults dispscreen(); dispnames(); cursor(0); while (end == 0) { // Continue program until you quit. gotoxy(51, 25); c = getch(); if (c == 0) c = getch(); switch (c) { case 13: enter(); break; // Enter key case 72: cursor(1); break; // Up key case 75: cursor(2); break; // Left key case 77: cursor(3); break; // Right key case 80: cursor(4); break; // Down key case 78: // Get names case 110: newname(); break; // 'N' or 'n' case 79: // Sort names case 111: sort(); break; // 'O' or 'o' case 65: // Get percentages case 97: percents(); break; // 'A' or 'a' case 81: // Quit case 113: end = quit(); break; // 'Q' or 'q' case 83: // Save case 115: save(); break; // 'S' or 's' case 76: // Load case 108: load(); break; // 'L' or 'l' }; }; }