GRP2.2


 * GRP 2**

NAME: Bay Wei Heng 3I302 NAME: Gan Wei Liang 3I308

code /* Name: Bay Wei Heng Class: 3I3 Mission 2 Date of submission: 1/8/10

FILE *out = fopen("blah2.txt","w"); class time{ public: int h, m, s; //Attributes should be in protected
 * 1) include
 * 2) include

time{h=0; m=0; s=0;}; time(int x, int y, int z){h = x; m = y; s = z;}; ~time{};

void Display{fprintf(out,"Current time: %d, %d, %d\n", h, m, s);};

void Set_h(int x){h = x; }; void Set_m(int y){m = y; }; void Set_s(int z){s = z; };

void Reset(int h1, int m1, int s1){ s = s1%60; m = (m1+s1/60)%60; h = (((m1+s1/60)%60)+h1)%24; } void Advance(int h2, int m2, int s2){ s = (s2+s)%60; m = (m2+m+(s2+s)/60)%60; h = (h2+h+(m2+m+(s2+s)/60)/60)%24; } }; int main{ time x(1,2,3); x.Display; x.Reset(23, 60, 59); x.Display; x.Advance(1, 2, 30); x.Display; return 0; }

/* Name: Bay Wei Heng Class: 3I3 Point Class Date of submission: 1/8/10

FILE *out = fopen("blah.txt","w"); class point{ public: int xcoord, ycoord, zcoord; //Attributes should be in protected
 * 1) include
 * 2) include

point{xcoord=0; ycoord=0; zcoord=0;}; point(int x, int y, int z){xcoord = x; ycoord = y; zcoord = z;}; ~point{};

void PRINT{fprintf(out,"Point given: %d, %d, %d", xcoord, ycoord, zcoord);};

void Set_x(int x){xcoord = x; }; void Set_y(int y){ycoord = y; }; void Set_z(int z){zcoord = z; };

point NEGATE{ point y; y.xcoord = -xcoord; y.ycoord = -ycoord; y.zcoord = -zcoord; return y; } float NORM{ float y; y = sqrt((xcoord*xcoord)+(ycoord*ycoord)+(zcoord*zcoord)); return y; } }; int main{ point x(1,2,3); fprintf(out, "Negative: %d, %d, %d\n", x.NEGATE.xcoord, x.NEGATE.ycoord, x.NEGATE.zcoord); fprintf(out, "Distance: %f\n", x.NORM); x.PRINT; return 0; }

/* Name: Gan Wei Liang Index No.: 3I308 Task: POINT class Date of Submission: 1/8/10 using namespace std; class POINT{
 * 1) include
 * 2) include
 * 1) include

protected:

int x,y,z;

public:

POINT{x=0;y=0;z=0;} POINT(int a, int b, int c){x=a;y=b;z=c;} ~POINT{};

void Set_x(int a){x=a;} void Set_y(int b){y=b;} void Set_z(int c){z=c;}

void NEGATE{x=-x;y=-y;z=-z;} void NORM{printf("Distance from origin: %.6lf\n",sqrt(x*x+y*y+z*z));} void PRINT{printf("Coordinates: (%d,%d,%d)\n",x,y,z);} };

int main{ POINT pt1; pt1.PRINT; POINT pt2(1,2,3); pt2.PRINT; pt2.NEGATE; pt2.PRINT; pt2.NORM; return 0; }

/* Name: Gan Wei Liang Index No.: 3I308 Task: TIME class Date of Submission: 1/8/10 using namespace std; class TIME{
 * 1) include
 * 2) include
 * 1) include

protected:

int h,m,s;

public:

TIME{h = time(0) / 3600 % 24 + 8; m = time(0) / 60 % 60; s = time(0) % 60;} TIME(int x, int y, int z){h=x;m=y;s=z;} ~TIME{};

void DISPLAY{printf("Time: %d%d:%d%d:%d%d\n",h/10,h%10,m/10,m%10,s/10,s%10);}

void ADVANCE(int x, int y, int z){ h+=x; m+=y; s+=z; m+=s/60; s%=60; h+=m/60; m%=60; h%=24; }   void RESET(int x,int y, int z){h=x;m=y;s=z;} };

int main{ TIME t1; t1.DISPLAY; TIME t2(11,11,11); t2.DISPLAY; t2.ADVANCE(100,100,100); t2.DISPLAY; t2.RESET(11,11,11); t2.DISPLAY; return 0; }

code