[問題] enum的用法
它是要我們使用enum控制是否使用Bubblesort排序成績
可是我寫出來的程式卻一直都run不出來
不知道是哪邊有問題了
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
using namespace std;
enum menu{a,b};
struct student
{
char stu_id[12];
int ScoreComputer;
int ScoreMath;
int ScoreEng;
float ScoreAvg;
unsigned short int s1:1;
};
void display(struct student);
void BubbleSort(struct student *arr,int arr_index);
void display(struct student tempStu)
{
cout << tempStu.stu_id << "\t" << tempStu.ScoreComputer << "\t" \
<< tempStu.ScoreMath << "\t" << tempStu.ScoreEng << "\t";
cout << setprecision(4) << tempStu.ScoreAvg << endl;
}
void BubbleSort(struct student *arr,int arr_index)
{
int k,times,i;
struct student temp;
k=arr_index-1;
while(k!=0)
{
times=0;
for(i=0;i<=k-1;i++)
{
if(arr[i].ScoreEng<arr[i+1].ScoreEng)
{
temp=arr[i]; arr[i]=arr[i+1]; arr[i+1]=temp; // arr[i]與arr[i+1]互換
times=i;
}
}
k=times;
}
}
int main(void)
{
int score[3][3]={{89,84,75},
{77,69,87},
{65,68,77}};
struct student IM[3],tempStu;
int i,Total;
strcpy(IM[0].stu_id,"D9412345");
strcpy(IM[1].stu_id,"D9423456");
strcpy(IM[2].stu_id,"S9434567");
for(i=0;i<3;i++)
{
Total=0;
IM[i].ScoreComputer=score[i][0];
IM[i].ScoreMath =score[i][1];
IM[i].ScoreEng =score[i][2];
Total=score[i][0]+score[i][1]+score[i][2];
IM[i].ScoreAvg=((float)Total)/3;
}
struct student POWER;
enum menu qq;
cout << "請輸入是否使用Bubblesort進行排序(否:a;是:b):" << "\n";
int qq;
cin >>qq;
switch(qq)
{
case 0:
cout << "不轉換" << endl;
cout << "學號\t\t計概\t數學\t英文\t平均" << endl;
cout << "------------------------------------------------" << endl;
for(i=0;i<3;i++)
display(IM[i]);
break;
case 1:
cout << "轉換" << endl;
cout << "學號\t\t計概\t數學\t英文\t平均\t(依計概排序前)" << endl;
cout << "---------------------------------------------------" << endl;
for(i=0;i<3;i++)
display(IM[i]);
BubbleSort(IM,3);
cout << "學號\t\t計概\t數學\t英文\t平均\t(依計概排序後)" << endl;
cout << "---------------------------------------------------" << endl;
for(i=0;i<3;i++)
display(IM[i]);
break;
}
system("pause");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.222.24.229
推
04/13 12:51, , 1F
04/13 12:51, 1F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章
-4
30