C语言程序的设计实验报告一Word文档下载推荐.docx

上传人:b****5 文档编号:17289390 上传时间:2022-11-30 格式:DOCX 页数:23 大小:142.65KB
下载 相关 举报
C语言程序的设计实验报告一Word文档下载推荐.docx_第1页
第1页 / 共23页
C语言程序的设计实验报告一Word文档下载推荐.docx_第2页
第2页 / 共23页
C语言程序的设计实验报告一Word文档下载推荐.docx_第3页
第3页 / 共23页
C语言程序的设计实验报告一Word文档下载推荐.docx_第4页
第4页 / 共23页
C语言程序的设计实验报告一Word文档下载推荐.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

C语言程序的设计实验报告一Word文档下载推荐.docx

《C语言程序的设计实验报告一Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《C语言程序的设计实验报告一Word文档下载推荐.docx(23页珍藏版)》请在冰豆网上搜索。

C语言程序的设计实验报告一Word文档下载推荐.docx

do

\t\t1copystring.\n”);

\t\t2connectstring.\n"

);

\t\t3exit.'

n"

printf("

\t\tinputanumber(1-3)please!

\n”);

scanf("

%d"

&

choice);

}

while(choice<

1||choice>

5);

switch(choice)

case1:

p=strcpy;

break;

case2:

p=strcat;

case3:

gotodown;

getchar();

inputthefirststringplease!

\n“);

i=0;

inputthesecondstringplease!

\n"

result=(a,b);

theresultis%s\n”,result);

down:

(2)请上机运行第

(1)题程序使之能按下面要求输出结果(注:

(输入)表示该行数据

是键盘数据):

1.copystring。

2.Connectstring。

3.Exit。

Inputanumber(1-3)please!

2(输入)

Inputthefirststringplease!

Themoreyoulearn,(输入)

Inputthesecondstringplease!

Themoreyouget.(输入)

Theresultisthemoreyoulearn,themoreyouget.

3.跟踪调试程序

请按下面的要求对所给源程序进行操作,并回答问题和排除错误。

(1)单步执行源程序。

进入strcpy时,watches窗口中s为何值?

返回main时,watches窗口中s为何值?

(2)排除源程序中的错误,使程序输出结果为:

thereisaboatonthelake.

#include<

char*strcpy(char*,char*);

chara[20],b[60]="

thereisaboatonthelack."

;

%s\n"

strcpy(a,b));

char*strcpy(char*s,char*t)

while(*s++=*t++)

5

return(s);

4.程序设计

编写并上机调试运行能实现以下功能的程序或函数:

(1)已知一个长整形变量占四个字符,其中每个字节又分高四位和低四位。

试编写一个程序,从该长整形变量的高字节开始,依次取出每个字节的高四位和低四位并以数字字符的形式进行显示。

(2)利用大小为n的指针数组指向用gets函数输入的n行,每行不超过80个字符。

试编

写一个函数,它将每一行中连续的多个空格字符压缩为一个空格字符。

在调用函数中输出

压缩空格后的各行,空行不予输出

(3)编写一个程序,输入n个整数,排序后输出。

排序的原则由命令行可选参数-d决定,并且有参数-d时按递减顺序,否则按递增顺序排序。

要求将排序算法定义成函数,利用指向函数的指针是该函数实现递增或递减排序。

(4)设每个班有n个学生,每个学生所修的M门课程的成绩,并且都存放到相应的数组中,试编写以下函数:

1计算每个学生各门课程平均成绩

2计算全班每门课程的平均成绩

3分别统计低于全班各门课程平均成绩的人数

4分别统计全班各门课程不及格的人数和90分以上(包含90)的人数。

在调用函数中输出结果(要求都用指针操作,不得用下标)

5•选做题

(1)编写并上机调试运行能实现以下功能的程序:

设有N位整数和M位小数(N=20,M=10)的两个数据a,b。

编程计算a+b并输出结果。

如:

12345678912345678912.1234567891+98765432109876543210.0123456789

(2)编写一个使用复杂声明的“har*(*p[2])(constchar*,constchar*);

"

的程序。

提示:

p中元素可为strcmp,strstr等函数名。

三、实验步骤及结果

错误:

悬挂指针,指针未初始化

改后程序:

#include<

intmain(void){

float*p,a;

p=&

a;

■=:

:

,1-*C:

\Docu>

entsandSettings\ib>

\ByDocunents\学樓\.c件业Ic实螫\指针实^\1.--5Tb00

3■000000

ProcessreturnedQ<

0x0>

executiontime:

3.266sPressanykeytocontinue.

2.

源程序完善、修改、替换

char*(*p)(char*a,char*b);

\t\t2connectstring.\n”);

\t\tinputanumber(1-3)please!

switch(choice)

inputthefirststringplease!

'

n"

while((a[i]=getchar())!

='

\n'

i++;

a[i]='

\0:

while((b[i]=getchar())!

b[i]='

\0'

result=(*p)(a,b);

theresultis%s\n"

result);

down:

g*C:

\lyDociULente\学栓\.c作业Ic实鲨\指针实^\2...

1copystring.

2connectstring.

3exit.

inputanumber<

l-3>

please*

*

inputthefirststringplease*

themoreyoulearn,

inputthesecondstringplease*

themoreyouget-

theresultisthemoreyoulearn,themoreyouget.

Processreturned0<

37.250s

Pressanykeytocontinue.

3.

跟踪调试程序

Vetches

ELocalvariaElfes

Nolocals.„

BFiinctionArfuments

s=0x2£

ff2c「峨Ei峨"

”=0x22fefO"

thareis直bo«

tonth«

lack."

Vtttckes

ELocalvariaEles

1S&

locals.

BFulucIionArfuments

s=0x22f£

49“

t=0x22f£

Dd

#include<

intmain(void){

char*m;

m=s;

return(m);

(1)

math.h>

#defineMAX32

intmain()

longintn;

inti;

chars[MAX];

pleaseinputanumber:

%ld"

n);

if(n>

=-2147483647&

&

n<

=2147483647)

else

wrong:

thenumberistoolarge"

return-1;

=0)

for(i=0;

n!

=0;

i++)

s[i]=n%2+'

0:

n/=2;

for(;

i<

=MAX-1;

s[i]='

O:

n=_(n+1);

0'

=MAX-2;

i++)s[i]='

MAX-1;

i++)if(s[i]=='

1'

)s[i]='

elseif(s[i]=='

for(i=31;

i>

=28;

i--)

putchar(s[i]);

putchar('

\t'

for(i=27;

=24;

putchar('

for(i=23;

=20;

i--)putchar(s[i]);

for(i=19;

=16;

for(i=15;

=12;

for(i=11;

=8;

for(i=7;

=4;

for(i=3;

stdlib.h>

ctype.h>

#defineN3

voidoutput(char*s);

char*s[N];

pleaseinputyourmassage:

N;

s[i]=malloc(80);

gets(s[i]);

yourmassagehasbeenchangedinto;

output(s[i]);

s[i]);

voidoutput(char*s)

inti,j;

for(i=0,j=0;

s[i]!

i++,j++)

if(isspace(s[i]))

isspace(s[i]);

s[j++]='

s[j]=s[i];

elses[j]=s[i];

entsandSettings\ibM\IyDociULents\学校l匚作业实鲨l指针实鲨\4・■■岂回「

pleaseinputyoui*massage:

k-jhatareyou

doing

riou

youpnassagehasbeenchangedinto;

nou

46.234sPressanykeytocantinue.

#defineMAX5voidswap(intv[],inti,intj);

voidqsort(intv[],intleft,intright);

intmain(intargc,char*argv[])

infli'

OSMAX"

if(——argcvoQOQO(*++argv)ollu<

=h((*argv)ullH-d-)

whiCD(AMAX)

scanf(=%d=QOs=++mqsort(SOMAXa八for(ll'

MAX丄ivuo〒-)prinff(=%dw「s=2

prinff(=wrong,n=)八e-se宀

scanf(=%d=QOs=++pqsomsoMAXa八for(ll'

oxMAXT+)prinff(=%dw「s=2

•T舞凹>

#-

 

voidqsort(intv[],intleft,intright){

inti,last;

voidswap(intv[],inti,intj);

if(left>

right)

return;

swap(v,left,(left+right)/2);

last=left;

for(i=left+1;

=right;

i++)if(v[i]<

v[left])swap(v,++last,i);

swap(v,left,last);

qsort(v,left,last-1);

qsort(v,last+1,right);

voidswap(intv[],inti,intj)

inttemp;

temp=v[i];

v[i]=v[j];

v[j]=temp;

#defineN5

#defineM3

structcourse

char*s;

intd[N];

}sm[M];

voidsaverage(structcourse*sm);

voidcaverage(structcourse*sm);

voidsummary_below(structcourse*sm);

voidsummary_both(structcourse*sm);

Pleaseinputthenamesofthe%dcourses.'

M);

M;

if(gets((sm+i)->

s=malloc(10))==NULL)

ERROR"

intk;

%s

Pleaseinputthegradesof%dstudentsofthesubject'

N,(sm+i)_>

s);

for(k=0;

k<

k++)

(sm+i)->

d+k);

saverage(sm);

caverage(sm);

summary_below(sm);

summary_both(sm);

voidsaverage(structcourse*sm)

doublesum=0,av;

inti,k;

Thisisthe%dstudent'

saveragegrade\t"

i+1);

sum+=*((sm+k)->

d+i);

av=sum/M;

%lf\n"

av);

sum=O;

voidcaverage(structcourse*sm)

Thisistheaveragegradeof%s\t"

sum+=*((sm+i)_>

av=sum/N;

sum=0;

voidsummary_below(structcourse*sm)

In%sthenumberofbelow-averagestudentis\t"

for(sum=0,k=0;

if(*((sm+i)->

d+k)<

av)

sum++;

%d\n"

(int)sum);

voidsummary_both(structcourse*sm)

intfsum=0,esum=0;

Thecourseis%s\t"

(*(sm+i)).s);

60)

fsum++;

d+k)>

90)

esum++;

thefailedis%d,whiletheabove90is%d\n"

fsum,esum);

fsum=0,esum=0;

s*C:

entsandSettings\ibM\lyDaciULents\学橈\.c作业实鲨'

指针实鲨\4・■■

inti,t=0;

chara[]="

12345678912345678912.1234567891"

charb[]="

98765432109876543210.0123456789"

ints[32];

s[0]=0;

32;

s[i]=0;

for(i=30;

if(a[i]=='

.'

i--;

intm,n,k;

m=a[i]_'

+t;

n=b[i]-'

k=m+n;

if(k>

=10)

t=k/10;

s[i+1]=k%10;

s[i+1]=k%10;

t=0;

k=0;

s[O]=t;

if(i==21)

."

intn;

char*(*p[2])(constchar*,constchar*);

char*a;

char*b;

char*c;

pleaseinputstringone:

a=malloc(20);

gets(a);

pleaseinputstringtwo:

b=malloc(20);

gets(b);

the

\nOtochoosethestrcpy\n1tochoose

strcat\n"

&

p[0]=strcpy;

p[1]=strcat;

2||n<

0)

wrong"

return

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

当前位置:首页 > 求职职场 > 社交礼仪

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1