) A new club opened up and they have three programs. Write ONLY ONE long logical
ID: 3832389 • Letter: #
Question
) A new club opened up and they have three programs. Write ONLY ONE long logical statement in c++ to cover all these conditions using and, or, and not conditions with the necessary variables definitions to cover the following rules: (..&&..&&..||.. !..)
- All children under 18 are allowed to enter only on Sundays from 8:00 am until 5:00 pm .
- Young adults between the ages of (18 and 54 inclusive) may enter the club after 5:00 pm except on Sundays. Males are allowed in on odd days and females on even days unless the day falls on a Friday then both young adults may enter the club after 5:00 pm regardless if it is odd or even.
Seniors, age 65 and older, may enter the club only on Sundays after 5:00 pm
Explanation / Answer
# Following are the assumptions
# age variable is read and is an integer
# day variable is read and is from 'Monday', 'Tuesday' .... 'Sunday'
# time variable is read and is in 24 hour format. That is 5pm is 17 hour
# assuming day starts from Monday and ends on Sunday. That means Monday, Wednesday, Friday are odd days and the rest are even days
# gender variable is read and contains value 'M' for Male and 'F' for female
if(
( age<18 && strcmp(day, "Sunday")==0 && ( time>='08' && time<'17' ) ) ||
(
( age>=18 && age<=54 ) &&
time>'17' &&
strcmp(day, "Sunday")!=0 &&
(
( gender=='M' && ( strcmp(day, "Monday")==0 || strcmp(day, "Wednesday")==0 ) ) ||
( gender=='F' && ( strcmp(day, "Tuesday")==0 || strcmp(day, "Thursday")==0 ) )
)
)||
( age>=65 && strcmp(day, "Sunday")==0 && time>'05' )
){
// write the necessary statements here
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.