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]
4 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]4 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
I need help with my homework
lukranit [14]

Answer:

C is not equal to the other two.

Explanation:

A = 35

B = 35

C is actually equal to 36.

8 0
2 years ago
Which two keys are commonly used to move or insert data?.
vlabodo [156]

Answer:

control and shift

Explanation:

6 0
3 years ago
Which of the following is not a common business use of blogs? document sharing promotions posting answers to frequently asked qu
vagabundo [1.1K]
Document sharing I think
4 0
3 years ago
Read 2 more answers
Legal functions are the most important area of IG impact. Under the FRCP amendments, corporations must proactively manage the e-
AfilCa [17]

Answer:It can jeopardize your chain of custody, but also expose sensitive data to the wrong people.

Explanation:

6 0
3 years ago
Andrew frequently uses bullet points and numbered lists in his presentation to _____.
seraphim [82]

Hey there!


Andrew likely does this to convey a <em>point </em>easily. Bullet points offer a way to explain a topic, but in simple sentences that when all add up, explain it. They're meant to be short and sweet, and don't make the reader lose their attention.


Hope this helps!

5 0
4 years ago
Read 2 more answers
Other questions:
  • In setting up a small office network, the network administrator decides to assign private IP addresses dynamically to workstatio
    12·1 answer
  • With which game is the Taito Corporation associated?
    9·1 answer
  • The PRNG variable ___________ is defined in NIST SP 800-90 as a number associated with the amount of work required to break a cr
    7·1 answer
  • When you tap or click the ____ button for a selected graphic, Word provides options for changing how a graphic is positioned wit
    5·1 answer
  • How many bits must be “flipped” (i.e., changed from 0 to 1 or from 1 to 0) in order to capitalize a lowercase ‘a’ that’s represe
    7·1 answer
  • What factors should you consider when buying a hard drive?
    8·1 answer
  • Describe how learning can be accessed in your class?​
    14·1 answer
  • Which picture should i put as my profile picture.
    15·2 answers
  • Implement the above in c++, you will write a test program named create_and_test_hash.cc . Your programs should run from the term
    9·1 answer
  • Which of the following statements is false?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!