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
Create a program in c/c++ which accepts user input of a decimal number in the range of 1 -100. Each binary bit of this number wi
kirill115 [55]

Answer:

// here is code in C++.

#include <bits/stdc++.h>

using namespace std;

void switch_fun(int input)

{

//array to store binary of input number

   int bin[7];

   // convert the number into binary

   for(int i=0; input>0; i++)

       {

           bin[i]=input%2;

           input= input/2;

       }

   // print the switch number and their status

   cout<<"Switch number:\t 1\t 2\t 3\t 4\t 5\t 6\t 7 \n";

   cout<<"status:      ";

   for(int j=6;j>=0;j--)

   {

   // if bit is 1 print "ON" else print "OFF"

       if(bin[j]==1)

           cout<<"\t ON";

       else

           cout<<"\t OFF";

   }

}

int main()

{

   int n;

   cout<<"enter the number between 1-100 only:");

   // read a number in decimal

   cin>>n

   // validate the input

   while(n<1 ||n>100)

   {

     cout<<"wrong input!! Input must be in between 1-100:"<<endl;

     cout<<"enter the number again :";

     cin>>n;

   }

// call the function with input parameter

  switch_fun(n);

return 0;

}

Explanation:

Read a decimal number from user. If the number is not between 1 to 100 the it will again ask user to enter the number until the input is in between 1-100.Then it will call the fun() with parameter n. First it will convert the decimal to binary array of size 7.Then print the status of switch.If bit is 1 then print "ON" else it will print "OFF".

Output:

enter the number between 1-100 only:-5

wrong input!! Input must be in between 1-100:

enter the number again :125

wrong input!! Input must be in between 1-100:

enter the number again :45

Switch number:   1       2       3       4       5       6       7

Status:          OFF     ON      OFF     ON      ON      OFF     ON

8 0
3 years ago
All cells in row 2 through 5 are referred as 2:5 true or false
Simora [160]
<h3>Answer:</h3><h2>TRUE</h2>

Explanation:

BRAINLIEST PLSSSSSSSSSSSSSSSSSSS

8 0
2 years ago
Coding with Loops Worksheet
BartSMP [9]

Answer:

if you give me brainliest i will answer your question

Explan

4 0
2 years ago
Read 2 more answers
Business intelligence is gained through industrial espionage and the gathering of this information often includes illegal or une
Nataly [62]

Answer:

A) True

Explanation:

Industrial espionage utilizes both illegal and unethical methods in gathering information about a corporate organization in order to get business intelligence. This involves stealing intellectual property and trade secrets to use them for a competitive advantage.  because Information about company's products, services, finances, sales, etc can be toold for  economic warfare

3 0
3 years ago
Why do some people argue that tech companies like Apple should do more to address the smartphone addiction problem?
Neko [114]

Answer:

Cause It Will Help Make A Fix For The Issue

Explanation:

Does This Help?

5 0
3 years ago
Other questions:
  • Which sentences in the passage show the preventive measures to avoid data breach?
    9·1 answer
  • What type of topology gives you a direct connection between two routers so that there is one communication path?
    14·1 answer
  • What is it called when two different files generate the same hashing result?
    15·1 answer
  • Which of the actions below will not create more room on your hard drive?
    11·1 answer
  • Assuming that we only support BEQ and ADD instructions, discuss how changes in the given latency of this resource affect the cyc
    7·1 answer
  • Rule number one for handling an emergency is to _____. A. buy a new vehicle B. call law enforcement C. remain calm D. restart th
    6·2 answers
  • Which feature is used to change how a presentation moves from slide to slide?
    14·1 answer
  • Discuss how printing, publishing, and e-learning industries have transformed on evolved due to developments and advances the fie
    14·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    11·1 answer
  • 1. A cell is identified by its ........
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!