5-5
#include<iostream>
#include<string>
using namespace std;
int main()
{
string table[] = {
"F", "D", "C", "B", "A", "A++"};
int grade;
string level;
cout << "please input your grade:";
cin >> grade;
cout << endl;
if (grade < 0 or grade > 100) {
cout << "illegal!" << endl;
system("pause");
return -1;
}
if (grade == 100) {
level = table[size(table) - 1];
cout << level << endl;
system("pause");
return 0;
}
if (grade < 60) {
level = table[0];
cout << level << endl;
system("pause");
return 0;
}
level = table[(grade - 50) / 10];
if (grade % 10 < 3) {
level = "-" + level;
}
else if (grade % 10 > 7) {
level = "+" + level;
}
cout << level << endl;
system("pause");
}
5-6
#include<iostream>
#include<string>
using namespace std;
int main()
{
string table[] = {
"F", "D", "C", "B", "A", "A++" };
int grade;
string level;
cout << "please input your grade:";
cin >> grade;
cout << endl;
if (grade < 0 or grade > 100) {
cout << "illegal" << endl;
}
if (grade == 100) {
level = table[size(table) - 1];
cout << level << endl;
system("pause");
return 0;
}
if (grade < 60) {
level = table[0];
cout << level << endl;
system("pause");
return 0;
}
int i = grade % 10;
int j = grade / 10;
level = (i == 6) ? table[1]
: (i == 7) ? table[2]
: (i == 8) ? table[3] : table[4];
//cout << level << endl;
level = ((j <= 2) ? "-"
: (j >= 8) ? "+" : " ") + level;
cout << level << endl;
system("pause");
}
5-9
#include<iostream>
#include<string>
using namespace std;
int main()
{
int opt = 1;
string s;
int acnt = 0, ecnt = 0, icnt = 0, ocnt = 0, ucnt = 0, others = 0;
while (opt) {
cout << "input some text:" << endl;
getline(cin, s);
for (auto i : s) {
switch (i) {
case 'a'