void main() { int N,sum=0; cout<<\请确定数组大小N的值:\ cin>>N; int *p = new int[N]; cout<<\请输入N个整数到数组p[N]中:\ for(int i=0;i 第五题: #include typedef struct Node { int data; Node *next; } *LinkList; LinkList CreateList(LinkList &L,int n) { LinkList p = NULL; LinkList temp = NULL; int data; cout << \请任意输入n个正整数:\ cin >> data; while (n > 0) { p = new struct Node; p->data = data; p->next = NULL; if (!L) L = temp = p; else { temp->next = p; temp = p; } cin >> data; n--; } return L; } int PrintList(LinkList L) { LinkList p = L; cout << \链表的全部数据如下:\ while (p) { cout << p->data << \ p = p->next; } cout << endl; return 0; } void freeLink(LinkList L) { LinkList p = NULL; while (L) { p = L; p->next = NULL; L = L->next; delete p; } } void main() { LinkList L = NULL; L = CreateList(L,3); //输入链表数据 PrintList( L ); //输出链表数据 freeLink( L ); //释放单链表的头指针 } 第六题: (1) 修改前的程序: include cin>>x; //使用x之前应先申明x的内型 int y=x*x; cout<<\//引号的位置错误,应改为\,且换行应该使用endl return 0; //main函数定义为void类型,因此不应该有返回值,故去掉这句话。 } 修改后的程序: #include 修改前的程序: #include int a,b; //整个过程中b都没有赋值,因此a+b为一个不确定的数。 a=7; int s=a+b; cout<<\} 修改后的程序: #include b=0; int s=a+b; cout<<\} 第七题: (1) #include //由于引用与其所引用的变量的值永远保持相同。故rdd+rde=dd+de=3.9+1.3=5.2 //因此输出为:5.2,5.2 cout< #include void fun(int m,int &n) { n=m*4; } (3) #include void main() { int a=5; for(int i=0;i<5;i++) //通过for循环,调用函数fun();为其建立引用,对数组aa[5]分别赋值 fun(i)=a+i; for(i=0;i<5;i++) //通过for循环,分别输出显示数组aa[5]的值:5 6 7 8 9 cout< int &fun(int a) { return aa[a]; } 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库实验一 C++基础练习(附答案)(2)在线全文阅读。
相关推荐: