// Programmer: Aaron Shbeeb // File: CIS_Grades2.h // Created: 07-30-03 // Updated: 08-02-03 #ifndef CIS_GRADES2_H #define CIS_GRADES2_H #include "../Keywords.h" #include "../Macros.h" #include "../String/String.h" #define NUM_CGHW 5 #define NO_GRADE 999.0f #define MAX_CGHW 5 #define MAX_HW 1 #define MAX_CL 1 #define MAX_LB 5 #define MAX_TS 100 class CIS_Grades_Rep { public: String Homework; String ClosedLab; String Lab; String Test; //These next members should be static so I don't have to pass //around some global structure static int NUM_HW, NUM_CL, NUM_LB, NUM_TS; static int cghw[NUM_CGHW]; }; int CIS_Grades_Rep::NUM_HW = 21; int CIS_Grades_Rep::NUM_CL = 8; int CIS_Grades_Rep::NUM_LB = 6; int CIS_Grades_Rep::NUM_TS = 2; int CIS_Grades_Rep::cghw[NUM_CGHW] = {1,2,3,4,5}; #define HW_KIND 0 #define CL_KIND 1 #define LB_KIND 2 #define TS_KIND 3 concrete_class CIS_Grades { public: //Basic Operations int& cghw(preserves int pos); //pos = 0, ..., NUM_CGHW int Get_NUM(preserves int kind); void Set_NUMs(preserves int n_hw, preserves int n_cl, preserves int n_lb, preserves int n_ts); void Set_NUMs(); //use existing settings to resize float& Score(preserves int kind, preserves int pos); float Percentage(preserves int kind); bool Is_Carefully_Graded(preserves int hw_num); //Constructor/Destructor CIS_Grades(); ~CIS_Grades(); //Standard Operations void Clear(); void operator&=(alters CIS_Grades& g); protected: void Initialize(); void Finalize(); void Set_Size(preserves int hw, preserves int cl, preserves int lb, preserves int ts); CIS_Grades_Rep* rep; }; //Basic Operations int& CIS_Grades:: cghw(preserves int pos) { return rep->cghw[pos]; } int CIS_Grades:: Get_NUM(preserves int kind) { switch(kind) { case HW_KIND: return rep->NUM_HW; case CL_KIND: return rep->NUM_CL; case LB_KIND: return rep->NUM_LB; case TS_KIND: return rep->NUM_TS; default: return 0; } } void CIS_Grades:: Set_NUMs(preserves int n_hw, preserves int n_cl, preserves int n_lb, preserves int n_ts) { rep->NUM_HW = n_hw; rep->NUM_CL = n_cl; rep->NUM_LB = n_lb; rep->NUM_TS = n_ts; Set_Size(n_hw, n_cl, n_lb, n_ts); } void CIS_Grades:: Set_NUMs() { Set_Size(rep->NUM_HW, rep->NUM_CL, rep->NUM_LB, rep->NUM_TS); } float& CIS_Grades:: Score(preserves int kind, preserves int pos) { switch(kind) { case HW_KIND: return rep->Homework[pos]; case CL_KIND: return rep->ClosedLab[pos]; case LB_KIND: return rep->Lab[pos]; case TS_KIND: return rep->Test[pos]; default: return rep->Homework[0]; } } float CIS_Grades:: Percentage(preserves int kind) { float sum = 0; //total points earned int count = 0; //total points possible switch(kind) { case HW_KIND: { //Not all homeworks have equal weight (1 or 5) for(int i = 0; i < rep->NUM_HW; i++) { if(rep->Homework[i] != NO_GRADE) { sum += rep->Homework[i]; if(self.Is_Carefully_Graded(i+1)) { count += MAX_CGHW; }else{ count += MAX_HW; } } } }break; case CL_KIND: { //All closed labs have equal maximums (out of 1) for(int i = 0; i < rep->NUM_CL; i++) { if(rep->ClosedLab[i] != NO_GRADE) { sum += rep->ClosedLab[i]; count += MAX_CL; } } }break; case LB_KIND: { //All labs have equal maximums (out of 5) for(int i = 0; i < rep->NUM_LB; i++) { if(rep->Lab[i] != NO_GRADE) { sum += rep->Lab[i]; count += MAX_LB; } } }break; case TS_KIND: { //All tests have equal maximums (out of 100) for(int i = 0; i < rep->NUM_TS; i++) { if(rep->Test[i] != NO_GRADE) { sum += rep->Test[i]; count += MAX_TS; } } }break; default: return 0.0; } if(count == 0) return NO_GRADE; sum /= count; //points earned / points possible return sum; } bool CIS_Grades:: Is_Carefully_Graded(preserves int hw_num) { int i; for(i = 0; i < 5; i++) { if(rep->cghw[i] == hw_num) { return true; } } return false; } //Constructor/Destructor CIS_Grades:: CIS_Grades() { Initialize(); } CIS_Grades:: ~CIS_Grades() { Finalize(); } //Standard Operations void CIS_Grades:: Clear() { Finalize(); Initialize(); } void CIS_Grades:: operator&=(alters CIS_Grades& g) { CIS_Grades_Rep* tmp = rep; rep = g.rep; g.rep = tmp; } //Protected Operations void CIS_Grades:: Initialize() { rep = new CIS_Grades_Rep; Set_Size(rep->NUM_HW, rep->NUM_CL, rep->NUM_LB, rep->NUM_TS); int i; for(i = 0; i < rep->NUM_HW; i++) {rep->Homework[i] = NO_GRADE;} for(i = 0; i < rep->NUM_CL; i++) {rep->ClosedLab[i] = NO_GRADE;} for(i = 0; i < rep->NUM_LB; i++) {rep->Lab[i] = NO_GRADE;} for(i = 0; i < rep->NUM_TS; i++) {rep->Test[i] = NO_GRADE;} } void CIS_Grades:: Finalize() { delete rep; } void CIS_Grades:: Set_Size(preserves int hw, preserves int cl, preserves int lb, preserves int ts) { rep->Homework.Set_Size(hw); rep->ClosedLab.Set_Size(cl); rep->Lab.Set_Size(lb); rep->Test.Set_Size(ts); } #endif