[Corsopoc] esercizio I

ale.m. mayonaise@inwind.it
Tue, 17 Dec 2002 16:26:10 +0000


--------------Boundary-00=_MZU99NWIHAC5WFKTUC2V
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

=2E..che ve ne pare?
--------------Boundary-00=_MZU99NWIHAC5WFKTUC2V
Content-Type: text/x-c++src;
  charset="us-ascii";
  name="esercizio_1.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="esercizio_1.cpp"

#include<stdio.h>

class time {
	private:
  		int t;
	public:
  		time();
		~time();
  		void show_time();
		void set_time(int x);
		int ret_time();
	};

time::time() {
	t=0;
	}

time::~time() {}

void time::set_time(int x) {
	if (x>=86400) x=x-86400;
	if (x<0) x=x+86400;
	t=x;
	}

int time::ret_time() {
	return t;
	}

void time::show_time() {
	int h=t/3600;
	int m=(t-h*3600)/60;
	int s=t-h*3600-m*60;
	printf("%d:%d,%d",h,m,s);
	}

class orologio {
	private:
		time T;
  	public:
  		orologio();
  		void set(int a, int b, int c);
  		void add(int x);
  		void sub(int x);
  		void show();
        void tick();
		};

orologio::orologio() {
	T.set_time(0);
	}

void orologio::set(int a, int b, int c) {
	int x=a*3600+b*60+c;
	T.set_time(x);
	}

void orologio::add(int x) {
	T.set_time(T.ret_time()+x*60);
	}

void orologio::sub(int x) {
	T.set_time(T.ret_time()-x*60);
	}

void orologio::show() {
	printf("orario: ");
	T.show_time();
	printf("\n");
	}

void orologio::tick() {
	add(1);
	}

int main() {
	orologio O;
	O.set(12,45,123);
	O.show();
	O.sub(10);
	O.show();
	O.tick();
	O.tick();
	O.show();
	return 0;
	}



/*::::::::::::::::::::::::::::::*\
::/                            \::
::  sviluppato da ale.m.        ::
::  17.XII.2002                 ::
::  e-mail: mayonaise@inwind.it ::
::\                            /::
\*::::::::::::::::::::::::::::::*/

--------------Boundary-00=_MZU99NWIHAC5WFKTUC2V--