Exercises and Sample Questions (Set I) 1.) Write an if decision statement that will check if a number is even. 2.) In a quadratic equation ax2 + bx + c = 0, the quantity b2 – 4ac is called the discriminant and is used to determine the type of solutions of the equation. Write a valid C statement (only the mathematical statement is necessary) that computes the discriminant and assigns it to the variable D. 3.) Write a decision statement(s) that will display the message “x is larger than y and positive” if x is both greater than y and positive. 4.) What is the output? int i = 4; if ( i == 1 ) cout << "Code red" << endl; if ( i == 2 ) cout << "Code yello" << endl; if ( i == 3 ) cout << "Code blue" << endl; else cout << "Code undefined" << endl; 5.) What is the output? int i = 1; if ( i == 1 ) cout << "Code red" << endl; if ( i == 2 ) cout << "Code yello" << endl; if ( i == 3 ) cout << "Code blue" << endl; else cout << "Code undefined" << endl; 6.) What is the output? int x = 4; while ( x >= 1) { x = x - 2; cout << "x = " << x << endl; } 7.) Given the following if statements: if ( Score == 'A') if ( Difficulty >= 7.0) TotalScore = 4.0 * Difficulty; a.) What type of variables (data type) should Score, Difficulty, and TotalScore be, respectively? b.) Write an equivalent compound if. 8.) Given the following switch statement in the code segment: int answer; cin >> answer; switch (answer) { case 5: cout << "The answer is 5"; break; case 10: cout << "The answer is 10"; break; case 15: cout << "The answer is 15"; break; default: cout << "Invalid input"; break; } Convert the switch statement and all its cases to an equivalent if construct.