GRP1.2


 * GRP 1**

NAME: Lester Foo NAME: Rick Wong

code // OOP Task 2 - POINT // Lester Foo Shi En // 3P3 // 10 // Rick Wong Tuck Jun // 3S2 // 21 // 28/07/2010

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

//Define class class PT{ protected: int x, y, z;

public: PT{x=0; y=0; z=0;}; PT(int x1, int y1, int z1){x=x1; y=y1; z=z1;}; ~PT{} void Set_x(int x1){x=x1;}; void Set_y(int y1){y=y1;}; void Set_z(int z1){z=z1;};

//Define NEGATE function void NEGATE { x=(x*-1); y=(y*-1); z=(z*-1); };

//Define NORM function double NORM{ return sqrt(x*x+y*y+z*z); };

//Define PRINT function void PRINT{ cout << "(" << x << ", " << y << ", " << z << ")" << endl; }; };

int main { int x2, y2, z2; PT p;

cout << "Enter value for x coordinate: " << endl; cin >> x2; p.Set_x(x2);

cout << "Enter value for y coordinate: " << endl; cin >> y2; p.Set_y(y2);

cout << "Enter value for z coordinate: " << endl; cin >> z2; p.Set_z(z2);

p.NEGATE;

cout << "The negative value of the coordinates: " << endl; p.PRINT;

cout << "The distance of the point from the orgin is: " <
 * 3) include 
 * 4) include 

//Define class class TIME{

protected: int h, m, s;

public: TIME{h = 00; m = 00; s = 00;}; void Set_h(int h1){h = h1;}; void Set_m(int m1){m = m1;}; void Set_s(int s1){s = s1;}; ~TIME{};

//Define DISPLAY function void DISPLAY{

cout << h << ":" << m << ":" << s << endl; };

//Define RESET function TIME RESET{ h=00; m=00; s=00; }

//Define ADVANCE function TIME ADVANCE(int hh, int mm, int ss){ s=s+ss; if (s>59) {m=m+1; s=(s+ss)-60;}; m=m+mm; if (m>59) {h=h+1; m=(m+mm)-60;}; h=h+hh; if (h>23) {h=h-24;}; } };

int main(void){ int inh, inm, ins;

TIME tt;

time_t now; time(&now);

cout << endl; cout << "The current time on your computer is: " << ctime(&now) << endl; cout << endl;

cout << "Please re-enter your current time in the following format >> hh mm ss" << endl; cin>>inh>>inm>>ins; tt.Set_h(inh); tt.Set_m(inm); tt.Set_s(ins); cout << "Enter the value of advancement for your current time: "<< endl; cin >> inh >> inm >> ins;

tt.ADVANCE(inh, inm, ins); cout << "Your advanced time: ";

tt.DISPLAY; cout << "Time Reset: " << endl;

tt.RESET;

tt.DISPLAY;

system("pause"); return EXIT_SUCCESS; }

code

code /* OOP Time Class Rick Wong 3s2 21 using namespace std; class TIME { protected: int hrs, min, sec; void timevalues { //allows change in values of sec, min and hrs if (hrs>24) { hrs=1; //if hours greater than 24, reset to 1. }
 * 1) include
 * 2) include 
 * 1) include 

if (min>60) { hrs+=1 ; //if minutes greater than 60, hour increase by 1 }

if (sec>60) min+=1; //if seconds greater than 60, min increase by 1 }

public: TIME{ hrs=12, min=0, sec=0; timevalues; }; TIME(int s1, int m1, int h1){ sec=s1; min=m1; hrs=h1; timevalues;}; ~TIME{};

void Display{ if (hrs < 10) cout << "0" <<hrs<< ":" ; //if hours<10, add 0 in front. else cout << hrs << ":";

if (min < 10) cout << "0" <<min << ":"; //if minutes<10, add 0 in front.

else cout << min << ":";

if (sec < 10) cout << "0" <<sec; //if seconds<10, add 0 in front.

else cout << sec;

};

void Reset(int h, int m, int s){ //reset h,m,s to the reset value defined in main hrs = h; min = m; sec = s; timevalues; };

void Advance(int h, int m, int s){ //allows timevalues to advance by (hours, min, seconds) defined in main hrs += h; min += m; sec += s; timevalues; };

}; int main { TIME t1 ; t1.Reset(1,0,0); //defines reset value in (hrs, min, sec) t1.Display; //displays the reset value cout << endl; t1.Advance(10,59,59); //advances from reset value t1.Display; //displays final value after advancing system("pause"); return 0; }

code