<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. C語言的基礎練習

    時間:2025-10-25 22:41:09 C語言

    C語言的基礎練習

      一、實驗目的

      對C語言的復習,增強學生對結構體數組和指針的學習,尤以結構體的應用和指針的操作作為重點。

      二、問題描述

      1、 構造一個學生結構體,成員包括學號,姓名,四門成績,以及平均成績;

      2、 從鍵盤上輸入學生的學號,姓名和四門成績;

      3、 找出學生中考試沒有通過的學生姓名并輸出;找出考試在90分以上的學生并輸出。

      三、實驗要求

      1、 要求分別用數組和鏈表存儲學生的記錄,并設計出輸入和查找的基本操作算法。

      2、 在實驗過程中,分析算法的時間復雜度和空間復雜度進行分析。

      四、實驗環境

      PC微機

      DOS操作系統或 Windows 操作系統

      Turbo C 程序集成環境或 Visual C++ 程序集成環境

      五、實驗步驟

      1、用所選擇的語言實現算法;

      3、 測試程序,并對算法進行時間和空間復雜度分析。

      結構體數組方法及測試結果:

      #include

      using namespace std;

      struct student

      {

      int num;

      char name[20];

      float score[4];

      float ave;

      }; /pic/p>

      struct student stu[100];

      int main()

      cout<<"Please input the number:(0 is end)"; cin>>stu[0].num;

      i=0;

      while (stu[i].num)

      {

      cout<<"Please input the name:"; cin>>stu[;

      cout<<"Please input the scores:"; stu[i].ave-0;

      for (j=0;j<=3;j++)

      {

      cin>>stu[i].score[j];

      stu[i].ave+=stu[i].score[j];

      }

      stu[i].ave=stu[i].ave/4.0;

      i++;

      cout<<"Please input the number:(0 is end)"; cin>>stu[i].num;

      } n=i-1;

      k=m=0;

      for (i=0;i<=n;i++)

      {

      if (stu[i].ave>90)

      a[k++]=i; else

      {

      for (j=0;j<=3;j++)

      if (stu[i].score[j]<60)

      {

      b[m++]=i; goto loop;

      }

      } /pic/pic/pic/p>

      loop:; } /pic/p>

      { for (i=0;i<=k-1;i++) cout<<stu[a[i]].name<<" ";

      cout<<"is(are) 90 above."<<endl;

      }             /pic/p>

      for (i=0;i<=m-1;i++)

      } cout<<stu[b[i]].name<<" "; cout<<"did not pass the exam."<<endl; }             /pic/p>

      鏈表方法及測試結果:

      #include

      using namespace std;

      struct student

      {

      long num;

      char name[20];

      float score[4];

      float ave;

      struct student *next;

      };

      int main()

      {

      struct student *head,*p,*q;

      int number,k,j,m,i;

      char *a[100],*b[100];

      head=0;

      k=0;

      cout<<"input the number of student:"; cin>>number;

      while (number!=0)

      {

      k++;

      p=new student;

      p->num=number;

      cout<<"Please input the name:";   cin>>p->name;

      cout<<"Please input the scores:";   p->ave=0;

      for (j=0;j<=3;j++)

      {

      cin>>p->score[j];

      p->ave+=p->score[j];

      }

      p->ave=p->ave/4.0;

      if (k==1)

      head=p;

      else q->next=p;

      q=p;

      cout<<"Please input the number:(0 is end)";  cin>>number;

      }          p->next=0;

      p=head;

      k=m=0;

      while (p) /pic/p>

      {

      if (p->ave>90)

      a[k++]=p->name; else

      {

      for (j=0;j<=3;j++) if="" p-="">score[j]<60) {

      b[m++]=p->name;  goto loop;

      }

      }

      loop: p=p->next;

      }         if (k>0)

      {

      for (i=0;i<=k-1;i++)

      cout<<a[i]<<" ";

      cout<<"is(are) 90 above."<0)

      {

      for (i=0;i<=m-1;i++)

      cout<<b[i]<<" ";

      cout<<"did not pass the exam."<<endl; }        return 0;

      } /pic/pic/pic/p>

    【C語言的基礎練習】相關文章:

    C語言練習02-14

    c語言基礎習題11-22

    C語言編程基礎10-20

    C語言基礎常識09-15

    C語言程序基礎練習題帶答案12-24

    C語言作業練習10-02

    C語言練習試題07-20

    C 語言基礎教程10-03

    C語言基礎知識02-19

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人