云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 教材练习题参考答案

教材练习题参考答案

  • 62 次阅读
  • 3 次下载
  • 2025/12/10 21:38:50

cout<

2.[程序如下]

# include # include struct score {

char name[8] ; int no ;

float c, english, maths, average ; } ;

score input(score st) ;

float average( float a, float b, float c ) ; void sort(score st[], int n) ; void print (score st[], int n) ; void main() {

score student[30] ;

for (int i=0 ; i<5 ; i++) student[i]=input(student[i]) ; sort(student, 5) ; print(student, 5) ; }

score input(score st) {

cout<<\请输入学生姓名:\ cin>>st.name ; cout<<\请输入学生学号:\ cin>>st.no ; cout<<\请输入C++成绩:\ cin>>st.c ;

cout<<\请输入英语成绩:\ cin>>st.english ; cout<<\请输入数学成绩:\ cin>>st.maths ; cout<

st.average=average(st.c, st.english, st.maths) ; return st ; }

float average( float a, float b, float c ) { return (a+b+c)/3 ; }

void sort(score st[], int n) { score temp ;

for ( int i=0 ; i

} void print (score st[], int n) {

cout<<\\ 姓名 \ 平均 \ C++ \ 英语 \ 数学 \ for ( int i=0 ; i

cout<<'\\t'<

cout<<'\\t'<

cout<<'\\t'<

3.[程序如下]#include struct student { long int num; float CPPmid; float CPPend; float ave; };

void main() {student s[3]; student *p; for(p=s;p

cout<<\请输入学生学号:\ cin>>p->num; cout<<\请输入C++期中成绩:\ cin>>p->CPPmid; cout<<\请输入C++期末成绩:\ cin>>p->CPPend; p->ave=(p->CPPmid+p->CPPend)/2; } cout<<\ 平均 \ C++期中 \期末 \ for(p=s;pnum ; cout<<'\\t'<ave;

cout<<'\\t'<CPPmid ; cout<<'\\t'<CPPend; cout<

} }

4.[程序如下] struct link {

int data; link*next; };

int sum(link *head) { link *p; int s=0; p=head->next; while(p) { s+=p->data; p=p->next; return s; } }

5.[程序如下] #include struct node {

int data;

node *next; };

node *create( ) {

node *head ; //头指针

node *p , *pend ; int a;

cout<<\请输入数据(为零表示结束输入):\ cin>>a; head=0 ; while(a!=0) {

p=new node ;

p->data=a ; if(head==0) {

head=p ; pend=p ;

}

else { pend->next=p ;

pend=p ;

}

cout<<\请输入数据(为零表示结束输入):\ cin>>a;

}

if(head) pend->next=0 ; return head ; }

node * invert(node *head) { node *p,*q; p=head->next; if(p!=NULL) {

head->next=NULL;

do { q=p->next; p->next=head; head=p; p=q;; }while(p!=NULL);

} return head; }

void print(node *head ) {

if(head==0) { cout<<\链表为空!\\n\ return ; } node *p=head ;

cout<<\链表上各个结点的值为:\\n\

while(p!=0) { cout < data<<'\\t' ; p=p->next ; } }

void release(node *head ) {

if(head==0) { cout<<\链表为空!\\n\ return ; node *p ; while( head )

{ p=head;

head=head->next ;

delete p; }

cout<<\结点空间释放完毕!\

}

搜索更多关于: 教材练习题参考答案 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

cout<

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com