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
Katarina [22]
3 years ago
13

Write a loop that reads c-strings from standard input where the c-string is either "land", "air", or "water". The loop terminate

s when "xxxxx" (five x characters ) is read in. Other strings are ignored. After the loop, your code should print out 3 lines: the first consisting of the string "land:" followed by the number of "land" strings read in, the second consisting of the string "air:" followed by the number of "air" strings read in, and the third consisting of the string "water:" followed by the number of "water" strings read in. Each of these should be printed on a separate line. Assume that the maximum length of a string is 8.

Computers and Technology
1 answer:
Anvisha [2.4K]3 years ago
3 0

Answer:

I am writing a C++ code.        

#include <iostream> // for input output functions

using namespace std; // identifies objects like cin cout

int main() { //start of main() function body

string c_string; // stores the string entered by user from land water or air

int land=0; // contains the number of times land string is read in

int air=0; //contains the number of times air string is read in

int water = 0; //contains the number of times water string is read in

cin>>c_string; //reads the string entered by user from air water or land

/*while loop continues to execute until user enters xxxxx or maximum length of a string exceeds 8 */

while(c_string!= "xxxxx" && c_string.length()<=8) {

if(c_string=="land"){ // if string entered by user is land

land = land + 1;} //counts and increments each occurrence of land string by 1

else if(c_string=="air"){// if string entered by user is air

air = air + 1;}// counts and increments each occurrence of string air by 1

else if(c_string=="water"){// if string entered by user is water

water = water + 1;}//counts and increments each occurrence of air by 1

cin>>c_string;}

/* keeps reading the string entered by user from land air or water, until the loop breaks after the user enters xxxxx or user enters a string whose length is greater than 8 */

//prints the number of times land, air and water are read in

cout << "land:"<<land;

cout << endl<<"air:"<<air;

cout << endl<< "water:"<<water; }                      

                                                                                     

Explanation:

Everything is well explained in the comments above.

The program prompts the user to input strings. These strings are either land air or water. The while loop continues to read the input strings until user enters xxxxx or the string entered by user exceeds the length 8. Both these terminating conditions are added in the while loop. After the loop terminates, the number of times land, air and water strings are read is displayed on the output screen. Any other string entered by user other than these 3 is ignored. The program along with the output is attached.

You might be interested in
Three popular types of ____ are handheld computers, PDAs, smart phones.
m_a_m_a [10]

Answer:

portable media players, and digital cameras

Explanation:

4 0
3 years ago
1. You will need to add data to the tables in your design that matches the data in the supplied Excel documents. If your databas
Harlamova29_29 [7]

Answer:

is all about knowing what to do with the data

Explanation:

determine what to do with your data

3 0
3 years ago
What do you think is the most important factor affecting the collection of digital data and what impact do you think that this f
borishaifa [10]

<u>Answer:</u>

<u>Privacy concerns.</u>

<u>Explanation:</u>

Privacy concerns have played an important role in how we collect digital data. For example, privacy activists believe that an individual has the right to know how his or her information is being used and that such an individual also has the right to withhold such information.

Such issues have affected the ability of law enforcement agencies to investigate criminal activities. For example, an individual who is accused of a crime may claim a <em>right to withhold his personal information, such as his mobile device, and thus he refuses to give out such information.</em>

4 0
3 years ago
Write 3 differences between Virtual reality and Augmented reality
nekit [7.7K]

Answer:

In vr you in a vurtial world

7 0
3 years ago
Read 2 more answers
What is the process or technique of "making something that allows" human beings to share their knowledge, perform a task, or ful
Mashcka [7]

Answer:Technology

Explanation: it can be define as process or technique of making something that allows human beings to share their knowledge, perform a task or fulfill a function

-tool or invention that, once created and used, is intended to solve a problem or improve on past understandings of how to do something.

7 0
3 years ago
Other questions:
  • Wanda wants to find some basic information about her computer, for example, what operating system and how much RAM are installed
    10·1 answer
  • What can you say about the following Java class definition?
    10·1 answer
  • How do you create a reference page in apa format with all websites?
    5·1 answer
  • What does the hard disk drive do?
    9·2 answers
  • A smartphone user entered an incorrect passcode on his phone several times in a row, which locked the device.
    5·1 answer
  • A look to different section of the same page is known as_____.
    7·1 answer
  • Write a program that performs the following tasks: Display a friendly greeting to the user Prompt the user for the value to conv
    13·1 answer
  • Write a program that calculates the average of 4 temperatures. Function 1--write a function to ask a user for 4 temperatures and
    10·1 answer
  • Do u have to divide or multiply this problem 5300 yd = mi
    9·1 answer
  • ____coping skills are instinctive.<br> A. All<br> B. No<br> C. Some
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!