List of all available Websheets
Viewing cpp/control/letter_grade by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | This program will ALWAYS take a non-negative integer between 70-100 as input from the keyboard. It will then print out the letter grade corresponding to the score according to the breakdown: <ul> <li>for input <tt>97-100</tt> it should output <tt>A+</tt> <li>for input <tt>94-96</tt> it should output <tt>A</tt> <li>for input <tt>90-93</tt> it should output <tt>A-</tt> <li>for input <tt>87-89</tt> it should output <tt>B+</tt> <li>for input <tt>84-86</tt> it should output <tt>B</tt> <li>for input <tt>80-83</tt> it should output <tt>B-</tt> <li>for input <tt>77-79</tt> it should output <tt>C+</tt> <li>for input <tt>74-76</tt> it should output <tt>C</tt> <li>for input <tt>70-73</tt> it should output <tt>C-</tt> <li>for input <tt>67-69</tt> it should output <tt>D+</tt> <li>for input <tt>64-66</tt> it should output <tt>D</tt> <li>for input <tt>60-63</tt> it should output <tt>D-</tt> </ul> (Don't worry about <tt>F</tt>s. (You shouldn't get one as long as you try), or any other input value. We will always give you an input in the range 70-100.) <p>We have used MANY if..else if...else if... statements. But consider the structure of the desired output. <strong>Can you break it into two sequential steps to produce the desired output using less <tt>if</tt> statements</strong>? <p>Also do you need compound conditions in all cases (i.e. <tt>cond1 && cond2</tt> or <tt>cond1 || cond2</tt>) to check your ranges or can you take advantage of the if...else if... sequencing in several cases? |
Public permissions | |
Remarks Comments, history, license, etc. | Copied from problem cpp/control/nth (author: daveagp@gmail.com) |
Engine | |
Template / Reference solution |
using namespace std; int main() { int s; // score cin >> s; \[ if (s >= 90) cout << "A"; else if (s >= 80) cout << "B"; else if (s >= 70) cout << "C"; else cout << "D"; if( s%10 >= 7 || s == 100) cout << "+" << endl; else if( s%10 <= 3) cout << "-" << endl; \show: if(s >= 97 && s <= 100) { cout << "A+" << endl; } else if(s >= 94 && s < 97) { cout << "A" << endl; } else if(s >= 90 && s < 94) { cout << "A-" << endl; } else if(s >= 87 && s < 90) { cout << "B+" << endl; } else if(s >= 84 && s < 87) { cout << "B" << endl; } else if(s >= 80 && s < 84) { cout << "B-" << endl; } else if(s >= 77 && s < 80) { cout << "C+" << endl; } else if(s >= 74 && s < 77) { cout << "C" << endl; } else if(s >= 70 && s < 74) { cout << "C-" << endl; } else if(s >= 67 && s < 70) { cout << "D+" << endl; } else if(s >= 64 && s < 67) { cout << "D" << endl; } else { cout << "D-" << endl; } ]\ return 0; } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [ {"stdin": "100"}, {"stdin": "99"}, {"stdin": "97"}, {"stdin": "96"}, {"stdin": "94"}, {"stdin": "93"}, {"stdin": "90"}, {"stdin": "89"}, {"stdin": "87"}, {"stdin": "86"}, {"stdin": "84"}, {"stdin": "83"}, {"stdin": "80"}, {"stdin": "79"}, {"stdin": "66"}, {"stdin": "64"}, {"stdin": "63"} ] |
Solution visibility |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.