省程序员考试Word下载.docx

上传人:b****4 文档编号:7247756 上传时间:2023-05-08 格式:DOCX 页数:24 大小:20.05KB
下载 相关 举报
省程序员考试Word下载.docx_第1页
第1页 / 共24页
省程序员考试Word下载.docx_第2页
第2页 / 共24页
省程序员考试Word下载.docx_第3页
第3页 / 共24页
省程序员考试Word下载.docx_第4页
第4页 / 共24页
省程序员考试Word下载.docx_第5页
第5页 / 共24页
省程序员考试Word下载.docx_第6页
第6页 / 共24页
省程序员考试Word下载.docx_第7页
第7页 / 共24页
省程序员考试Word下载.docx_第8页
第8页 / 共24页
省程序员考试Word下载.docx_第9页
第9页 / 共24页
省程序员考试Word下载.docx_第10页
第10页 / 共24页
省程序员考试Word下载.docx_第11页
第11页 / 共24页
省程序员考试Word下载.docx_第12页
第12页 / 共24页
省程序员考试Word下载.docx_第13页
第13页 / 共24页
省程序员考试Word下载.docx_第14页
第14页 / 共24页
省程序员考试Word下载.docx_第15页
第15页 / 共24页
省程序员考试Word下载.docx_第16页
第16页 / 共24页
省程序员考试Word下载.docx_第17页
第17页 / 共24页
省程序员考试Word下载.docx_第18页
第18页 / 共24页
省程序员考试Word下载.docx_第19页
第19页 / 共24页
省程序员考试Word下载.docx_第20页
第20页 / 共24页
亲,该文档总共24页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

省程序员考试Word下载.docx

《省程序员考试Word下载.docx》由会员分享,可在线阅读,更多相关《省程序员考试Word下载.docx(24页珍藏版)》请在冰点文库上搜索。

省程序员考试Word下载.docx

f2;

n=2;

while(n<

20)

f3=f1+f2;

if(f3%2)

f3;

n++;

if(n%5==0)cout<

f1=f2;

f2=f3;

11235813

 

/*ex=1+x+x2/2!

+x3/3!

+x4/4!

+...+xn/n!

+....

计算ex的近似值.设x位于区间[0,1],该算法要点是逐步累积计算每项xn/n!

的值(作为T),

再逐步累加T值得到所需的结果S.当T值小于-5时,结束计算*/

#include<

math.h>

doubleEX(doublex)

doubleex,xx,nn,temp,i;

if(x<

0||x>

1)return0;

if(x==0.0)return1;

ex=1,xx=nn=1,i=1;

do{

xx*=x;

nn*=i;

temp=xx/nn;

ex+=temp;

i++;

}while(temp>

1e-5);

returnex;

EX(0)="

EX(0)<

EX(0.5)="

EX(0.5)<

EX

(1)="

EX

(1)<

/*抽象类*/

iostream.h>

#definePI3.1415926

classbase//抽象基类BO声明

{public:

//外部接口

virtualvoiddisplay()=0;

//纯虚函数成员

};

classcircle:

publicbase//公有派生

{protected:

doubler;

public:

circle(doublex=0)

{r=x;

voiddisplay()

{cout<

圆的面积:

r*r*PI<

classcfx:

{

doublea,b,s;

cfx(doublex=0,doubley=0)

a=x;

b=y;

s=a*b;

cout<

长方形的面积:

s<

classtx:

doublea,b,h,s;

tx(doublea1=0,doubleb1=0,doubleh1=0)

{a=a1;

b=b1;

h=h1;

s=(a+b)*h/2;

梯形的面积:

voidfun(base*ptr)//普通函数

ptr->

display();

voidmain()//主函数

base*p;

//声明抽象类基类指针

circlec1(10);

//声明派生类对象

cfxc2(9,10);

txc3(6,10,5);

p=&

c1;

fun(p);

c2;

c3;

//后面一数是前面两项之和

intfun(intA[],intn)

intm=0;

if(n>

1)

for(inti=1;

i<

i++)

{

for(intj=m;

j>

=0;

j--)

{

if(A[i]==A[j])break;

}

if(j>

=0)continue;

A[m+1]=A[i];

}

returnm;

inta[10]={5,2,2,7,4,4,7,1,9,1};

intk=fun(a,10);

for(inti=0;

=k;

a[i]<

"

;

//计算两点之间的距离

conio.h>

classTpoint{

doublex,y;

//增加public

public:

Tpoint(doublea,doubleb)

x=a;

y=b;

frienddoublediatance(Tpointa,Tpointb);

doubledistance1(Tpointa,Tpointb)

//改为doubledistance1(Tpointa,Tpointb)

doubledist;

dist=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));

returnrist;

voidmain()

Tpointpa(2,2),p2(5,5);

上述两点之间的距离:

distance1(p1,p2)<

//将p1.distance(p1,p2)改为distance1(p1,p2)

getch();

/*构造函数*/

classBuilding

Building(intf,intr,intft)

floors=f;

rooms=r;

footage=ft;

voidshow()

floors:

floors<

rooms:

rooms<

totalarea:

footage<

protected:

intfloors;

introoms;

doublefootage;

classHousing:

publicBuilding

Housing(intf,intr,doubleft,intbd,intbth):

Building(f,r,ft)

bedrooms=bd;

bathrooms=bth;

\nHOUSING:

\n"

Building:

:

show();

bedrooms:

bedrooms<

bathrooms:

bathrooms<

private:

intbedrooms;

intbathrooms;

classOffice:

Office(intf,intr,doubleft,intmie,inttel):

miehuoqi=mie;

telphone=tel;

\nOFFICE:

miehuoqi:

miehuoqi<

telphone:

telphone<

intmiehuoqi;

inttelphone;

Housinghob(5,8,100,56,18);

Officeoob(6,89,56,88,5);

hob.show();

oob.show();

/*编写程序,从键盘上输入一个*3的整数矩阵A和一个*2列

的整数矩阵B,把矩阵的值输出到文件juzhen.txt中.

A

123

456

B

12

34

56

两个矩阵相乘

*/

fstream>

intmain()

inti,j,A[2][3],B[3][2];

fstreamfile("

juzhen.txt"

ios:

out);

if(!

file){

不能打开文件:

return-1;

A"

for(i=0;

for(j=0;

j<

3;

j++)

cin>

>

A[i][j];

file<

file<

B"

B[i][j];

intc=0;

for(intk=0;

c+=A[i][k]*B[k][j];

cout<

c;

file.close();

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;

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};

N;

第"

i+1<

个用例测试"

if(last(srYear[i],srMonth[i])==yqshuchu[i])

通过"

未通过"

//纯虚数

publicbase//公有派生

圆的面积为:

publicbase

b=y;

voiddisplay()

s=a*b;

长方形的面积为:

a=a1;

b=b1,h=h1;

s=(a*b)*h/2;

梯形的面积为:

base*P;

//声明抽象基类指针

circlec1(10);

cfxc2(9,10);

txc3(6,10,5);

p=&

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)

等边三角形"

return2;

}elseif(a==b||a==c||b==c){

等腰三角形"

return3;

}elseif((a*a+b*b==c*c)||(a*a+c*c==b*b)||(b*b+c*c=a*a)){

直角三角形"

return4;

}else{

一般三角形"

return1;

不能组成三角形"

return0;

//求最大公约数和最小公倍数

fun(intm,intn)

intt,r;

if(m<

n){t=m;

m=n;

n=t;

while(n!

=0)

r=m%n;

m=n;

n=r;

18和的最大公约数是:

fun(18,36)<

最小公倍数是"

(18*36/fun(18,36))<

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;

leap=0;

returnleap;

intshu[N]={1999,2004,1990,2000};

intshuchu[N]={0,1,0,1};

个用例测试"

if(IsLeap(shu[i])==shuchu[i])

/*用-9之间不同的三个数构成一个三位数*/

inti,j,k,count=0;

for(i=1;

10;

for(k=0;

if(i==j||j==k||i==k)continue;

cout<

count++;

总共有"

count;

/*统计学生成绩*/

charname[5][12]={"

小强"

"

小红"

张三"

李四"

王五"

intscore,min,max;

intn=1;

doublesum;

score.txt"

Englishcheng:

min=100;

max=0;

while(true)

file<

name[n-1]<

Pleaseinput"

chengji:

Pleaseinput"

n<

score:

cin>

score;

score<

sum+=score;

if(score>

max)max=score;

elseif(score<

min)min=score;

file<

共计"

n-1<

个学生"

最高分,"

max<

最低分"

min<

平均分"

sum/n<

file.close();

/*文件*/

charname[20];

intscore,min,max,sum;

intn,n60,n90;

chengji.txt"

Pleaseinputname(0exit):

name;

if(name[0]=='

0'

)break;

Pleaseinputhisscore:

name<

if(score<

60)n60++;

elseif(score>

=90)n90++;

优秀率(>

=90),"

n90*100/n<

%'

不及格率(<

60),"

n60*100/n<

}elseif((a*a+b*b==c*c)||(a*a+c*c==b*b)||(b*b+c*c==a*a)){

retur

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2