帮助OO闰年计算器 [英] Help on OO leap year calculator
问题描述
您好!!!我需要一个项目的帮助我计算闰年;我是错误的b $ b得到错误,我不知道他们的意思;这里是代码:
#include< iostream>
#include< cstdlib>
using namespace std ;
班级年份
{
公开:
年份(int y = 0): year(new int)* year(y){}
~Ya year(){删除年份;}
年(const年& rhs)*年(rhs。*年份){}
年度运算符=(const年& rhs)
{
if(this!=& rhs)
{
*年= rhs->年;
删除年份;
}
否则返回;
}
void SetYear(int y):year(new int),* year(y){}
int GetYear()const {return * year;}
bool IsLeapYear(const Year& y)const
{
if(y-> ;年%400 == 0&& y->年%4 == 0)
返回true;
else if(y-> year%100 )
返回false;
返回false
}
朋友ostream& operator<<(ostream& os,const Year& y);
private:
int * year;
};
ostream& operator<<(ostream& os,const Year& y)
{
os<< y.GetYear();
返回操作系统;
}
}
int main()
{
int date;
for(;;)
{
cout< < 输入年份: << endl;
cin>>日期;
年份(日期);
if(year.IsLeapYear)
cout<<年<< "是闰年。 " << endl;
else
cout<<年<< "不是闰年。 " << endl;
bool cont;
cout<< 继续?[1 =是| 0 =否]: << endl;
cin>>续;
if(cont == true)继续;否则中断;
system(PAUSE);
返回0;
}
作为附注,它不是让我使用构造函数iniguilization
语法。你能帮我(这不是功课)吗?谢谢你的帮助!!!
Hi!!! I need some help on a project I''m that calculates leap years; I''m
getting errors that I have no idea what they mean; here''s the code:
#include <iostream>
#include <cstdlib>
using namespace std;
class Year
{
public:
Year(int y=0):year(new int) *year(y){}
~Year(){delete year;}
Year(const Year& rhs)*year(rhs.*year){}
Year operator=(const Year& rhs)
{
if(this!=&rhs)
{
*year=rhs->year;
delete year;
}
else return this;
}
void SetYear(int y):year(new int),*year(y){}
int GetYear()const{return *year;}
bool IsLeapYear(const Year& y)const
{
if(y->year%400==0&&y->year%4==0)
return true;
else if(y->year%100)
return false;
else return false
}
friend ostream& operator<<(ostream& os,const Year& y);
private:
int* year;
};
ostream& operator<<(ostream& os,const Year& y)
{
os << y.GetYear();
return os;
}
}
int main()
{
int date;
for(;;)
{
cout << "Enter a year: " << endl;
cin >> date;
Year year(date);
if(year.IsLeapYear)
cout << year << " is a leap year. " << endl;
else
cout << year << " is not a leap year. " << endl;
bool cont;
cout << "Continue?[1=yes|0=no]: " << endl;
cin >> cont;
if(cont==true)continue;else break;
system("PAUSE");
return 0;
}
And as a side note, it''s not letting me use constructor inizilization
syntax. Can you help me (this isn''t homework)? Thanks for your help!!!
推荐答案
你会得到什么样的错误?
And what erros u get?
我确定这是一个学校的工作;>
And I''m sure this _is_ a school work ;>
不,不是;我的朋友,BIOLA的Jonathon Mastron,让我把它给了他。我的学校工作是三角形的东西,而不是日历和日期。请帮助
我。
No it''s not; my friend, Jonathon Mastron at BIOLA, asked me to it for
him. My school work is trig stuff, not calendars and dates. Just help
me please.
这篇关于帮助OO闰年计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!