SOGO論壇
  登入   註冊   找回密碼
查看: 1344|回覆: 0
列印 上一主題 下一主題

[程式設計] 設計"成績查詢系統" [複製連結]

Rank: 4

狀態︰ 離線
跳轉到指定樓層
1
發表於 2009-5-18 09:38:55 |只看該作者 |倒序瀏覽
這個程式搞了我好幾天了><
痘痘不知道冒了幾顆了
懇求大大們幫忙一下解決問題><!!!
我想睡覺阿Orz!

建置後出現三個錯誤:
(71) : error C2065: 'i' : 未宣告的識別項
(73) : error C2228: '.display' 的左邊必須有類別/結構/等位
(80) : error C2228: '.name' 的左邊必須有類別/結構/等位

一直在找始終找不到Orz

以下是我的程式:
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <string>
using namespace std;
class grade {
public:  
    string name, id;
    int chi, bcc, math, eng, tot;
    float avg;
    void set();         //用來設定資料成員的初值
    void display();     //輸出三科的成績
}; // end class grade
void grade::set() {    //由鍵盤輸入三科的成績放入資料成員
        cout << "  輸入學號:";
        cin >> id;        
        cout << "  輸入姓名:";
        cin >> name;
        cout << "  計概成績:";
        cin >> bcc;
        cout << "  數學成績:";
        cin >> math;
        cout << "  英文成績:";
        cin >> eng;
        cout << "  國文成績:";
        cin >> chi;
        avg=(float)(bcc+math+eng+chi)/4;
        tot=(bcc+math+eng+chi);
} // end grade::set()
void grade::display() {
        cout << " 學號:" << id;            
        cout << " 姓名:" << name;
        cout << " 國文:" << chi;
        cout << " 計概:" << bcc;
        cout << " 數學:" << math;
        cout << " 英文:" << eng ;
        cout << " 平均:" << avg;
} // end grade::display

void totsort(grade s[], int n) {
        int i, j;
        grade temp;
        for(i=n-1;i>=0;i--){
                for(j=0;j<=i;j++) {
                        if(s[j].tot < s[j+1].tot) {
                                temp=s[j];
                s[j]=s[j+1];
                s[j+1]=temp;
                        } // end if(s[j].tot < s[j+1].tot)
                } // end for(j=0;j<=i;j++)
        } // end for(i=n-2;i>=0;i--)
} // end totsort(grade s[], int n)
//-----------
int main(void) {
        grade my[4];          //宣告my是屬於grade類別的陣列,共有my[0]~my[3]
        for(int k=1;k<=3;k++){ //透過迴圈及set()成員函式由鍵盤輸入資料並放到資料成員中
                cout << "輸入第" << k << "位同學的成績" << endl;
                my[k-1].set();
        } // end main(void)
        cout << endl << "-----------------------------------------------\n\n";
        for(int i=1;i<=3;i++){ //透過迴圈及display()成員函式將資料成員輸出
                cout << endl << "第" << i << "位同學的成績-->" ;
                my[i-1].display();
        } // end for(int i=1;i<=3;i++)
        totsort(my, 3);
        cout <<  "\n\n依總分排序後...\n";
        for(i=1;i<=3;i++){ //透過迴圈及display()成員函式將資料成員輸出
                cout << endl << "第" << i << "名同學的成績-->" ;
                my[i-1].display();
        } // end for(int i=1;i<=3;i++)
        int f=3;
        string sname;
        cout << "\n\n請輸入欲尋找的學生姓名:";
        cin>>sname;
        for (i=0; i<3; i++) {
                if(my.name==sname) {
                        f=i;
                        break;
                } // end if(my.name==sname)
        } // end for (int i=0; i<4; i++)
        cout << endl <<endl;
        cout << sname << "的資料如下..." << endl;
        my[f].display();
        getch();
        return 0;
} // end main
喜歡嗎?分享這篇文章給親朋好友︰
               感謝作者     

請注意︰利用多帳號發表自問自答的業配文置入性行銷廣告者,將直接禁訪或刪除帳號及全部文章!
您需要登錄後才可以回覆 登入 | 註冊


本論壇為非營利自由討論平台,所有個人言論不代表本站立場。文章內容如有涉及侵權,請通知管理人員,將立即刪除相關文章資料。侵權申訴或移除要求:abuse@oursogo.com

GMT+8, 2024-4-27 05:23

© 2004-2024 SOGO論壇 OURSOGO.COM
回頂部