Question
Lab 4.3 This lab introduces the logical operators AND, OR, and NOT in a menu driven application program. Copy and paste the code below in
Lab 4.3
This lab introduces the logical operators AND, OR, and NOT in a menu driven application program.
Copy and paste the code below in a filename LastFirst_lab43.cpp (e.g. DoeJoe_lab43.cpp) and save it in Lab 4 folder.
Bring in the LastFirst_lab43.cpp program from the Lab 3 folder.
How could you rewrite gpa >= 2.0 in the first if statement using the NOT operator?
Could you replace year !='4' in the else if statement with year < 4 or year <= 3? Why or why not?
If you replace
if ( gpa >= 2.0 && year == '4') with
if ( gpa >= 2.0 || year == '4') and replace
else if ( year != '4'|| gpa < 2.0) with
else if ( year != '4' && gpa < 2.0)
which students will graduate and which will not graduate according to this new program? Does this handle all cases (i.e., all combinations of year and gpa)?
Could you replace else if ( year != '4'|| gpa < 2.0) with the single word else?
this introduces a logic error!
fix the logic error, and then
submit the revised LastFirst_lab43.cpp
The following is the code to be used:
// This program illustrates the use of logical operators
// PLACE YOUR NAME HERE
#include
using namespace std;
int main()
{
char year;
float gpa;
cout << "What year student are you ?" << endl;
cout << "Enter 1 (freshman), 2 (sophomore), 3 (junior), or 4 (senior)" << endl << endl;
cin >> year;
cout << "Now enter your GPA" << endl;
cin >> gpa;
if (gpa >= 2.0 && year == '4')
cout << "It is time to graduate soon" << endl;
else if (year != '4'|| gpa <2.0)
cout << "You need more schooling" << endl;
return 0;
}
Remember to submit your .cpp file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started