GRP8.2

code format="cpp" Feedbacks: 1) Attributes should not be in PUBLIC 2) Negate its own set of coordinates will be sufficient. No need to take in values code =Group 8 =

Cheng Wei Hong & Joel Tan
code format="cpp" /* * 3d.cpp * * * Created by Commodore on 7/26/10. * Copyright 2010 EC³ ExCo. All rights reserved. * */

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

class PT {

public:

int x, y, z;

PT {       x = 0; y = 0; z = 0; }

PT(int a, int b, int c)   { x = a;       y = b;        z = c;    }

PT NEGATE(PT a)   { PT b;

b.x = -a.x;       b.y = -a.y;        b.z = -a.z;

return b;   };

void NORM       // distance from origin {       double length;

length = sqrt(x * x +  y * y  +  z * z);

printf("%f\n", length); };

void PRINT {       printf("(%d, %d, %d)\n", x, y, z); };

};

int main {   int x;    int y;    int z;

printf("\nCoordinates of point?\n\n"); scanf("%d %d %d", &x, &y, &z); printf("\n");

PT a(x,y,z); PT b;

b = b.NEGATE(a);

a.PRINT;

printf("Negative = "); b.PRINT;

printf("Distance from origin = "); a.NORM;

printf("\n");

return 0; }

code

code format="cpp" // Submitted on behalf of Wei Hong using namespace std;
 * 1) include

class T   { protected: int hour, minute, second, h, m, s ; public: T(int h, int m, int s){hour=h; minute=m; second=s;}; // Default Constructor ~T{}; // Destructor

// Functions //Display void Display   { cout << hour <<":"<< minute <<":"<< second; cout << endl; };   //Reset void Reset(int h, int m, int s)   { hour = h;       minute = m;        second = s;

};   //Advance void Advance   { hour = hour+1; minute = minute+1; second = second+1; };

};

int main { T t1(1,2,3); t1.Display; t1.Advance; t1.Display; t1.Reset(1,2,3); t1.Display; cout<
 * 2) include 
 * 3) include 

class TIME { protected: int h, m, s;

public:

TIME {		h = 0; m = 0; s = 0; }

~TIME {		// a dead dialga };

TIME(int x, int y, int z)	{ h = x;		m = y;		s = z;	}

TIME advance(int x, int y, int z)	{ s = s + z;

if (s >= 60) {			m = m + (s / 60); s = s % 60; }

m = m + y;		if (m >= 60) {			h = h + (m / 60); m = m % 60; }

h = h + x;		if (h >= 24) {			h = h % 24; }

// output new time

if (h < 10) printf("0");

printf("%d:", h);

if (m < 10) printf("0");

printf("%d:", m);

if (s < 10) printf("0");

printf("%d\n", s);

};

void set(int x, int y, int z)	{ h = x;		m = y;		s = z;	};

void reset {		h = 0; m = 0; s = 0; };

void display {		if (h < 10) printf("0");

printf("%d:", h);

if (m < 10) printf("0");

printf("%d:", m);

if (s < 10) printf("0");

printf("%d\n", s);

};

};

int main {	time_t rawtime; time(&rawtime); // printf("\nCurrent local time: %s\n", ctime(&rawtime));

/* Algorithm to extract current hour, minute, and second values from timestamp */

int t_hour = (time(NULL) / 3600) % 24 + 8; // + 8 because SGT is GMT+8 int t_min = (time(NULL) % 3600) / 60; int t_sec = time(NULL) % 60;

/* end */

/* Prints current time */

printf("\nCurrent time (GMT+8): ");

TIME dialga(t_hour, t_min, t_sec); dialga.display;

printf("\n");

/* end */

/* Time travel */

int hour, minute, second;

printf("Advance time by (h m s)...\n"); scanf("%d %d %d", &hour, &minute, &second);

printf("\n");

dialga.advance(hour, minute, second);

/* end */

/* Reset */

dialga.reset;

printf("\nreset...\n");

dialga.display;

/* end */

printf("\n");

return 0; } code dialgas