返回列表 發帖

陣列 (七) - 成績表 (二)

本帖最後由 tonyh 於 2014-1-18 17:44 編輯

新宣告一維陣列, 以用來插入姓名欄位, 如下圖所示.
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[5]={"王大明","李大頭","蘇小安","余美美","張醜醜"};
  7.     float score[5][3]={{90,85,85},
  8.                        {70,75,80},
  9.                        {80,95,80},
  10.                        {70,95,75},
  11.                        {80,85,95}};
  12.     cout<<"座號\t姓名\t\t國文\t英文\t數學\t"<<endl;
  13.     cout<<"============================================"<<endl;
  14.     for(int i=0; i<=4; i++)
  15.     {
  16.         cout<<i+1<<"\t"<<name[i]<<"\t\t";
  17.         for(int j=0; j<=2; j++)
  18.         {
  19.             cout<<score[i][j]<<"\t";   
  20.         }     
  21.         cout<<endl;
  22.     }
  23.     system("pause");
  24.     return 0;   
  25. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int score[5][3]={{85,80,75},
  7.                      {90,85,88},
  8.                      {95,97,98},
  9.                      {75,85,77},
  10.                      {84,75,70}};
  11.     string name[5]={"王大明","李大頭","蘇小安","余美美","張醜醜"};
  12.     cout<<"座號\t姓名\t\t國文\t英文\t數學\t"<<endl;
  13.     cout<<"============================================"<<endl;               
  14.     for(int i=0;i<=4;i++)
  15.     {
  16.          cout<<i+1<<"\t"<<name[i]<<"\t\t";
  17.          for(int j=0;j<=2;j++)  
  18.          {
  19.             cout<<score[i][j]<<"\t";
  20.          }
  21.          cout<<endl;
  22.     }
  23.     cout<<endl;                        
  24.     system("pause");
  25.     return 0;   
  26. }
複製代碼

TOP

本帖最後由 張峻瑋 於 2014-1-18 17:41 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[5]={"王大明","李大頭","蘇小安","余美美","張醜醜"};
  7.     int a[5][3]={{ 90 , 95 , 80 },
  8.                     { 80 , 70 , 90 },
  9.                     { 90 , 85 , 90 },
  10.                     { 95 , 95 , 80 },
  11.                     { 80 , 90 , 90 }};
  12.     cout<<"座號\t姓名\t\t國文\t英文\t數學\t"<<endl;
  13.     cout<<"============================================"<<endl;               
  14.     for(int i=0;i<=4;i++)
  15.     {
  16.         cout<<i+1<<"\t";
  17.         cout<<name[i]<<"\t\t";     
  18.         for(int j=0;j<=2;j++)  
  19.         {
  20.             cout<<a[i][j]<<"\t";
  21.         }
  22.         cout<<endl;
  23.     }                        
  24.     system("pause");
  25.     return 0;   
  26. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. string name[5]={"黑子","紫原","赤司","綠間","黃瀨"};   
  7. float score [5][3]={{90,95,85},
  8.                      {89,95,92},
  9.                      {89,95,92},
  10.                      {89,95,92},  
  11.                      {89,95,92}};
  12.     cout<<"座號\t姓名\t\t國文\t英文\t數學\t"<<endl;
  13.     cout<<"============================================="<<endl;              
  14.     for(int i=0;i<=4;i++)
  15.     {
  16.      cout<<i+1<<"\t"<<name[i]<<"\t"<<"\t";        
  17.      for(int j=0;j<=2;j++)
  18.      {
  19.      cout<<score[i][j]<<"\t";               
  20.      }
  21.      cout<<endl;      
  22.     }                           
  23.    
  24.    
  25.    
  26. system("pause");   
  27. return 0;   
  28. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.   float a[5][3]={{100,100,100},
  7.                  {100,100,100},         
  8.                  {100,100,100},
  9.                  {100,100,100},         
  10.                  {100,100,100}};
  11.   string n[5]={"王大明","李大頭","蘇小安","余美美","張醜醜"};
  12.   cout<<"Number \tName\t\tChinese\tEnglish\tMath\t"<<endl;
  13.   cout<<"----------------------------------------------"<<endl;
  14.   for(int i=0; i<=4; i++)
  15.   {
  16.          cout<<i+1<<"\t"<<n[i]<<"\t\t";
  17.          for(int j=0; j<=2 ;j++)  
  18.           {
  19.                   cout<<a[i][j]<<"\t";
  20.           }
  21.           cout<<endl;
  22.   }              
  23.   system ("pause");   
  24.   return 0;
  25. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<iostream>
  3. #include<cstdlib>
  4. using namespace std;
  5. int main()
  6. {
  7.     string name[5]={"王大明","李大頭","蘇小安","余美美","張醜醜"};
  8.     float score[5][3]={{96,92,91},
  9.                        {94,98,92},   
  10.                        {97,85,89},         
  11.                        {97,95,91},            
  12.                        {85,94,97}};            
  13.     cout<<"座號\t姓名\t\t國文\t英文\t數學\t"<<endl;
  14.     cout<<"============================================"<<endl;
  15.     for(int i=0;i<=4;i++)
  16.     {
  17.          cout<<i+1<<"\t"<<name[i]<<"\t\t";
  18.          for(int j=0;j<=2;j++)   
  19.          {
  20.                  cout<<score[i][j]<<"\t";
  21.          }
  22.          cout<<endl;   
  23.     }
  24.     system ("pause");
  25.     return 0;
  26. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.   float a[5][4]={{100,100,100,0},
  7.                  {100,100,100,0},         
  8.                  {100,100,100,0},
  9.                  {100,100,100,0},         
  10.                  {100,100,100,0}};
  11.   string n[5]={"王大明","李大頭","蘇小安","余美美","張醜醜"};
  12.   cout<<"Number\tName\t\tChinese\tEnglish\tMath\tAvarage\t"<<endl;
  13.   cout<<"-------------------------------------------------------"<<endl;
  14.   for(int i=0; i<=4; i++)
  15.   {
  16.           a[i][3]=(a[i][0]+a[i][1]+a[i][2])/3;
  17.          cout<<i+1<<"\t"<<n[i]<<"\t\t";
  18.          for(int j=0; j<=3;j++)  
  19.           {
  20.                   cout<<a[i][j]<<"\t";
  21.           }
  22.           cout<<endl;
  23.          
  24.   }              
  25.   system ("pause");   
  26.   return 0;
  27. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     string name[5]={"王大明","李大頭","蘇小安","余美美","張醜醜"};
  7.     float score[5][3]={{90,98,89},
  8.                                  {76,83,85},
  9.                                  {91,87,94},
  10.                                  {76,82,78},
  11.                                  {91,86,95}};
  12.     cout<<"座號\t姓名\t\t國文\t英文\t數學\t"<<endl;
  13.     cout<<"============================================"<<endl;
  14.     for(int i=0; i<=4; i++)
  15.     {      
  16.             cout<<i+1<<"\t"<<name[i]<<"\t\t";
  17.             for(int j=0; j<=2; j++)  
  18.             {
  19.                  cout<<score[i][j]<<"\t";
  20.             }        
  21.             cout<<endl;
  22.     }
  23.     system("pause");
  24.     return 0;
  25. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[5]={"王小明","大張郎","王小安","邱裕仁","張好醜"};
  7.     float score[5][3]={{97,85,85},
  8.                        {74,78,83},
  9.                        {81,95,81},
  10.                        {79,97,75},
  11.                        {87,85,95}};
  12.     cout<<"座號\t姓名\t\t國文\t英文\t數學\t"<<endl;
  13.     cout<<"============================================"<<endl;
  14.     for(int i=0; i<=4; i++)
  15.     {
  16.         cout<<i+1<<"\t"<<name[i]<<"\t\t";
  17.         for(int j=0; j<=2; j++)
  18.         {
  19.             cout<<score[i][j]<<"\t";   
  20.         }     
  21.         cout<<endl;
  22.     }
  23.     system("pause");
  24.     return 0;   
  25. }
複製代碼

TOP

返回列表