channel link : h ps://www.youtube.
com/c/ComputerScienceAcademy7
#include<iostream.h>
#include<conio.h>
/*
Type conversion programs:
1. Basic type to class type
*/
/* class me
{
int hr, min; // 1 hr 30 min 2 hr 20 min
public:
void display()
{
cout<<hr<<" hour "<<min<<" minutes"<<endl;
me(){}
me(int TotalMins) //121 121 / 60 => 2 121 % 60 => 1
{
hr = TotalMins / 60; //hr = 2
min = TotalMins % 60; // min = 1
};
void main()
{
clrscr();
int TotalMins = 150;
cout<<"Total minutes = "<<TotalMins<<endl;
me t;
t = TotalMins; //t = me(TotalMins);
cout<<"Time dura on in hour and minute format"<<endl;
t.display();
getch();
*/
/*
Type conversion programs:
2. Class type to Basic type
*/
/*
class me
{
int hr, min;
public:
void display()
{
cout<<hr<<" hour "<<min<<" minutes"<<endl;
void getdata(int x, int y)
{
hr = x;
min = y;
}
operator int()
{
int TotalMins = hr * 60 + min;
return TotalMins;
}
};
void main()
{
clrscr();
me t;
t.getdata(3, 59);
cout<<"Time dura on in hour and minute format"<<endl;
t.display();
int TotalMins = t; // t.operator int()
cout<<"Time dura on in minutes = "<<TotalMins<<endl;
getch();
*/
/*
Type conversion programs:
3. One class type to another class type
*/
class minute
{
int min;
public:
void getdata(int x)
{
min = x; //m.min = 150
}
void display()
{
cout<<"Time dura on in minutes = "<<min<<endl;
int getmin()
{
return min;
}
};
class hours
{
float hr; // 1 2 1.5 hr = 1hr 30 min = > 80 min
public:
void getdata(float x)
{
hr = x;
}
void display()
{
cout<<"Time dura on in hours = "<<hr<<endl;
}
hours(){}
hours(minute m)
{
hr = m.getmin() / 60.0;
};
void main()
{
clrscr();
minute m;
m.getdata(150);
m.display();
hours h;
h = m; //h = hours(m)
h.display();
getch();