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
What type of html list will automatically place a list marker, or bullet point, indicator in front of each item? group of answer
scZoUnD [109]

Main Answer:What type of html list will automatically place a list marker, or bullet point, indicator in front of each item? group of answer choices description l <u>unordered list</u>

Sub heading:

How many types of html list and explain?

Explanation:

1.There are three types

unordered list

ordered list

description list

2.unordered list: is used to group a set of related items in no particular order.

Reference link:

https://brainly.com

Hashtag:

#SPJ4

3 0
2 years ago
Write a program that asks the user to provide a word, validate that it is a word, and print the word.
natta225 [31]

Answer:

be clearer. your question doesn't seem to be presented well

8 0
3 years ago
In which contingency plan testing strategy do individuals participate in a role-playing exercise in which the CP team is present
vesna_86 [32]

Answer:  B. structured walk-through

4 0
3 years ago
Read 2 more answers
The ____ provides access to the Internet may also be internal.
dmitriy555 [2]
Local area network (LAN)
7 0
3 years ago
Read 2 more answers
What's wrong with SontungMTP's song?
Anettt [7]

Answer:

A

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • Write a program that estimates the approximate number of times the user’s heart has beat in his/her lifetime using an average he
    12·1 answer
  • Select the correct answer.
    7·2 answers
  • Ryan wants to ensure that all the words in this document are evenly spaced so that they look neat and readable . Which option in
    12·1 answer
  • Your employer gives you a list of all chemicals in the entire building and the location of the SDS collection, and he asks you t
    15·2 answers
  • technician is dispatched to troubleshoot a user's computer. After performing diagnostics, the technician determines that drive t
    5·1 answer
  • Web design and development tools
    13·1 answer
  • Help a brotha out..................
    10·1 answer
  • I need a C++ program to ask the user to put in different numbers until zero is pressed then the program counts the numbers that
    10·1 answer
  • Which of the following is not a reason to choose a community college?
    14·1 answer
  • Writing queries in sql to compile data from a database is related to the physical level of databases true or false?.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!