C ++中的评分系统 [英] Grading system in C++

查看:147
本文介绍了C ++中的评分系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是我的C ++问题:

So this is my C++ question :

Write a program that translates a letter grade into a number grade. Letter grades are
A, B, C, D and F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1 and
0. There is no F+ or F-. A + increases the numeric value by 0.3, a – decreases it by
0.3. However, an A+ has value 4.0.
        Enter a letter grade: B
        The numeric value is 2.7

是我的代码:

    int main ()
    {
char grade;
int value;
cout << "Enter letter grade : " ;
cin >> grade;

switch(grade)
{
case 'A' : value = 4;
    break;
case 'B' : value =  3;
    break;
case 'C' : value = 2;
    break;
case 'D' : value = 1;
    break;
case 'E' : value = 0;
    break;
default : cout << "Wrong input " << endl;
    break;
}

cout << value;
system("PAUSE");
return 0;

    }

它能够打印出4表示A,3表示B等等。但是,这个问题需要我们计算+和 - 。我应该使用if else语句后切换?

It able to print out 4 for A, 3 for B and so on. But however, the question required us to make calculation for the + and - also. Am I supposed to use if else statement after the switch?

任何帮助将不胜感激。提前感谢。

Any help would be appreciated. Thanks in advance.

推荐答案

如果输入为 A + c $ c> B - ,那么它不再是字符了。所以,使用一个字符串的字符串,并检查值。

If the input is A+ or B-, then it is not a character anymore. So, get it using a string of chars, and check the values.

char a[3];
float m,n;
cin>>a;
if(a[1]=='+')
   m=0.3;
else if (a[1]=='-')
   m=-0.3;
else
    m=0;
switch(a[0])
{
  //Assign the value of n as 4,3,2,1 depending upon the grade.
}
cout<<n+m;

将打印成绩

这篇关于C ++中的评分系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆