Write a program that reads words from standard input and displays them to standard output. When the word "end" is read, print it out and then stop reading input.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
**Learning Objectives:**

- **[Remember]** Students will recall how to read from standard input.
- **[Apply]** Students will write loops that iterate as long as a condition is true.

**Task:**

Write a program that reads words from standard input and displays them to standard output. When the word "end" is read, print it out and then stop reading input.

**Code Explanation:**

Below is a simple C++ program framework provided to achieve the task:

```cpp
#include <iostream>
using namespace std;

/*
 * Reads and displays words from standard input until hitting a stop word.
 */
int main() {

    return 0;
}
```

### Code Details:

- **Line 1-2:** Includes the necessary C++ library `iostream` and uses the standard namespace (`std`). This allows access to standard input and output stream objects.
  
- **Lines 4-7:** Contains a comment block describing the purpose of the program, which is to read and display words from standard input until a stop word is encountered.

- **Line 9:** Declares the `main` function where the execution of the program begins. It currently lacks the implementation of reading from standard input.

- **Line 11:** Returns 0 to indicate that the program executed successfully, although more code is needed for its functionality.

**Additional Notes:**

To complete this task, students need to add a loop and input reading mechanism within the `main` function. The goal is to continuously read inputs until "end" is encountered, which involves understanding loop constructs and conditional statements in C++.
Transcribed Image Text:**Learning Objectives:** - **[Remember]** Students will recall how to read from standard input. - **[Apply]** Students will write loops that iterate as long as a condition is true. **Task:** Write a program that reads words from standard input and displays them to standard output. When the word "end" is read, print it out and then stop reading input. **Code Explanation:** Below is a simple C++ program framework provided to achieve the task: ```cpp #include <iostream> using namespace std; /* * Reads and displays words from standard input until hitting a stop word. */ int main() { return 0; } ``` ### Code Details: - **Line 1-2:** Includes the necessary C++ library `iostream` and uses the standard namespace (`std`). This allows access to standard input and output stream objects. - **Lines 4-7:** Contains a comment block describing the purpose of the program, which is to read and display words from standard input until a stop word is encountered. - **Line 9:** Declares the `main` function where the execution of the program begins. It currently lacks the implementation of reading from standard input. - **Line 11:** Returns 0 to indicate that the program executed successfully, although more code is needed for its functionality. **Additional Notes:** To complete this task, students need to add a loop and input reading mechanism within the `main` function. The goal is to continuously read inputs until "end" is encountered, which involves understanding loop constructs and conditional statements in C++.
**Learning Objective (LO):** Apply loops to iterate over every value in a range.

Some marathon organizers are advertising race distances using kilometers. Help them explain the races to participants unfamiliar with the metric system by printing a line for each race length that explains its approximate length in miles.

The races are organized in increments of 5 km: 5 km, 10 km, and so forth, up to 40 km. There are approximately 0.621 miles in a kilometer. Miles should be rounded to the nearest whole number. Follow this format:

**A 5km race is approximately 3 miles long.**

---

**Code Explanation:**

```cpp
#include <iostream>
using namespace std;

/*
 * Displays how long each race is in kilometers and miles.
 */

int main() {
    return 0;
}
```

This code snippet is an initial setup in C++ for a program that will calculate and display the approximate length of various races in miles based on their kilometer measurement. The main function is currently empty, which means implementation code for the calculation needs to be added.
Transcribed Image Text:**Learning Objective (LO):** Apply loops to iterate over every value in a range. Some marathon organizers are advertising race distances using kilometers. Help them explain the races to participants unfamiliar with the metric system by printing a line for each race length that explains its approximate length in miles. The races are organized in increments of 5 km: 5 km, 10 km, and so forth, up to 40 km. There are approximately 0.621 miles in a kilometer. Miles should be rounded to the nearest whole number. Follow this format: **A 5km race is approximately 3 miles long.** --- **Code Explanation:** ```cpp #include <iostream> using namespace std; /* * Displays how long each race is in kilometers and miles. */ int main() { return 0; } ``` This code snippet is an initial setup in C++ for a program that will calculate and display the approximate length of various races in miles based on their kilometer measurement. The main function is currently empty, which means implementation code for the calculation needs to be added.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education