#includeusingnamespacestd;intgrade_to_score(chargrade);//等級(jí)轉(zhuǎn)換成分?jǐn)?shù)charscore_to_grade(intscore);//分?jǐn)?shù)轉(zhuǎn)換成等級(jí)////// " />

亚洲国产综合久久香蕉|亚洲国产超清无码专区|av片在线观看无码免费|亚洲欧美另类精品久久久|人妻无码中文字幕一二三区|亚洲成av人在线观看网址|99久久久无码国产精品不卡|9191精品国产免费久久国语

關(guān)于C++的項(xiàng)目實(shí)訓(xùn)

農(nóng)機(jī)大全網(wǎng)(www.97661a.com)最新農(nóng)機(jī)信息:關(guān)于C++的項(xiàng)目實(shí)訓(xùn),農(nóng)機(jī)新產(chǎn)品,二手農(nóng)機(jī),農(nóng)機(jī)補(bǔ)貼目錄,農(nóng)機(jī)價(jià)格查詢,農(nóng)機(jī)報(bào)價(jià)大全,更多農(nóng)機(jī)資訊請(qǐng)查看:農(nóng)機(jī)資訊

  關(guān)于C++的項(xiàng)目實(shí)訓(xùn)

#include<iostream>
#include<string>
using namespace std;

int grade_to_score(char grade); //等級(jí)轉(zhuǎn)換成分?jǐn)?shù)
char score_to_grade(int score); //分?jǐn)?shù)轉(zhuǎn)換成等級(jí)
///////////////////////////////////////////////////////////////
/*
* 測試等級(jí)轉(zhuǎn)換成分?jǐn)?shù)函數(shù)的正確性
*/
//注釋測試代碼,為了方便,把所有的需求都下在這一個(gè)源文件中
//可以將其改成多文件結(jié)構(gòu)
/*
int main(){
char temp = 'A';
for(int i = 0; i < 6; i++){
cout << "The grade: " << temp << " the score: ";
cout << grade_to_score(temp) << endl;
temp++;
}
}
*/
//////////////////////////////////////////////////////////////
/*
* 等級(jí)轉(zhuǎn)換成分?jǐn)?shù)
*/
int grade_to_score(char grade){
switch(grade){
case 'A': case 'a': return 95;
case 'B': case 'b': return 85;
case 'C': case 'c': return 75;
case 'D': case 'd': return 65;
case 'E': case 'e': return 50;
default :
cout << "The grade error!" ;
return 0;
};
}
/*
* 分?jǐn)?shù)轉(zhuǎn)換成等級(jí)
*/
char score_to_grade(int score){
if(score < 0 || score > 100){
cout << "score error " << endl;
exit(0);
}
if(score >= 90) {
return 'A';
}else if( score >= 80){
return 'B';
}else if(score >= 70){
return 'C';
}else if(score >= 60){
return 'D';
}
return 'E';
}

///////////////////////////////////////////////////////////
/*
* 測試分?jǐn)?shù)轉(zhuǎn)換成等級(jí)的正確性
*/
/*
int main(){
for(int i = 10; i <= 100; i += 5){
cout << "The score: " << i << ", the grade ";
cout << score_to_grade(i) << endl;
}
}
*/
///////////////////////////////////////////////////////////

void my_main(){
int total = 0; //總分
int index = 0; //科目數(shù)
int average = 0; //平均分
string grade_in;
bool input_ok = false;
while(1){
cout << "============================================" << endl;
cout << "Enter the grades, end by ' -1 ' > ";
getline(cin,grade_in);
index = grade_in.find("-1", 0);
if(index < 0){ //未找到結(jié)束標(biāo)志 "-1"
cout << "Input has no end point, input again!" << endl;
continue;
}

for(int i = 0; i < index; i++){
char grade = grade_in[i];
//發(fā)現(xiàn)輸入有無效的等級(jí)標(biāo)志
if(grade > 101 || grade < 65 || grade >69 && grade <97){
cout << "Grade input error, your input the grade of < " << grade << " >"<< endl;
cout << "Input again please ! " << endl;
input_ok = true;
break;
}
total += grade_to_score(grade); //累加得到總分
}
if(input_ok){
total = 0; //總分歸零
continue;
}
break;
}

average = total/index; //求得平均分
cout << "average = " << average << endl;
cout << "The average grade: " << score_to_grade(average); //打印平均分等級(jí)
cout << endl;
}

int main(){
my_main();
}

/*
* 不知道是不是有點(diǎn)刁難,為什么要用-1作為結(jié)束符呢
* 等級(jí)轉(zhuǎn)換成分?jǐn)?shù)A->95,B->85,C->75,D->65,E->50, 這樣是不是有點(diǎn)牽強(qiáng)
* 不過就這樣的
*/

標(biāo)簽:in   等級(jí)

聲明:農(nóng)機(jī)大全所有(圖文、音視頻)均由用戶自行上傳分享,僅供網(wǎng)友學(xué)習(xí)交流,版權(quán)歸原作者。若您的權(quán)利被侵害,請(qǐng)聯(lián)系 56325386@qq.com 刪除。

載注明出處:http://www.97661a.com/news/186829.html