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
How does a security information and event management system (SIEM) in a SOC help the personnel fight against security threats
snow_lady [41]

A security information and event management (SIEM) system in an SOC helps fight security threats by combining data from varying technology sources and analyzing logs in real time, which helps in managing resources to implement protective measures against threats.

<h3 /><h3>Features of a SIEM</h3>

They are tools used to promote information security through the provision of reports that display malicious intrusion attempts and alerts that are triggered in case of violation of established rules for security.

Therefore, through SIEM tools there is greater analysis and collection of data that can impact information security, generating a better classification of threats and investigative capacity to carry out actions to combat system insecurities.

Find out more information about security information here:

brainly.com/question/26282951

6 0
2 years ago
Why are computer messages encapsulated?
Tcecarenko [31]

Answer:

I think the answer is to translate messages from one machine’s programming language into another

Explanation:

6 0
3 years ago
Semiconductor memory is used mainly for primary storage even with its high cost. In another hand, the magnetic tape is the cheap
vodomira [7]
<span>In general you want to use the cheapest storage medium who's speed is compatible with the function it needs to perform. For active storage that's handled while running programs, you need memory whose speed is closely matched to the processor speed. And that would be the rather expensive semiconductor memory which is close to ideal for the task. But semiconductor memory has the disadvantage of being expensive and it loses the values stored when power is lost. So slower, persistent storage is used such as SSD (Solid State Drives) and hard disks. That media is cheaper, but slower, but still fast enough to handle tasks such as loading programs and data into memory for execution, or storing data generated by programs to persistent storage. But as with all man made things, disasters happen. Computers break down, hard disks crash, floods and fires happen, etc., and as a result data is lost. So we make backups. Backups have to have a lot of storage and they have to be cheap. But they don't need rapid access, you can start at the beginning and read (or write) all the way to the end. And for that purpose, magnetic tape is ideal. Magnetic tape is actually quite fast when you're simply streaming a continuous stream of data without any need to randomly access any piece of that data. And it's cheap, so you're willing to make a back up copy of your system and store that backup off site so a single disaster won't destroy both the primary system and the backup.</span>
3 0
3 years ago
Letm1, m2,···mnbe distinct numbers on the number line, in the increasing order. Your goalis to color all of them blue. You have
siniylev [52]

Answer:

Following are the algorithm to this question:

y = 0 //  initialize variable y that assigns the value  0

p = 1 // initialize value 1 in the variable p which also known as starting position

init num = 1//define variable num that assign value 1

for j = 1 to n: //defining loop

y = m[j] - m[p]

if (y > 10) //defining if block

num++;  //increment num variable

p=i; //holding loop value in p variable

y= 0//assign value 0 in y variable

Explanation:

Following are the runtime analysis of the above-given algorithm:

The above-provided algorithm is greedy, but if it doesn't exceed the scope, it operates by greedily choosing its next object. Therefore the algorithm selects the fewest number of pens.

Running time:

This algorithm merely iterates once over all the points. The run-time is therefore O(n).

7 0
3 years ago
Which is technologically backward country? Options United States U K CHILE INDIA
agasfer [191]
The answer is India.

There are a lot of factors affecting India in becoming backward in technology competitiveness. 
One factor is producing or exporting lots of engineers to other countries leaving average skills in the country. Second, poor government institutes. Next, problems with budget allocations. 
3 0
3 years ago
Other questions:
  • While in slide show mode, if you are not careful you can close the application by clicking the x on the menu bar. question 38 op
    12·2 answers
  • In this context, the word “session” refers to _____.
    5·2 answers
  • how to answer the questions on brainly? I've typed my answer in the box but there's no submit button or whatever, and the only t
    14·2 answers
  • Jack is an accountant. He can't access the spreadsheet software, which is installed on the server. What should Jack do?
    5·2 answers
  • To prepare a data character for transmission, a ____ bit is added to the beginning of the character and informs the receiver tha
    11·1 answer
  • ) A popular PivotChart that is used in Access is (Points : 4) column.
    9·1 answer
  • Why are computers useful for modeling situations?
    13·2 answers
  • Why it is not recommended to add sound effect on slide transition? Write at least two reasons.​
    6·1 answer
  • What is text formatting?​
    5·2 answers
  • What is the output for the following code?<br><br> print (5*4+5)
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!