Click here to Skip to main content
15,886,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include<iostream.h>
#include<conio.h>
class time24;
class time12
{
	int hour,minute,second;
	char *meridian;
	public:
	void getdata();
	void putdata();
	void summation(time24 x);
};
class time24
{
	int hour,minute,second;
	public:
	void getdata();
	void conto12();
	friend void time12::summation(time24 x);
};

void time12::summation(time24 x)
{
	hour=hour+x.hour;
	minute=minute+x.minute;
	second=second+x.second;
	meridian="PM";
	if(second>=60)
	{
		minute=minute+(second/60);
		second=second%60;

	}
	if(minute>=60)
	{
		hour=hour+(minute/60);
		minute=minute%60;

	}
	x.conto12();

}
void time24::conto12()
{

	if(hour>12)
	{
	       hour=hour-12;
	       meridian="AM";
	}
}

void time12::getdata()
{
	cout<<"\nenter hour:";
	cin>>hour;
	cout<<"enter minute:";
	cin>>minute;
	cout<<"enter second:";
	cin>>second;
}
void time24::getdata()
{
	cout<<"\nenter hour:";
	cin>>hour;
	cout<<"enter minute:";
	cin>>minute;
	cout<<"enter second:";
	cin>>second;
}
void time12::putdata()
{
	cout<<"time:"<<hour<<":"<<minute<<":"<<second<<" "<<meridian;
}
void main()
{
	clrscr();
	time12 a;
	time24 b;
	a.getdata();
	b.getdata();
	a.summation(b);
	a.putdata();
	getch();
}
Posted
Updated 17-Mar-15 7:28am
v2
Comments
[no name] 17-Mar-15 13:01pm    
You should improve your question by clarifying what exactly you mean. The question in the title doesn't make a whole lot of sense on its own and dumping your code without saying what you want to assign where isn't helping.

1 solution

You can do it via so called "forward declaration". It is a simple statement as you done it. But in the implemention file needs to be the header for that class. As parameter you better use pointers.

But I recommand you to do that NOT IN REAL CODE. It leeds to dependencies and its problems. It is better to use native data types for interfaces.

Example for your summation:

C++
void time12::summation(int h24, int m24, int s24);


It improves maintainability and stability. And if you do it than see it as as "One way ticket". Never ever. :-O
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900