少妇AV一区二区三区无|久久AV电影一区三|日本一级片黄色毛片|亚洲久久成人av在线久操|黄色视频在线免费看呀一区二区|综合精品视频精品久久久浪朝|亚洲午夜成人资源|欧美黄色一级片黑寡妇|内射无毛少妇特写|无码农村夜晚偷拍啪啪

2016年計算機軟件設計師程序模擬題

時間:2016-06-27 16:29:00   來源:無憂考網     [字體: ]
●試題四

  閱讀下列程序說明,將在空缺處填入正確的內容。

  【程序說明】

  定義一個多邊形結構:struct polygon實現以下內容: (1) 建立該結構的鏈表:create函數是創(chuàng)建鏈表,每輸入一個結點的數據,就把該結點加入到鏈表當中,它返回創(chuàng)建的鏈表的頭指針。 (2) 顯示鏈表的各個結點數據:結點數據包括:多邊形頂點數、各頂點的縱橫坐標、當多邊形頂點數為0時,鏈表創(chuàng)建結束。 (3) 編寫一個函數disp,刪除鏈表中的所有結點。需要注意的是:要先釋放結點數據內存,再刪除結點,如果在釋放結點數據內存單元之前刪除結點,則無法找到結點數據內存單元的地址,也就無法釋放數據的內存單元。

  【程序】

  #include"iostream.h"

  #include"iomanip.h"

  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];}

  (4) =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<<"第"<

  for(i=0;i<=head->n-1;i++)

  cout

  (8) ;

  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);

  }