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
Part 1 of 4 parts for this set of problems: Given an 4777 byte IP datagram (including IP header and IP data, no options) which i
LekaFEV [45]

Answer:

Fragment 1: size (1332), offset value (0), flag (1)

Fragment 2: size (1332), offset value (164), flag (1)

Fragment 3: size (1332), offset value (328), flag (1)

Fragment 4: size (781), offset value (492), flag (1)

Explanation:

The maximum = 1333 B

the datagram contains a header of 20 bytes and a payload of 8 bits( that is 1 byte)

The data allowed = 1333 - 20 - 1 = 1312 B

The segment also has a header of 20 bytes

the data size = 4777 -20 = 4757 B

Therefore, the total datagram = 4757 / 1312 = 4

6 0
2 years ago
Write a program that reads in an integer, and breaks it into a sequence of individual digits. Display each digit on a separate l
Montano1993 [528]

Answer:

The program in Python is as follows:

num = int(input())

for i in str(num):

   print(int(i))

Explanation:

This gets input for the number

num = int(input())

This converts the number to string and iterates through each element of the string

for i in str(num):

This prints individual digits

   print(int(i))

4 0
2 years ago
How many times is the body of the loop executed?
Flura [38]

Answer:

The loop will run 5 times.

3 0
2 years ago
Imagine that you are preparing a multimedia presentation. What are the four things you need to consider when getting started?
Marrrta [24]

Explanation:

Consider the Content

Create an Outline

Develop Your Presentation

PRACTICE!!

8 0
3 years ago
Read 2 more answers
You complete your database, and the company begins using it. Shortly afterwards, two GearUp buyers, Cora and Owen, work together
Olegator [25]

Answer: Multi-user issue

Explanation: A database management system scheme can have multi-user issue when the designing of the system is not made properly. The multi user issue rises when the users concurrently access the data from the database and related error get invoked due to some reason like  repeatable reading issue, serialization, etc.

The reading problem is usually can be related to reading of the database in  uncommitted manner, uncommitted reading, repeatedly reading etc.Thus, Cora and Owen are accessing the database concurrently which can create multi-user issue.

3 0
2 years ago
Other questions:
  • Trish uas bought a new computer, which she plans to start working on aftwr a week. Since Trish has not used computers in the pas
    13·1 answer
  • Which of the following is NOT an option in the comments group
    12·1 answer
  • Write a program to calculate and return total surface area of a box using FUNCTION _END FUNCTION.​
    15·1 answer
  • What is the keyboard shortcut to display the merge to printer dialog box?
    5·1 answer
  • Match each career with the education required for each job
    12·1 answer
  • Which of these is the proper flow for an Auto Trans cooling system?
    7·2 answers
  • The objective of ____ testing is to identify and eliminate execution errors that could cause a program to terminate abnormally,
    15·1 answer
  • A10:A20 Refer to values in
    8·1 answer
  • A user calls to complain that her computer is behaving erratically. Some days it functions correctly, and other days, it crashes
    15·1 answer
  • Do network packets take the shortest route?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!