Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //code by Rehan Naeem
- #include <iostream>
- #include <cstdio>
- using namespace std;
- enum option {cis32 = 1, otherClasses, quit};
- option display_menu();
- void switcher(option, double [][4], int [][3], double [][5]);
- int record_cis32(double [][4]);
- void OtherClasses(int [][3], double [][5]);
- void selectionSort(double [][4], int);
- void bubbleSort();
- bool searchDup1(int , double [][4], int);
- bool searchDup2(int , int [][3] , int , int );
- int main()
- {
- option choose ;
- double arrayOpt1[10][4];
- int arrayOpt2[10][3];
- double anotherOpt2[10][5];
- do
- {
- choose = display_menu() ;
- switcher (choose, arrayOpt1, arrayOpt2, anotherOpt2) ;
- } while (choose != 4) ; //****************************************change to 3
- return 0 ;
- }
- option display_menu()
- {
- option choose ;
- printf ("Choose an option:\n\n") ;
- printf ("1) CIS 32\n");
- printf ("2) Other Classes\n");
- printf ("3) Quit 32\n\n");
- scanf ("%d", &choose);
- return choose ;
- }
- void switcher (option choose, double arrayOpt1[][4], int arrayOpt2[][3], double anotherOpt2[10][5])
- {
- bool valid;
- int effective1 ;
- do
- {
- valid = true;
- switch (choose)
- {
- case cis32:
- effective1 = record_cis32(arrayOpt1);
- break;
- case otherClasses:
- OtherClasses(arrayOpt2, anotherOpt2);
- break;
- case quit:
- selectionSort(arrayOpt1, effective1-1);
- for (int i=0; i<effective1; i++)
- {
- printf ("\n\n%.0lf", arrayOpt1[i][0]) ;
- }
- break;
- default:
- printf("Wrong input.\n\n");
- choose = display_menu();
- valid = false;
- }
- } while (valid == false);
- }
- int record_cis32(double arrayOpt1[10][4])
- {
- static int effective1 = 0;
- int studID , midterm, final, sum=0;
- double avg;
- bool valid1 , valid2 ;
- if (effective1 < 10)
- {
- effective1 += 1;
- do
- {
- valid2 = true;
- printf("\nInput student ID: ");
- do
- {
- valid1 = true ;
- scanf ("%d", &studID ) ;
- if (studID > 100 || studID < 1)
- {
- printf ("Input a valid student ID:");
- valid1 = false ;
- }
- } while (valid1 != true ) ;
- arrayOpt1[effective1][0] = studID ;
- if (searchDup1(studID , arrayOpt1, effective1))
- {
- printf ("Duplicate student ID. Re-enter ID.\n");
- valid2 = false;
- }
- }while (valid2 == false) ;
- printf("Input midterm exam score: ");
- do
- {
- valid1 = true ;
- scanf ("%d", &midterm);
- if (midterm > 100 || midterm < 1)
- {
- printf ("Input a valid midterm exam score:");
- valid1 = false ;
- }
- }while (valid1 != true ) ;
- arrayOpt1[effective1][1] = midterm;
- printf("Input final exam score: ");
- do
- {
- valid1 = true ;
- scanf ("%d", &final);
- if (final > 100 || final < 1)
- {
- printf ("Input a valid final exam score:");
- valid1 = false ;
- }
- }while (valid1 != true ) ;
- arrayOpt1[effective1-1][2] = final ;
- sum += midterm + final ;
- avg = double(sum) / 2.00 ;
- arrayOpt1[effective1-1][3] = avg ;
- printf("avg is: %.2lf", arrayOpt1[effective1-1][3]) ;
- printf("\n");
- return effective1;
- }
- else
- printf("\nOut of bounds. Choose another option.\n\n");
- }
- bool searchDup1(int studID, double arrayOpt1[][4] , int effective1 )
- {
- bool found = false;
- for (int i = 0; i<effective1; i++)
- {
- if (arrayOpt1[i][0] == studID)
- {
- found = true;
- break;
- }
- }
- return (found) ;
- }
- void OtherClasses(int arrayOpt2[][3], double anotherOpt2[][5])
- {
- static int effective2 = 0 , effective3 = 0;
- int studID , classCode, score, numbScores, i = 0, sum=0, j ;
- double avg ;
- bool valid1 , valid2 ;
- if (effective2 < 10)
- {
- effective2 += 1 ;
- do
- {
- valid2 = true;
- printf("\nInput student ID: ");
- do
- {
- valid1 = true ;
- scanf ("%d", &studID ) ;
- if (studID > 100 || studID < 1)
- {
- printf ("Input a valid student ID: ");
- valid1 = false;
- }
- } while (valid1 != true );
- arrayOpt2[effective2][0] = studID ;
- printf("Input class code: ");
- do
- {
- valid1 = true;
- scanf ("%d", &classCode );
- if (classCode < 1)
- {
- printf ("Input a valid class code: ");
- valid1 = false;
- }
- } while (valid1 != true );
- arrayOpt2[effective2][1] = classCode ;
- if (searchDup2(studID , arrayOpt2, effective2, classCode))
- {
- printf ("Duplicate pair of student ID and class code entered. Re-enter the values.\n");
- valid2 = false;
- }
- }while (valid2 == false);
- printf("Input how many scores you want to record: ");
- do
- {
- valid1 = true ;
- scanf ("%d", &numbScores ) ;
- if (numbScores > 4 || numbScores < 2)
- {
- printf ("Input a number of scores (2 to 4): ");
- valid1 = false;
- }
- } while (valid1 != true );
- effective3 = numbScores ;
- arrayOpt2[effective2][2] = numbScores ;
- for (j = 0; j<effective3 ; j++ )
- {
- printf ("Enter score %d: ", j+1) ;
- do
- {
- valid1 = true ;
- scanf ("%d", & score) ;
- if (score < 0)
- {
- printf ("Input a valid score (greater than 0): ");
- valid1 = false;
- }
- } while (valid1 != true );
- anotherOpt2[effective2-1][j] = score ;
- sum += score ;
- }
- avg = double(sum) / effective3 ;
- anotherOpt2[effective2-1][5] = avg ;
- printf("avg is: %.2lf", anotherOpt2[effective2-1][5]) ;
- printf ("\n");
- }
- else
- printf("\nOut of bounds. Choose another option.\n\n");
- }
- bool searchDup2(int studID, int arrayOpt2[][3] , int effective2 , int classCode)
- {
- bool found = false;
- for (int i = 0; i<effective2 ; i++)
- {
- if (arrayOpt2[i][0] == studID && arrayOpt2[i][1] == classCode)
- {
- found = true;
- break;
- }
- }
- return (found);
- }
- void selectionSort(double arrayOpt1[][4], int effective1)
- {
- int temp, indexLargest, index;
- for (; effective1 > 0; effective1--)
- {
- indexLargest = 0;
- for (index=1; index <= effective1; index++)
- {
- if (arrayOpt1[index][0] > arrayOpt1[indexLargest][0])
- indexLargest = index;
- }
- if (effective1 != indexLargest)
- {
- temp = arrayOpt1[effective1][0] ;
- arrayOpt1[effective1][0] = arrayOpt1[indexLargest][0] ;
- arrayOpt1[indexLargest][0] = temp ;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement