1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kupik [55]
3 years ago
15

Print either "Fruit", "Drink", or "Unknown" (followed by a newline) depending on the value of userItem. Print "Unknown" (followe

d by a newline) if the value of userItem does not match any of the defined options. For example, if userItem = GR_APPLES, output should be:FruitSample program:#include using namespace std;int main() { enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER}; GroceryItem userItem = GR_APPLES; return 0;}Below, do not type an entire program. Only type the portion indicated by the above instructions (and if a sample program is shown above, only type the portion.)

Computers and Technology
1 answer:
vagabundo [1.1K]3 years ago
7 0

Answer:

I am writing a C++ program. Let me know if you want the program in some other programming language. Here is the portion of the code:

if((userItem == GR_APPLES) || (userItem == GR_BANANAS)){

 cout << "Fruit";   }

else if((userItem == GR_JUICE) || (userItem == GR_WATER)){

 cout << "Drink";  }

else{

 cout << "Unknown";  }  

cout << endl;

 

Explanation:

The IF statement is used to check the defined options with the value in the userItem.

If the value of the userItem is GR_APPLES OR GR_BANANAS then Fruit is printed as the output. || represents a logical operator OR so this means that userItem can be either the GR_APPLES or GR_BANANAS for the If condition to evaluate to true.

If the above condition evaluates to false then the else-if part will be checked next. So the else if checks if the value in the userItem is GR_JUICE or GR_WATER. If userItem contains either of these two then Drink is displayed on the screen as output.

If the else-if statement also evaluates to false then the else part is executed which displays Unknown.

The cout<< endl; statement in the last is used to print the new line. For example if the output is Unknown then it is followed by a new line.

In the given program userItem is set to GR_APPLES

GroceryItem userItem = GR_APPLES

So the output of the whole program is Fruit followed by a new line.

The screenshot of the code along with the output is attached.

You might be interested in
Business application software programs make it possible to
Daniel [21]
Business application software programs make it possible to: increase productivity in the office setting.
Please give me Brainless if this help!!
6 0
2 years ago
You can edit existing conditional formatting _____ from the conditional formatting rules manager dialog box.
Lera25 [3.4K]
I believe the term you're looking for would be "rules" 
send me a message if not true.
7 0
3 years ago
What products data from corruption?<br>​
vesna_86 [32]

Answer:

Types of data corruption

Data corruption refers to errors in computer data that occur during writing, reading, storage, transmission, or processing, which introduce unintended changes to the original data.

...

Data Integrity Field.

ECC memory.

Forward error correction.

List of data recovery software.

Parchive.

RAID.

Reed-Solomon error correction.

Explanation:

7 0
3 years ago
Read 2 more answers
What will the following code snippet print out? class Raspberry extends Fruit implements Boxable { ... } Raspberry berry = new R
sveticcg [70]

Answer:

The answer to this question is "TrueTrueTrueTrue".

Explanation:

In the java program code firstly we declare the class that is Fruit and an interface that is Boxable. In the class and interface, we write some code. Then we declare another class that is Raspberry. for class to class inherit we use the extends keyword and class to interface inherit we use the implements keyword. Then we create a Raspberry class object that is berry. and use the print command or method that is (System.out.println). In this, we write some code and run it. So the output of the program is true because all the code that is written in the method is correct.  

3 0
3 years ago
Write the function longest that, given a nonempty list of strings, finds the longest even-length string that ends with ing. It t
lorasvet [3.4K]

Answer:

  1. def longest(L):
  2.    for x in L:
  3.        if(len(x) % 2 == 0):
  4.            if(x.endswith("ing")):
  5.                return x  
  6.    return ""
  7. print(longest(["Playing", "Gaming", "Studying"]))

Explanation:

The solution is written in Python 3.

Firstly, create a function longest that takes one parameter L as required by question (Line 1).

In the function, create a for loop to traverse through each string in L and check if the current string length is even (Line 2 - 3). If so, use string endwiths method to check is the current string ended with "ing". If so return the string (Line 4-5).

At last, test the function by passing a list of string and we shall get the output "Gaming".

8 0
3 years ago
Other questions:
  • Write a MIPS assembly language program that prompts for a user to enter how many floating point numbers to enter, then prompts t
    10·1 answer
  • Naseer has inserted an image into his document but needs the image to appear on its own line.
    14·2 answers
  • Which CSS attribute would change an element's font color to blue
    15·2 answers
  • In 4-bit sign magnitude representation, what is the binary encoding of the number -5?
    15·1 answer
  • Which code will allow Joe to print Coding is fun. on the screen? print("Coding is fun.") print(Coding is fun.) print = (Coding i
    10·2 answers
  • Given a String variable named line1 and given a Scanner reference variable stdin that has been assigned a reference to a Scanner
    11·1 answer
  • According to the textbook, the definition of transition is
    13·1 answer
  • I really want to know the best way to deal as much heart as possible plz tell me
    7·2 answers
  • What are the local, state, and national opportunities that may be available to those who participate in CTSOs?
    9·1 answer
  • The domain name system ________. Question 2 options: A) is a way to find a host's IP addresses if your computer only knows the h
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!