Показать сообщение отдельно

  #153  
Старый 23.12.2007, 20:25
Nea7
Участник форума
Регистрация: 08.09.2007
Сообщений: 211
Провел на форуме:
5076186

Репутация: 778
По умолчанию

Определить класс "дата" c компонентными данными: число, месяц, год. Перегрузить операциия: >>,<<
(вывод в формате "чч/мм/гггг"),
>= (проверка на более позднюю дату или на их равенство), += (прибавить n дней).

Код:
#include <iostream>
#include <iomanip>
using namespace std;

class v_date 
{
	int number; 
	int month;  
	int year;  
public:
	v_date (int , int, int );
	int put_1();
	int put_2();
	int put_3();
	void get_1(int );
	void get_2(int );
	void get_3(int );
	
};
v_date::v_date(int a=0, int b=0, int c=0)  
	{
		if (a<31) 
		    number=a;
		if (b<13) 
		    month=b;
		if (c<2014) 
		    year=c;
	}

int v_date::put_1()
{
	return number;
}
int v_date::put_2()
{
	return month;
}
int v_date::put_3()
{
	return year;
}
void v_date::get_1(int a)
{
	if (a<31)
	    number=a;
	else 
		number=0;
}
void v_date::get_2(int b)
{
	if (b<13)
		month=b;
	else
		month=0;
}
void v_date::get_3(int c)
{
	if (c<2014)
		year=c;
	else
		year=0;
}

	ostream& operator << (ostream& out, v_date p)
	{
		out<<setw(2)<<p.put_1()<<"/"<<setw(2)<<p.put_2()<<"/"<<setw(4)<<p.put_3()<<endl;
		return out;
	}
	istream& operator >> (istream& in, v_date& p)
	{
		int a;
		cout<<"\nEnter number ";
		in>>a;
		p.get_1(a);
		cout<<"\nEnter month ";
		in>>a;
		p.get_2(a);
		cout<<"\nEnter year ";
		in>>a;
		p.get_3(a);
		return in;
	}
	int operator >= (v_date p, v_date pp)
	{   int kz;
		int np=365*p.put_3()+30*p.put_2()+p.put_1();
		int npp=365*pp.put_3()+30*pp.put_2()+pp.put_1();
	return  kz=np<npp ? 0: 1; //вычисляем большую дату
		
	}
		
	void main()
	{
		v_date d1, d2;
		cout<<"\nEnter d1\n";
		cin>>d1;
		cout<<"\nd1="<<d1;
		cout<<"\nEnter d2\n";
		cin>>d2;
		cout<<"\nd2="<<d2;
		if (d1>=d2)
			cout<<"\nbig number "<<d1;
		else 
			cout<<"\nbig number "<<d2;
		
	}
вот программка не хватает оператора +=, не могу понять как сделать... что-то вроде
Код:
 v_date operator += (v_date p, v_date pp)

{ int zz; zz=p.put_1()+pp.put_1(); return zz;}
может кто поможет /

//решил

Последний раз редактировалось Nea7; 24.12.2007 в 19:04..
 
Ответить с цитированием