Problem 3: Friends and Relations Select/write a solution to each of these problems using relational and logical operators. Do not use any if statements! Rule 1: If I see a friend, I greet them. (Friends can be seen more than once in the same input.) Rule 2: If a person doesn't have the name of a friend, I do not greet them. Rule 3: The input consists of the names of the people I meet represented as String data Note: All output should be true if and only if a certain condition occurs. Your code must return true for all situations where that condition occurs, not just some of them. Similarly, your code must return false for all situations where the condition does not occur. For example, if I have two friends named "Abby" and "George", I would greet both of them if I saw "Abby" first, then "George". But, I would also greet them both if I saw "George" first, then "Abby". My code would need to print true in both of those situations not just one of them. odd number of people. (true if 1, 3, or 5 people, false otherwise) boolean oddFriends oddFriends = (input() EQ "David" AND input() EQ "David" AND input() EQ "David" AND input() EQ "David" AND input() EQ "David") print oddFriends boolean one, three, five one =input() == "David" two =input() == "David" AND input() == "David" three = input() == "David" AND input() == "David" AND input() == "David" print one or two or three boolean oddFriends oddFriends = (input() EQ "David" OR input() EQ "David" OR input() EQ "David" OR input() EQ "David" OR input() EQ "David") print oddFriends boolean oddFriends oddFriends = (input() EQ "David" XOR input() EQ "David" XOR input() EQ "David" XOR input() EQ "David" XOR input() EQ "David") print oddFriends

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 20PE: When you borrow money to buy a house, a car, or for some other purpose, you repay the loan by making...
icon
Related questions
icon
Concept explainers
Question

I need help at this question because I am stuck at this question. I included answer choice as well and please solve with carefully. 

input.)
Rule 2: If a person doesn't have the name of a friend, I do not greet them
Rule 3: The input consists of the names of the people I meet represented as String
data
Note: All output should be true if and only if a certain condition occurs. Your code must
return true for all situations where that condition occurs, not just some of them. Similarly,
your code must return false for all situations where the condition does not occur.
For example, if I have two friends named "Abby" and "George", I would greet both of
them if I saw "Abby" first, then "George". But, I would also greet them both if I saw
"George" first, then "Abby". My code would need to print true in both of those situations,
not just one of them.
Friend: "David"
Input: 5 people
Output: true iff I greet an
odd number of
O
O
people.
(true if 1, 3, or 5
people, false
otherwise)
boolean oddFriends
oddFriends (input() EQ "David" AND
input() EQ "David" AND
input() EQ "David" AND
input() EQ "David" AND
input() EQ "David")
print oddFriends
boolean one, three, five
one =input() == "David"
two =input() == "David" AND input() == "David"
three=input() == "David" AND input() == "David" AND
input() == "David"
print one OR two OR three
boolean oddFriends
oddFriends = (input() EQ "David" OR
input() EQ "David" OR
input() EQ "David" OR
input() EQ "David" OR
input() EQ "David")
print oddFriends
Transcribed Image Text:input.) Rule 2: If a person doesn't have the name of a friend, I do not greet them Rule 3: The input consists of the names of the people I meet represented as String data Note: All output should be true if and only if a certain condition occurs. Your code must return true for all situations where that condition occurs, not just some of them. Similarly, your code must return false for all situations where the condition does not occur. For example, if I have two friends named "Abby" and "George", I would greet both of them if I saw "Abby" first, then "George". But, I would also greet them both if I saw "George" first, then "Abby". My code would need to print true in both of those situations, not just one of them. Friend: "David" Input: 5 people Output: true iff I greet an odd number of O O people. (true if 1, 3, or 5 people, false otherwise) boolean oddFriends oddFriends (input() EQ "David" AND input() EQ "David" AND input() EQ "David" AND input() EQ "David" AND input() EQ "David") print oddFriends boolean one, three, five one =input() == "David" two =input() == "David" AND input() == "David" three=input() == "David" AND input() == "David" AND input() == "David" print one OR two OR three boolean oddFriends oddFriends = (input() EQ "David" OR input() EQ "David" OR input() EQ "David" OR input() EQ "David" OR input() EQ "David") print oddFriends
Problem 3: Friends and Relations
Select / write a solution to each of these problems using relational and logical
operators.
Do not use any if statements!
Rule 1: If I see a friend, I greet them. (Friends can be seen more than once in the same
input.)
Rule 2: If a person doesn't have the name of a friend, I do not greet them.
Rule 3: The input consists of the names of the people I meet represented as String
data.
Note: All output should be true if and only if a certain condition occurs. Your code must
return true for all situations where that condition occurs, not just some of them. Similarly,
your code must return false for all situations where the condition does not occur.
For example, if I have two friends named "Abby" and "George", I would greet both of
them if I saw "Abby" first, then "George". But, I would also greet them both if I saw
"George" first, then "Abby". My code would need to print true in both of those situations,
not just one of them.
odd number of
people.
(true if 1, 3, or 5
people, false
otherwise)
boolean oddFriends
oddFriends = (input() EQ "David" AND
input() EQ "David" AND
input() EQ "David" AND
input() EQ "David" AND
input() EQ "David")
print oddFriends
boolean one, three, five
one
=input() == "David"
two
=input() == "David" AND input() == "David"
three = input() == "David" AND input() == "David" AND
input() == "David"
print one OR two OR three
boolean oddFriends
oddFriends = (input() EQ "David" OR
input() EQ "David" OR
input() EQ "David" OR
input() EQ "David" OR
input() EQ "David")
print oddFriends
boolean oddFriends
oddFriends (input() EQ "David" XOR
input() EQ "David" XOR
input() EQ "David" XOR
input() EQ "David" XOR
input() EQ "David")
print oddFriends
Transcribed Image Text:Problem 3: Friends and Relations Select / write a solution to each of these problems using relational and logical operators. Do not use any if statements! Rule 1: If I see a friend, I greet them. (Friends can be seen more than once in the same input.) Rule 2: If a person doesn't have the name of a friend, I do not greet them. Rule 3: The input consists of the names of the people I meet represented as String data. Note: All output should be true if and only if a certain condition occurs. Your code must return true for all situations where that condition occurs, not just some of them. Similarly, your code must return false for all situations where the condition does not occur. For example, if I have two friends named "Abby" and "George", I would greet both of them if I saw "Abby" first, then "George". But, I would also greet them both if I saw "George" first, then "Abby". My code would need to print true in both of those situations, not just one of them. odd number of people. (true if 1, 3, or 5 people, false otherwise) boolean oddFriends oddFriends = (input() EQ "David" AND input() EQ "David" AND input() EQ "David" AND input() EQ "David" AND input() EQ "David") print oddFriends boolean one, three, five one =input() == "David" two =input() == "David" AND input() == "David" three = input() == "David" AND input() == "David" AND input() == "David" print one OR two OR three boolean oddFriends oddFriends = (input() EQ "David" OR input() EQ "David" OR input() EQ "David" OR input() EQ "David" OR input() EQ "David") print oddFriends boolean oddFriends oddFriends (input() EQ "David" XOR input() EQ "David" XOR input() EQ "David" XOR input() EQ "David" XOR input() EQ "David") print oddFriends
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Query Syntax
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning