c语言第七次作业解析Word文件下载.docx

上传人:b****4 文档编号:16685722 上传时间:2022-11-25 格式:DOCX 页数:26 大小:150.45KB
下载 相关 举报
c语言第七次作业解析Word文件下载.docx_第1页
第1页 / 共26页
c语言第七次作业解析Word文件下载.docx_第2页
第2页 / 共26页
c语言第七次作业解析Word文件下载.docx_第3页
第3页 / 共26页
c语言第七次作业解析Word文件下载.docx_第4页
第4页 / 共26页
c语言第七次作业解析Word文件下载.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

c语言第七次作业解析Word文件下载.docx

《c语言第七次作业解析Word文件下载.docx》由会员分享,可在线阅读,更多相关《c语言第七次作业解析Word文件下载.docx(26页珍藏版)》请在冰豆网上搜索。

c语言第七次作业解析Word文件下载.docx

&

(q->

year)%100!

=0)||(q->

year)%400==0)

if(p->

month<

=2||q->

month>

2)

total++;

}

elseif(years!

=0)

for(i=p->

12;

i++)total+=monthday[i];

for(i=0;

total+=q->

year+1;

year);

{

total+=365;

if((i%4==0&

i%100!

=0)||i%400==0)

}

if(((p->

year%4==0&

p->

year%100!

=0)||p->

year%400==0)&

=2)total++;

=0)||q->

2)total++;

returntotal;

voidmain()

intdays;

printf("

pleaseinputdate1(year,month,day):

"

);

scanf("

%d,%d,%d"

&

date1.year,&

date1.month,&

date1.day);

pleaseinputdate2(year,month,day):

date2.year,&

date2.month,&

date2.day);

days=totaldays(&

date1,&

date2);

days=%d\n"

days);

2.结构体数组应用

请定义一个描述学生基本信息的结构,包括姓名,学号,籍贯,身份证号,年龄,家庭住址,性别,联系方式等。

并定义一个结构体数组。

编程:

a)编写函数input(),输入基本信息(3~5条记录);

b)编写函数print(),输出全体记录信息;

c)编写函数search(),检索一个指定的学生信息并返回,由主函数打印到屏幕上;

d)说明,访问结构的时候,什么时候应该用运算符“.”,什么时候应该用运算符“->

”。

string.h>

structstudent

{charname[20];

intnum;

charhome[20];

charIDnum[20];

intage;

charaddr[50];

charsex;

charphone[20];

}stu[10];

voidinput(structstudent*p)

%s%d%s%s%d%s%c%s"

name,&

num,&

home,&

IDnum,&

age,&

addr,&

sex,&

phone);

voidprint(structstudent*p)

%s,%d,%s,%s,%d,%s,%c,%s\n"

p->

name,p->

num,p->

home,p->

IDnum,p->

age,p->

addr,p->

sex,p->

intsearch(structstudentstu[],intn,charstu_name[20])

inti;

for(i=0;

n;

if(strcmp(stu_name,stu[i].name)==0){returni;

break;

elsecontinue;

returnn+1;

intn,i;

chara[20];

pleaseinputthenumberofthestudents:

%d"

n);

i++)input(&

stu[i]);

i++)print(&

pleaseinputthenameofthestudentyouwanttosearch:

\n"

%s"

a);

i=search(stu,n,a);

if(i<

n)print(&

elseif(i==n+1)printf("

Nothisstudent!

3.一元多项式加法

编写一元多项式加法器,输入两个一元稀疏多项式,然后对它们进行加法操作。

在具体实现上,要求用线性链表形式来存储一个多项式,每个链表的节点包括两个成员变量,系数和指数(均为整数)。

例如

可以用下面的链表表示:

说明:

(1)每个链表节点都是根据需要动态创建的;

(2)程序采用多函数形式来实现,至少包括创建链表、打印链表、加法函数等。

(3)多项式系数可正、可负;

指数肯定是非负整数,且按照递增顺序排列

输入格式:

第一行是一个整数M,表示第一个多项式的项数。

接下来有M行,每行有两个整数ci和ei,分别表示第i项的系数和指数。

再接下来是输入第二个多项式,方法同第一个多项式输入。

输出格式:

输出两个多项式相加的结果。

第一行是整数K,表示新多项式的项数。

接下来有K行,每一行为两个整数,分别代表系数和指数。

malloc.h>

#defineLENsizeof(structpoly)

structpoly

{intc;

inte;

structpoly*next;

}poly1[10],poly2[10];

voidinput(structpolya[],intm)

for(inti=0;

m;

scanf("

%d,%d"

a[i].c,&

a[i].e);

structpoly*linkcreate(structpolya[],intm)

structpoly*head;

structpoly*p1,*p2;

p1=p2=(structpoly*)malloc(LEN);

head=p1=&

a[0];

{p2=&

a[i];

p1->

next=p2;

p1=p2;

p1->

next=NULL;

return(head);

voidlinkprint(structpoly*head)

structpoly*p;

thepolynomial:

p=head;

if(head!

=NULL)

do

printf("

%dx^%d"

c,p->

e);

p=p->

next;

if(p!

=NULL)putchar('

+'

}while(p!

=NULL);

putchar('

\n'

structpoly*add(structpoly*head1,structpoly*head2)

structpoly*p1,*p2,*p3,*p4;

p1=p2=p3=p4=(structpoly*)malloc(LEN);

p2=head2;

do

p1=head1;

while(p1!

if(p2->

e==p1->

e)

{

p1->

c=p1->

c+p2->

c;

p4=p2;

p2=p2->

p1=head1;

}

elsep3=p1;

p1=p1->

while((p2->

e>

e)&

(p1->

next!

=NULL))

{p3=p1;

p1=p1->

p4=p2;

p2=p2->

if(p4->

e<

if(head1==p1)head1=p4;

elsep3->

next=p4;

p4->

next=p1;

else{p1->

p4->

}while(p2!

return(head1);

voidaddprint(structpoly*head)

structpoly*p1;

thenewpolynomial:

p1=head;

p1->

c,p1->

if(p1!

putchar('

intm,n;

structpoly*p,*q,*head;

pleaseinputthenumberoffirstterms:

m);

input(poly1,m);

p=linkcreate(poly1,m);

linkprint(p);

pleaseinputthenumberofsecondterms:

input(poly2,n);

q=linkcreate(poly2,n);

linkprint(q);

head=add(p,q);

addprint(head);

4.循环淘汰

有N个同学,编号分别为1,2,3……,N,围成一圈,随便选定一个整数m,让大家按顺时针依次报数,报到m的同学便会从圈子中退出,从而被淘汰,直到最后剩下一个人。

编写函数实现上述循环淘汰功能。

编写一个程序测试上述函数的功能,要求用户能够任意输入N与m;

程序输入最后剩下人的编号。

#defineLENsizeof(structstudent)

intnum;

structstudent*next;

};

intwin(intn,intm)

structstudent*p,*p1,*p2,*head;

p=(structstudent*)malloc(LEN);

head=p;

i++)//建立链表

p->

num=i+1;

p1=p;

p=(structstudent*)malloc(LEN);

p1->

next=p;

next=head;

p1=head;

while(p1->

=p1)//开始删除元素

i=1;

p1=p;

i=i+1;

while(i!

=m);

p2=p1;

p2->

next=p->

p=p->

return(p1->

num);

intN,m,num;

pleaseinputN,m:

N,&

num=win(N,m);

thewinnerisNO.%d."

num);

5.工资单处理

(1)编写函数:

有两个单向链表,头指针分别为list1、list2,链表中每一结点包含员工号(员工号为关键字段,不重复)、姓名、工资基本信息,请编一函数,把两个链表拼组成一个链表,并返回拼组后的新链表,按员工号升序排列。

(2)编写函数:

利用指针数组,实现按照工资进行升序排列的功能。

返回排序完成的指针数组

(3)编写一程序,分别输出按员工号排序后的新链表,以及按照工资排序的结果。

假设链表list1初始化内容为:

{002,name002,3000},{005,name005,2500},{003,name003,3500}

链表list2初始化内容为:

{006,name006,2800},{004,name004,3700},{001,name001,3000},{007,name007,3600},

structstaff

charnum[5];

charname[10];

intwages;

structstaff*next;

}a3={"

003"

"

name003"

3500,NULL},a2={"

005"

name005"

2500,&

a3},a1={"

002"

name002"

3000,&

a2},

b4={"

007"

name007"

3600,NULL},b3={"

001"

name001"

b4},b2={"

004"

name004"

3700,&

b3},b1={"

006"

name006"

2800,&

b2};

structstaff*rank_num(structstaff*list1,structstaff*list2)

structstaff*head,*p1,*p2,*p3,*p4;

head=NULL;

p1=list1;

p4=p1;

while(p4!

{/*老师,我在这题的想法是把它一个一个卸下来然后按顺序装到另一个头指针后,但是感觉这样拆开很麻烦,尤其是我在插入的时候需要定义四个指针,做着做着就乱了,有什么更好的办法吗?

*/

if(head==NULL){head=p1;

p2=p1;

p2->

while(strcmp(p1->

num,p2->

num)>

0&

p3=p2;

p4=p1;

if(strcmp(p1->

num)<

p2!

if(head==p2)head=p1;

elsep3->

p4=p1->

p1=p4;

else

p2->

p1=list2;

p4=list2;

while(p4!

p2=head;

structstaff*rank_pay(structstaff*head)

structstaff*p1,*p2,*p3,*p4,*head2;

head2=NULL;

while(p1!

p2=head2;

if(head2==NULL){head2=p1;

while((p1->

wages>

wages)&

if(p1->

wages<

wages&

if(head2==p2)head2=p1;

return(head2);

voidprint(structstaff*p)

therank:

while(p!

printf("

%s,%s,%d\n"

wages);

structstaff*list1,*list2,*head,*p;

list1=&

a1;

list2=&

b1;

head=rank_num(list1,list2);

print(p);

p=rank_pay(head);

6.单向链表练习

设节点结构:

学号

姓名

后继结点指针

链表结构:

编程。

要求程序实现如下功能:

a)链表生成。

键盘输入学生信息,建立一个节点按学号递增有序的单链表A={a1,a2,..,an},比如包含5~10条记录;

//假设输入的学号依次为2010002,2010005,2010009,2010007,2010003,2010000,姓名自己随便定义

b)节点计数。

对单链表A={a1,a2,..,an}编写节点计数函数f,求单链表中的节点个数。

主函数调用节点计数函数f,并将其返回值(整数)显示到屏幕;

c)对单链表A={a1,a2,..,an}编写函数fv,将它倒序为A={an,an-1,..,a1};

d)编写输出单链表函数list。

每次操作(插入一个新节点或者倒序)之后,调用函数list,在屏幕上显示链表的全部记录数据。

e)编写一个函数search,输入学号,检索链表A,如果指定学号记录存在则返回指向该节点的指针,主函数打印纪录信息。

若学生纪录不存在,则返回空指针,主函数给出检索失败的信息。

charname[20];

structstudent*create()

structstudent*p1,*p2,*p3,*p4,*head;

p1=(structstudent*)malloc(LEN);

head=p1;

pleaseinputthetotalnumberofstudent:

pleaseinputtheinformationofstudent:

%d,%s"

num,p1->

name);

p3=head;

while(p1->

num>

p3->

num&

{p4=p3;

p3=p3->

if(p1->

num<

num)

if(head==p3)head=p1;

elsep4->

p1->

next=p3;

else{p3->

next=N

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

当前位置:首页 > 求职职场 > 简历

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

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