Binod's Blog

Tag: basic to user defined

Type conversion between Basic Data and User Defined Data

by on Dec.13, 2010, under C & C++, Tutorial

//type conversion between basic data and user defined data
#include<iostream.h>
#include<conio.h>
class time{
int hr,min,sec;
public:
time(){hr=0;min=0;sec=0;}
time(int value){
hr=value/3600;
int remainder=value%3600;
min=remainder/60;
sec=remainder%60;
}
time(int h, int m, int s){
hr=h;min=m;sec=s;
}
void show(){
cout<<hr<<”:”<<min<<”:”<<sec<<endl;
}
operator int(){
return(hr*3600+min*60+sec);
}
};
main()
{
time t1;
t1=2450; //basic to user defined
t1.show();
time t2(5,25,50);
int seconds=t2; //user defined to basic
cout<<seconds<<endl;
getch();
return 0;
}

Leave a Comment :, more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...