年月日=天
#include <iostream.h>
class date{
public:
void setdate(int y,int m,int d)
{cin>>y>>m>>d;
{year=y;month=m;day=d;}
int count()
{
int *p,i,*j;
int date1[][13]={{0,31,28,31,30,31,31,30,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}}
p=date1[0];
i=(year%4==0&&year%100!=0||year%400==0);
if(i) p+=13;
j=p+month;while(p<j){yd+=*p;p++;}
return yd;
}
void setdate(int y,int m,int d)
{cin>>y>>m>>d;}
void print()
{cout<<year<<"年"<<month<<"月"<<day<<"日:";
cout<<yd;
}
private:
int year,month,day,yd;
}
void main()
{
int y,m,d;
date h;
h.setdate(y,m,d);
h.count();
h.print;
}
阶乘的练习(有错误)
#include <iostream.h>
class jiecheng{
public:
void setnumber(int m)
{cin>>m;n=m;}
void print()
{cout<<m<<"!="ji();}
int ji()
{int i;sum(1)
for(i=1;i<=m;i++)
sum*=i;
return sum;
}
private:
int m,sum;
}
void main()
{jiecheng t;
for(int i=2;i<=9;i++)
{t.setnumber(i);
t.print();}
}
改正后的
#include <iostream.h>
class jiecheng{
public:
void setnumber(int m)
{cin>>m;n=m;}
void print()
{cout<<m<<"!="ji();}
int ji()
{int i;sum(1)
for(i=1;i<=m;i++)
sum*=i;
return sum;
}
private:
int m,sum;
}
void main()
{jiecheng t[10];
for(int i=2;i<=9;i++)
{t[i].setnumber(i);
t[i].print();}
}