}
}
file.close();
}
#include
usingnamespacestd;
constintN=7;
intlast(constint&year,constint&month)
{
intnLast;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
nLast=31;//若每有天,则月末日期为
elseif(month==2)
{
if((year%4==0&&year%100!
=0)||year%400==0)
nLast=29;//若为闰年则本月月末是号
else
nLast=28;//若为普通年份则本月末是号
}else
nLast=30;//若每月有天,则日期为
returnnLast;
}
voidmain()
{
intsrYear[N]={2000,1999,2000,1899,2051,1999,1999};
intsrMonth[N]={1,4,2,1,1,0,13};
intyqshuchu[N]={31,30,29,0,0,0,0};
for(inti=0;i{
cout<<"第"<
if(last(srYear[i],srMonth[i])==yqshuchu[i])
cout<<"通过"<else
cout<<"未通过"<}
}
#include
#definePI3.1415926
#include
classbase//抽象基类BO声明
{
public:
virtualvoiddisplay()=0;//纯虚数
};
classcircle:
publicbase//公有派生
{
protected:
doubler;
public:
circle(doublex=0)
{r=x;}
voiddisplay()
{
cout<<"圆的面积为:
"<}
};
classcfx:
publicbase
{
doublea,b,s;
public:
cfx(doublex=0,doubley=0)
{
a=x;
b=y;
voiddisplay()
{
s=a*b;
cout<<"长方形的面积为:
"<
}
}
};
classtx:
publicbase
{
doublea,b,h,s;
public:
tx(doublea1=0,doubleb1=0,doubleh1=0)
{
a=a1;b=b1,h=h1;
}
voiddisplay()
{
s=(a*b)*h/2;
cout<<"梯形的面积为:
"<
}
};
voidfun(base*ptr)//普通函数
{
ptr->display();
};
voidmain()
{
base*P;//声明抽象基类指针
circlec1(10);//声明派生类对象
cfxc2(9,10);//声明派生类对象
txc3(6,10,5);
p=&c1;
fun(p);
p=&c2;
fun(p);
p=&c3;
fun(p);
};
intfun(floata,floatb,floatc)
{
floats;
if(a+b>c&&b+c>a&&a+c>b)
{
s=(a+b+c)/2;
if(a==b&&b==c)
{
cout<<"等边三角形";
return2;
}elseif(a==b||a==c||b==c){
cout<<"等腰三角形";
return3;
}elseif((a*a+b*b==c*c)||(a*a+c*c==b*b)||(b*b+c*c=a*a)){
cout<<"直角三角形";
return4;
}else{
cout<<"一般三角形";
return1;
}else{
cout<<"不能组成三角形";
return0;
}
}
}
//求最大公约数和最小公倍数
#include
usingnamespacestd;
fun(intm,intn)
{
intt,r;
if(mwhile(n!
=0)
{
r=m%n;
m=n;
n=r;
}
returnm;
}
voidmain()
{
cout<<"18和的最大公约数是:
"<}
#include
usingnamespacestd;
constintN=4;
intIsLeap(intyear)
{
intleap;
if(year%4==0)
{
if(year%100==0)
{
if(year%400==0)
leap=1;
else
leap=0;
}else
leap=1;
}else
leap=0;
returnleap;
}
voidmain()
{
intshu[N]={1999,2004,1990,2000};
intshuchu[N]={0,1,0,1};
for(inti=0;i{
cout<<"第"<
if(IsLeap(shu[i])==shuchu[i])
cout<<"通过"<else
cout<<"未通过"<}
}
/*用-9之间不同的三个数构成一个三位数*/
#include
#include
usingnamespacestd;
intmain()
{
inti,j,k,count=0;
for(i=1;i<10;i++)
{
for(j=0;j<10;j++)
{
for(k=0;k<10;k++)
{
if(i==j||j==k||i==k)continue;
cout<
count++;
}
}
}
cout<<"总共有"<}
/*统计学生成绩*/
#include
#include
usingnamespacestd;
intmain()
{
charname[5][12]={"小强","小红","张三","李四","王五"};
intscore,min,max;
intn=1;
doublesum;
fstreamfile("score.txt",ios:
:
out);
if(!
file){
cout<<"不能打开文件:
"<<"score.txt"<return-1;
}
cout<<"Englishcheng:
"<min=100;
max=0;
while(true)
{
file<";
cout<<"Pleaseinput"<"<cout<<"Pleaseinput"<";
cin>>score;
file<n++;
sum+=score;
if(score>max)max=score;
elseif(score}
file<<"共计"<file<<"最高分,"<file<<"最低分"<file<<"平均分"<file.close();
}
/*文件*/
#include
#include
usingnamespacestd;
intmain()
{
charname[20];
intscore,min,max,sum;
intn,n60,n90;
fstreamfile("chengji.txt",ios:
:
out);
if(!
file){
cout<<"不能打开文件:
"<<"chengji.txt"<return-1;
}
while(true)
{
cout<<"Pleaseinputname(0exit):
";
cin>>name;
if(name[0]=='0')break;
cout<<"Pleaseinputhisscore:
";
cin>>score;
file<'<n++;
sum+=score;
if(score>max)max=score;
elseif(scoreif(score<60)n60++;
elseif(score>=90)n90++;
}
file<<"共计"<file<<"最高分,"<file<<"最低分"<file<<"平均分"<file<<"优秀率(>=90),"<file<<"不及格率(<60),"<file.close();
}
intfun(floata,floatb,floatc)
{
floats;
if(a+b>c&&b+c>a&&a+c>b)
{
s=(a+b+c)/2;
if(a==b&&b==c)
{
cout<<"等边三角形";
return2;
}elseif(a==b||a==c||b==c){
cout<<"等腰三角形";
return3;
}elseif((a*a+b*b==c*c)||(a*a+c*c==b*b)||(b*b+c*c==a*a)){
cout<<"直角三角形";
return4;
}else{
cout<<"一般三角形";
retur