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 are multiple worksheets
Naddika [18.5K]
More than one worksheet?
5 0
2 years ago
You resurrected an old worksheet. It appears to contain most of the information that you need, but not all of it. Which step sho
vagabundo [1.1K]

Answer:

The answer is "check the worksheet is not read only"

Explanation:

The read only mode is used for read the file data, and it doesn't allows the user to update the file, and for updating the worksheet we should check iut does not open in the read-only mode.

If it is open, then we close it and for close we goto the office button and click on the tools option after that goto general setting, in this there is a check box for turn off the read-only mode.

 

8 0
3 years ago
The array mycats is an 8 element array of type kitty that has already been declared and initialized. write the expression(s) in
Basile [38]
Console.log(mycats[3])
5 0
3 years ago
The MAA is responsible on a daily basis to protect office computers and patient records and personal information from hackers. R
d1i1m1o1n [39]

Two things that I can do in order to protect these assets with the use of the computer or the internet is by first, downloading and using an antivirus software where this has the ability to protect the computer from invaders, hackers and other viruses that could get into the system of the computer. Second, making the data encrypted, so that it will be protected with a code to prevent other people who are trying to get in the data.

3 0
3 years ago
Hulu suggestions? I just got it and I wanna know what's good :)
o-na [289]
Anime show: naruto

Drama show: sweet Mongolian

Adventure show: outer banks
6 0
3 years ago
Read 2 more answers
Other questions:
  • What type of link is used to call this file
    11·1 answer
  • What is the primary reason that organizations change their structure through downsizing, outsourcing, and offshoring as a means
    14·1 answer
  • c++ You are given an array A representing heights of students. All the students are asked to stand in rows. The students arrive
    5·1 answer
  • You would like to know how many cells contain data. Which function should you use?
    11·1 answer
  • Gta! ! ! !!aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    11·2 answers
  • Ayuda necesito 7 objetos que se utilizan en la vida diaria
    8·1 answer
  • What is the main circuit board inside the computer called?CD-ROMY
    12·1 answer
  • Is social media bringing people together or cause in sepretation?​
    11·2 answers
  • How can I master networking my home/business computer(s) - Tv's - iot devices and make the whole system as secure as possible?
    12·1 answer
  • The impact of the destruction of train station on the budget of the minister of finance
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!