Question

In: Computer Science

// Lab Homework 11 // Logical Operator AND and OR // Demonstrate how to use a...

// Lab Homework 11
// Logical Operator AND and OR
// Demonstrate how to use a logical operator
// with a Boolean expression.

#include <iostream>
#include <cctype> // for tolower()
using namespace std;

int main()
{
   int numberOfCreditHours; // Number of credit hours student has completed
   float gpa; // The student's cumulative grade point average

   // Ask the user two questions:
   cout << "Answer the following questions:" << endl << endl;

   cout << "How many credit hours have you completed (0-200): ";
   cin >> numberOfCreditHours;

   cout << "What is your cumulative GPA (0.00-4.00)? ";
   cin >> gpa;

   cout << endl;

   // TODO: Students can petition for graduation if:
   // - they have completed 48+ credit hours
   // - they have a GPA of 2.0 or greater
   //
   // Use Logical operators in complex logical expressions to decide which of the following
   // four messages to print:
   //
   // 1) You may petition for graduation.
   // 2) You must raise your GPA before you can graduate.
   // 3) You must complete more credit hours before you can graduate.
   // 4) You must raise your GPA and complete more credits before graduating.
   //
   // Use just ONE of the logical operators below in the expression
   // to choose the approprate message. You MAY use the chosen operator
   //       more than once.
   //
   // Logical AND: &&
   // Logical OR: ||
   //
   // Note: Do NOT worry about situations where the user doesn't enter Y, y, N, or n

   // Use the if structure provided below.

   if // (<write a compound logic expression here for graduating>)
       //graduation message

   else if // (<write a compound logic expression here for too low gpa>)
       //raise gpa message

   else if // (<write a compound logic expression here for too few credits>)
       //complete more credits message

   else // else is good enough, no logic expression needed - it's the only other possibility
       // raise gpa and earn more credits message

   cout << endl << endl;

   return 0;
}

/* Sample interaction and output:

Test #1
==========================================
Answer the following questions:

How many credit hours have you completed (0-200): 60
What is your cumulative GPA (0.00-4.00)? 3.75

You may petition for graduation.

Press any key to continue . . .

Test #2
==========================================
Answer the following questions:

How many credit hours have you completed (0-200): 60
What is your cumulative GPA (0.00-4.00)? 1.99

You must raise your GPA before you can graduate.

Press any key to continue . . .

Test #3
==========================================
Answer the following questions:

How many credit hours have you completed (0-200): 47
What is your cumulative GPA (0.00-4.00)? 3.25

You must complete more credit hours before you can graduate.

Press any key to continue . . .

Test #4
==========================================
Answer the following questions:

How many credit hours have you completed (0-200): 45
What is your cumulative GPA (0.00-4.00)? 1.75

You must raise your GPA and complete more credits before graduating.

Press any key to continue . . .

*/

Solutions

Expert Solution

If you have any doubts, please give me comment...

// Lab Homework 11

// Logical Operator AND and OR

// Demonstrate how to use a logical operator

// with a Boolean expression.

#include <iostream>

#include <cctype> // for tolower()

using namespace std;

int main()

{

    int numberOfCreditHours; // Number of credit hours student has completed

    float gpa;               // The student's cumulative grade point average

    // Ask the user two questions:

    cout << "Answer the following questions:" << endl

         << endl;

    cout << "How many credit hours have you completed (0-200): ";

    cin >> numberOfCreditHours;

    cout << "What is your cumulative GPA (0.00-4.00)? ";

    cin >> gpa;

    cout << endl;

    // TODO: Students can petition for graduation if:

    // - they have completed 48+ credit hours

    // - they have a GPA of 2.0 or greater

    //

    // Use Logical operators in complex logical expressions to decide which of the following

    // four messages to print:

    //

    // 1) You may petition for graduation.

    // 2) You must raise your GPA before you can graduate.

    // 3) You must complete more credit hours before you can graduate.

    // 4) You must raise your GPA and complete more credits before graduating.

    //

    // Use just ONE of the logical operators below in the expression

    // to choose the approprate message. You MAY use the chosen operator

    //       more than once.

    //

    // Logical AND: &&

    // Logical OR: ||

    //

    // Note: Do NOT worry about situations where the user doesn't enter Y, y, N, or n

    // Use the if structure provided below.

    if (numberOfCreditHours > 48 && gpa >= 2.0) // (<write a compound logic expression here for graduating>)

        //graduation message

        cout << "You may petition for graduation." << endl;

    else if (numberOfCreditHours > 48 && gpa < 2.0) // (<write a compound logic expression here for too low gpa>)

        //raise gpa message

        cout << "You must raise your GPA before you can graduate." << endl;

    else if (numberOfCreditHours <= 48 && gpa > 2.0) // (<write a compound logic expression here for too few credits>)

        //complete more credits message

        cout << "You must complete more credit hours before you can graduate." << endl;

    else // else is good enough, no logic expression needed - it's the only other possibility

        // raise gpa and earn more credits message

        cout << "You must raise your GPA and complete more credits before graduating." << endl;

    cout << endl

         << endl;

    return 0;

}

nagarajuanagaraju-Vostro-3550:26092019$ g++ lab hw11.cpp nagarajuanagaraju-Vostro-3550:26092019$ ./a.out, Answer the following questions: How many credit hours have you completed (0-200): 60 What is your cumulative GPA (0.00-4.00)? 3.75 You may petition for graduation. nagarajuanagaraju-Vostro-3550:26092019$ ./a.out Answer the following questions: How many credit hours have you completed (0-200): 60, What is your cumulative GPA (0.00-4.00)? 1.99 You must raise your GPA before you can graduate. nagaraju@nagaraju-Vostro-3550:26092019$ /a.out, Answer the following questions: How many credit hours have you completed (0-200): 47 What is your cumulative GPA (0.00-4.00)? 3.25 You must complete more credit hours before you can graduate. nagarajuanagaraju-Vostro-3550:26092019$ ./a.out, Answer the following questions: How many credit hours have you completed (0-200): 45 What is your cumulative GPA (0.00-4.00)? 1.75 You must raise your GPA and complete more credits before graduating.


Related Solutions

In this lab assignment, students will demonstrate the abilities to: - Use functions in math module...
In this lab assignment, students will demonstrate the abilities to: - Use functions in math module - Generate random floating numbers - Select a random element from a sequence of elements - Select a random sample from a sequence of elements (Python Programming) NO BREAK STATEMENTS AND IF TRUE STATEMENTS PLEASE Help with the (create) of a program to play Blackjack. In this program, the user plays against the dealer. Please do the following. (a) Give the user two cards....
How Much Iron is in Total Cereal?        The following at home lab exercise will demonstrate...
How Much Iron is in Total Cereal?        The following at home lab exercise will demonstrate that iron is actually in iron fortified cereal such as Total.        Materials: 1 cup iron fortified cereal (Total) 2 cups of hot water (from the sink)   1 clear glass large enough to hold the cereal and the water. Magnet- The magnet can be from an inexpensive refrigerator magnet. You will be able to see the results better if you paint the magnet white...
The logical operator ______________________ takes one operand and inverts its value, changing true to false and...
The logical operator ______________________ takes one operand and inverts its value, changing true to false and false to true. A. && B. != C. II D. ! The ___________________ operator takes two boolean expressions as operands; if both are true, then the result is true; otherwise the result is false. A. $$ B. && C. || D. ! What is the order of precedence of the operators that Java uses to evaluate a condition and selection statements to choose which...
Lab Assignment Objectives 'Be able to overload combined binary operators as member operator functions. Show how...
Lab Assignment Objectives 'Be able to overload combined binary operators as member operator functions. Show how to overload binary operators as friend functions. Show how to convert from a fundamental type to a user-defined type using a constructor. Understand exception handling mechanisms using try-catch block statements. Understand the Application Complex Numbers A complex number, c, is an ordered pair of real numbers (doubles). For example, for any two real numbers, s and t, we can form the complex number: This...
Lab Assignment Objectives 'Be able to overload combined binary operators as member operator functions. Show how...
Lab Assignment Objectives 'Be able to overload combined binary operators as member operator functions. Show how to overload binary operators as friend functions. Show how to convert from a fundamental type to a user-defined type using a constructor. Understand exception handling mechanisms using try-catch block statements. Understand the Application Complex Numbers A complex number, c, is an ordered pair of real numbers (doubles). For example, for any two real numbers, s and t, we can form the complex number: This...
The objective of this homework assignment is to demonstrate proficiency with reading files, and using string...
The objective of this homework assignment is to demonstrate proficiency with reading files, and using string methods to slice strings, working with dictionaries and using-step wise development to complete your program. Python is an excellent tool for reading text files and parsing (i.e. filtering) the data. Your assignment is to write a Python program in four steps that reads a Linux authentication log file, identifies the user names used in failed password attempts and counts the times each user name...
c++ using class... define operator overloading and give simple example how we can use operator overloading...
c++ using class... define operator overloading and give simple example how we can use operator overloading by writing simple program in which different operators are used to add, subtract, multiply and division.
Objectives:         The objectives of this lab exercise are to: Demonstrate an understanding of the concept...
Objectives:         The objectives of this lab exercise are to: Demonstrate an understanding of the concept of operator precedence in Python expressions and statements. Take simple problem descriptions and produce small but complete Python programs that solve these problems. Give you some practice in using simple Python interactive input and output capabilities. Give you some practice in the simplest Python decision statement (if). Give you some practice in the simplest Python loop statement (while). Specifications: This is a four-part exercise....
Propositional Logic Using operator properties and other logical equivalences (not truth tables), prove these statements. 1....
Propositional Logic Using operator properties and other logical equivalences (not truth tables), prove these statements. 1. ((p→r)∧(q→r)∧(p∨q))→r (tautology) 2. ¬(q→p)∧(p∧q∧s→r)∧p (contradiction) 3. (p→q)∧(p→r)≡p→(q∧r)
Question Objectives: The objectives of this lab exercise are to: Demonstrate an understanding of the concept...
Question Objectives: The objectives of this lab exercise are to: Demonstrate an understanding of the concept of operator precedence in Python expressions and statements. Take simple problem descriptions and produce small but complete Python programs that solve these problems. Give you some practice in using simple Python interactive input and output capabilities. Give you some practice in the simplest Python decision statement (if). Give you some practice in the simplest Python loop statement (while). Specifications: This is a four-part exercise....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT