文档介绍:软件设计师模拟题第一套
●试题一
阅读下列说明和数据流图,回答问题 1~问题 3。
【说明】
某考务处理系统主要功能是考生管理和成绩管理:
对考生送来的报名表进行检查。
对合格的报名表编好准考
【程序说明】
定义一个多边形结构: struct polygon 实现以下内容: (1) 建立该结
构的链表: create 函数是创建链表,每输入一个结点的数据,就把该结点加入
到链表当中,它返回创建的链表的头指针。 (2) 显示链表的各个结点数据:结
点数据包括:多边形顶点数、各顶点的纵横坐标、当多边形顶点数为 0时,链表创建结束。 (3) 编写一个函数 disp ,删除链表中的所有结点。需要注意的是:要先释放结点数据内存,再删除结点,如果在释放结点数据内存单元之前删除结点,则无法找到结点数据内存单元的地址,也就无法释放数据的内存单元。
【程序】
#include""
#include""
struct polygon
{
int n;
int *x;
int *y;
polygon *next;
};
void Push(polygon*& head , int n)
{
polygon*newNode=new polygon;
newNode=new polygon;
newNode->next= (1) ;
newNode->x=new int[n]; newNode->y=new int[n];
newNode->n=
(2) ;
for(int i=0;i<= (3) ;i++){
cout<<" 请输入多边形各顶点 x、y坐标,坐标值之间用空格分隔: ";
cin>>newNode->x[i]>>newNode->y[i]; }
=head;//在 head前不需要额外的 * head=newNode;
}
polygon *create()
{
polygon*head=NULL;
polygon*tail;
int n;
cout<<" 请输入多边形顶点的个数 ( 顶点个数为 0时结束 ) :";
cin>>n;
if(n==0)return (5) ;
Push(head, (6) ;
tail=head;
cout<<" 请输入多边形顶点的个数 ( 顶点个数为 0时结束 ) :";
cin>>n;
while(n!=0)
{
Push(tail->next , (7) ;// 在tail->next 增加结点
tail=tail->next;//advance tail to point to last node
cout<<" 请输入多边形顶点的个数 ( 顶点个数为 0时结束 ) :";
cin>>n;
}
return head;
}
void disp(polygon*head)
{
int i ,No=1;
cout<<
while(head!=NULL)
{
cout<<" 第"<<no<<" 结点: "<<endl;< p="">
for(i=0;i<=head->n-1;i++)
cout<<x[i]<<y[i]<<endl;< p="">
;
head= (9) ;
}//Match while statement
}
void del(polygon*head)
{
polygon*p;
while(head!=NULL)
{
p= (10) ; head=head->next; delete p->x; delete P->y; deletep;
}//Match while statement
}
void main()
{
polygon*head;
head=create();
disp(head);
del(head);
}
●试题五
阅读下列程序说明,将应填入 (n)