GRP6.2


 * GRP 6**

NAME: Edgar NAME: Jim Yang

code Task 1 Point Class (unfinished)


 * 1) include 
 * 2) include 

using namespace std;

class PT{ protected: int x,y,z; public: PT{x,y,z}; ~PT{}; PT NEGATE(-x,-y,-z){ } PT NORM(0,0,0){ int length,power; power = pow(x,2) + pow(y,2) + pow(z,2); length = sqrt(power);

/*  Time Class Done by Edgar Leung */

using namespace std;
 * 1) include
 * 2) include

class TIME{ protected: int h,m,s; public: TIME {h = 0; m = 0; s = 0;}; //Constructor void setHour (int vh){h = vh;}; void setMinute (int vm){m = vm;}; void setSecond (int vs){s = vs;}; ~TIME{}; //Destructor

void Display { //Resets the time if value is over expected display if (s > 59){ s = s - (s/60)*60; m = m + 1; } if (m > 59){ h = h + 1; m = m - (m/60)*60; } if (h > 23){ h = h - 24; } //Makes an extra 0 if time is one digit if (h < 10){ cout << "0" << h; } else { cout << h; } cout << ":"; //Divider for time if (m < 10){ cout << "0" << m; } else { cout << m; } cout << ":"; if (s < 10){ cout << "0" << s; } else { cout << s; } } TIME Reset { //Reset function, sets all values to 0 h = m = s = 0; } TIME Advance (int inputHour, int inputMinute, int inputSecond){ //Advances time s = s + inputSecond; m = m + inputMinute; h = h + inputHour; } };

int main { int hour, minute, second, inputOption; TIME time; cout << "Enter time in order: Hours, Minutes, Seconds" << endl; cin >> hour >> minute >> second; //Input for time time.setHour (hour); //Call function time.setMinute (minute); time.setSecond (second); cout << "Time now is: "; time.Display; cout << endl; cout << "Type 1 to advance time, 2 to Reset Time, or any other key to stop" << endl; //Choice to reset time or advance time cin >> inputOption; if (inputOption == 1){ //Condition to reset times or advance cout << "Enter time to advance in order of hour, minute, second" << endl; cin >> hour >> minute >> second; time.Advance(hour, minute, second); time.Display; cout << endl; } else if (inputOption == 2){ time.Reset; time.Display; cout << endl; } else { return 0; } time.Reset; return 0; }

Task 2 Time Class

/* TIME Class

Teo Jim Yang 3O3(26)


 * 1) include
 * 2) include 

using namespace std;

class TIME { protected: int h, m, s;     public: TIME{h = 0; m = 0; s = 0;}; // Default Constructor TIME(int H, int M, int S){ h = H; m = M; s = S;}; // Constructor ~TIME{}; // Destructor

// Setter functions void setH(int HR){ h = HR; }; void setM(int MIN){ m = MIN; }; void setS(int SEC){ s = SEC; };

void DISPLAY{ // To keep hours below 24, minutes and seconds below 60 while ( s >= 60 ) { s-=60; m++; }                 while ( m >=60 ){ m-=60; h++; }                 while ( h >= 24 ) {h-=24;}

if ( h < 10 ) cout << "0" << h << "hours "; else cout << h << "hours "; if ( m < 10 ) cout << "0" << m << "minutes "; else cout << m << "minutes "; if ( s < 10 ) cout << "0" << s << "seconds\n"; else cout << s << "seconds\n"; } // Display function

void ADVANCE(int a, int b, int c){ h += a;                 m += b;                  s += c;             } // Advance function

void RESET{ h = 0; m = 0; s = 0; } // Reset function };

int main { int hr, min, sec, reset=0; TIME time;

// Displaying given time cout << "Enter the time\n " << endl; cout << "Hours: "; cin >> hr ; cout << "Minutes: "; cin >> min ; cout << "Seconds: "; cin >> sec; cout << endl; time.setH(hr); time.setM(min); time.setS(sec); cout << "The time now is: "; time.DISPLAY; cout << endl;

// Advancing given time cout << "Enter time to advance: " << endl; cout << "Hours: "; cin >> hr ; cout << "Minutes: "; cin >> min ; cout << "Seconds: "; cin >> sec; cout << endl; time.ADVANCE(hr,min,sec); cout << "The time will be: "; time.DISPLAY; cout << endl;

// Resetting time to 0 while ( reset !=1 ){ cout << "Press 1 to reset time: "; cin >> reset; }   time.RESET; time.DISPLAY;

system("pause"); return 0; }

code