- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
[计算机软件及应用]C++程序设计题库182道含答案.doc
试卷编号:8172
所属语言:C++
试卷方案:题库182道设计题
试卷总分:1820分
共有题型:1种
一、程序设计 共182题 (共计1820分)
第1题 (10.0分) 题号:664
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:已知有结构体类型定义:
struct node
{ int data;
struct node *nextPtr;
};
请编写函数void computingList(node * head),对head
指向的单向链表,分别统计结点的data成员值为负数、0、
正数的结点个数分别存入变量negtive、zero、positive中。
-------------------------------------------------------
注意:部分源程序给出如下。请勿改动主函数main和其它函数中
的任何内容,仅在函数的花括号中填入所编写的若干语句。
-------------------------------------------------------*/
#include iostream
#include fstream
using namespace std;
void grading(int,int,int);
struct node
{
int data;
struct node *nextPtr;
};
void computingList(node * head)
{
int positive=0,negtive=0,zero=0;
/**********Program**********/
/********** End **********/
//忽略阅读
grading(positive,zero,negtive);
//忽略阅读结束
}
struct node *createList(void)
{
node *head=NULL, *p1, *p2;
int i;
int a[10] = {-1,3,4,0,9,4,11,-6,2,-10};
head=p2=p1= new node;
p1-data = a[0];
for (i=1; i10; i++)
{
p1= new node;
p1-data = a[i];
p2-nextPtr=p1;
p2=p1;
}
p2-nextPtr=NULL;
return (head);
}
int main()
{
struct node *head;
head = createList();
computingList(head);
return 0;
}
//以下忽略阅读
void grading(int a,int b,int c)
{
fstream myfile;
myfile.open(out.txt,ios::out);
myfilea b cendl;
myfile.close();
}
答案: struct node *p;
p=head;
while(p!=NULL)
{
if(p-data 0)
positive++;
else if (p-data 0)
negtive++;
else if (p-data == 0)
zero++;
p=p-nextPtr;
}
第2题 (10.0分) 题号:522
/*--------------------
您可能关注的文档
最近下载
- (高清版)DB13∕T 5769-2023 钢丝编织隔离栅应用技术导则.pdf VIP
- 和美乡村建设工程监理细则.docx VIP
- 和美乡村建设工程监理工作总结.docx VIP
- 生命体征生命体征测量.ppt VIP
- 2024年9月28日上海市浦东新区社区工作者考试《综合能力测验》真题及答案.docx VIP
- GBT 15781-2015 森林抚育规程.pdf
- (正式版)D-L∕T 448-2016 电能计量装置技术管理规程.docx VIP
- 第二章坐标系统和时间系统.ppt VIP
- 顺河场镇中心学校食堂环境卫生方案.doc VIP
- 【国家标准】GBT 20828-2015 柴油机燃料调和用生物柴油(BD100).pdf
文档评论(0)