answer.
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
Lelechka
2 months ago
7

Write a loop that reads strings from standard input, where the string is either duck or goose. the loop terminates when goose is

read in. after the loop, your code should print out the number of duck strings that were read.
Computers and Technology
1 answer:
Amiraneli [1K]2 months ago
4 0
Consider that the code shown is in C++, however, the same concept can apply no matter the programming language used:

<span><iostream> 
using namespace std; 
int main() 
{ 
int count = 0; 
string input; 
while (true) 
{ 
cout << "Type either goose or duck"; 
cin >> input; 
if (input == "Goose") break; 
count++; 
} 

cout << "Ducks counted = " << count << endl; 
return 0; 
}
</span>
A simpler version can be implemented in Python as follows:
counter = 0 while True: line = input() if line == 'duck': counter += 1 elif line == 'goose': break print(counter)
You might be interested in
The president of the company wants a list of all orders ever taken. He wants to see the customer name, the last name of the empl
zubka84 [1067]

Response:

refer to the explanation

Clarification:

Examine the SQL statement shown below:

SELECT c.CustomerName, e.LastName, s.ShipperName, p.ProductName, o.Quantity, od.OrderDate

FROM

Customers c, Employees e, Shippers s, Orders o, OrderDetails od, Products p

WHERE c.customerID = o.customerID AND

e.employeeID = o.employeeID AND

o.orderID = od.orderID AND

od.shipperID = s.shipperID AND

od.productID = p.productID;

6 0
2 months ago
You work in the educational software industry. Your boss asks you to give a brief lecture to other employees about the digital d
Harlamova29_29 [1022]
Joe mama is the most extraordinary person on the planet.
5 0
2 months ago
Read 2 more answers
Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with a
8_murik_8 [964]

Answer:

Below is the JAVA program:

import java.util.Scanner;   //to take input from user

public class Main {  //name of the class

  public static void main(String[] args) {  //beginning of main method

      Scanner input = new Scanner(System.in);  //creates Scanner instance

      int integer = input.nextInt();  //defines and collects an integer for the number of words

      String stringArray[] = new String[integer]; //initializes an array to hold strings

      for (int i = 0; i < integer; i++) {  //iterates through the array

          stringArray[i] = input.next();         }  //collects strings

      int frequency[] = new int[integer];  //creates an array for holding frequencies

      int count;         //initializes variable to calculate frequency of each word

      for (int i = 0; i < frequency.length; i++) {  //iterates through frequency array

          count = 0;  //sets count to zero

          for (int j = 0; j < frequency.length; j++) {  //iterates through array

              if (stringArray[i].equals(stringArray[j])) {  //checks if element at ith index matches jth index

                  count++;                 }            }  //increments count

          frequency[i] = count;      }  //stores count in the frequency array

      for (int i = 0; i < stringArray.length; i++) {  //iterates through the string array

          System.out.println(stringArray[i] + " " + frequency[i]);         }    }    } //displays each word and its frequency

Explanation:

To illustrate the program, consider:

let integer = 3

for (int i = 0; i < integer; i++) is used to input strings into stringArray.

On the first pass:

i = 0

0<3

stringArray[i] = input.next(); takes a word and saves it to the ith index of stringArray. For example, if the user types "hey", it will be in stringArray[0].

Then, i increments to i = 1

On the second pass:

i = 1

1<3

stringArray[i] = input.next(); takes another word and assigns it to stringArray[1]. If the user enters "hi", then hi will be in stringArray[1]

Next, i becomes i = 2

On the third pass:

i = 2

2<3

stringArray[i] = input.next(); captures a word and places it in stringArray[2]. If the user types "hi", it goes to stringArray[2]

Then, i increments to i = 3

The loop terminates since i<integers is false.

The next outer loop for (int i = 0; i < frequency.length; i++) and inner loop for (int j = 0; j < frequency.length; will check each word and if (stringArray[i].equals(stringArray[j])) identifies any duplicates. Words that repeat will have their count incremented and the frequency array will record these values. For example, hey appears once while hi shows up twice, thus resulting in the final outputs:

hey 1

hi 2

hi 2

The visual representation of the program and its outcome based on the example provided is attached.

4 0
2 months ago
Technological improvements have allowed people to inhabit a wider variety of places more easily. Please select the best answer f
zubka84 [1067]

True. Technological advances have simplified and accelerated life, making it easier for people to live in a broader range of locations. Purchasing land or a home from a developer is one example of how this facilitates obtaining a desired place.

9 0
2 months ago
Read 2 more answers
Other questions:
  • . Electricians will sometimes call ______ "disconnects" or a "disconnecting means."
    12·1 answer
  • When you add a zero to the right of a decimal number, it multiplies its value by 10 (For example, "15" becomes "150"). What simi
    10·1 answer
  • What are the 2 things you are not sure about evaluating functions​
    7·2 answers
  • More Loops: All versions of foods.py in this section have avoided using for loops when printing to save space. Choose a version
    13·1 answer
  • Assign max_sum with the greater of num_a and num_b, PLUS the greater of num_y and num_z. Use just one statement. Hint: Call find
    5·1 answer
  • Q2 - Square Everything (0.25 points) Write a function called square_all that takes an input called collection that you assume to
    7·1 answer
  • Write a Scheme predicate function that tests for the structural equality of two given lists. Two lists are structurally equal if
    13·1 answer
  • In QlikView, ________ are used to search information anywhere in the document.
    8·1 answer
  • Java Programming home &gt; 1.14: zylab training: Interleaved input/output Н zyBooks catalog Try submitting it for grading (click
    6·1 answer
  • Social networking sites like Office Online, PayPal, and Dropbox are used to develop social and business contacts.
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!