4. Write a program that reads a file one character at a time and prints out how many times each of the vowels a e io u occur (in upper- or lowercase). Complete the following code. vowels.cpp 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 int main() 8 ( 9 string vowels = "aeiou"; 10 11 12 13 14 15 16 ASASENEG 18 20 22 23 24 } int counters [] = {0, 0, 0, 0, 0); cout << "Input file: " << endl; string input file name; cin >> input file_name; for (int i = 0; i < vowels.length(); i++) { cout << vowels[i]<<":"<< counters [i] << endl; } return 0;
4. Write a program that reads a file one character at a time and prints out how many times each of the vowels a e io u occur (in upper- or lowercase). Complete the following code. vowels.cpp 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 int main() 8 ( 9 string vowels = "aeiou"; 10 11 12 13 14 15 16 ASASENEG 18 20 22 23 24 } int counters [] = {0, 0, 0, 0, 0); cout << "Input file: " << endl; string input file name; cin >> input file_name; for (int i = 0; i < vowels.length(); i++) { cout << vowels[i]<<":"<< counters [i] << endl; } return 0;
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
Related questions
Question
![The image contains an exercise related to programming in C++. It prompts the user to write a program that reads a file one character at a time and counts the occurrences of each vowel (a, e, i, o, u), regardless of case. Below is the transcribed code and accompanying instructions:
---
**4. Write a program that reads a file one character at a time and prints out how many times each of the vowels a e i o u occur (in upper- or lowercase). Complete the following code.**
**vowels.cpp**
```cpp
#include <iostream>
#include <string>
#include <fstream>
#include <cctype>
using namespace std;
int main() {
string vowels = "aeiou";
int counters[] = {0, 0, 0, 0, 0};
cout << "Input file: " << endl;
string input_file_name;
cin >> input_file_name;
. . .
for (int i = 0; i < vowels.length(); i++) {
cout << vowels[i] << ": " << counters[i] << endl;
}
return 0;
}
```
At the bottom, there are two buttons labeled "CodeCheck" and "Reset".
---
### Explanation of the Code:
1. **Libraries Included:**
- `<iostream>`: For input and output streams.
- `<string>`: To use the string class.
- `<fstream>`: To handle file operations.
- `<cctype>`: Offers functions to check character types such as lowercase or uppercase.
2. **Main Function:**
- Initializes a string `vowels` containing "aeiou".
- Initializes an array `counters` with zeroes to hold the count of each vowel.
- Prompts the user to input the file name.
- Contains a loop that iterates over the `vowels` string to output the count of each vowel.
3. **Incomplete Section (marked by `. . .`):**
- The section where the file is opened, read character by character, and the counting logic for each vowel is implemented is missing.
### Usage:
This program template is designed for students learning file I/O operations and character counting in C++. The task is to complete the missing logic to successfully perform the vowel counting.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc8525d30-f731-4576-a11c-639afeb912cb%2F522b1b82-68f7-472d-9c3c-533520b1d1af%2Fxnwiom9_processed.jpeg&w=3840&q=75)
Transcribed Image Text:The image contains an exercise related to programming in C++. It prompts the user to write a program that reads a file one character at a time and counts the occurrences of each vowel (a, e, i, o, u), regardless of case. Below is the transcribed code and accompanying instructions:
---
**4. Write a program that reads a file one character at a time and prints out how many times each of the vowels a e i o u occur (in upper- or lowercase). Complete the following code.**
**vowels.cpp**
```cpp
#include <iostream>
#include <string>
#include <fstream>
#include <cctype>
using namespace std;
int main() {
string vowels = "aeiou";
int counters[] = {0, 0, 0, 0, 0};
cout << "Input file: " << endl;
string input_file_name;
cin >> input_file_name;
. . .
for (int i = 0; i < vowels.length(); i++) {
cout << vowels[i] << ": " << counters[i] << endl;
}
return 0;
}
```
At the bottom, there are two buttons labeled "CodeCheck" and "Reset".
---
### Explanation of the Code:
1. **Libraries Included:**
- `<iostream>`: For input and output streams.
- `<string>`: To use the string class.
- `<fstream>`: To handle file operations.
- `<cctype>`: Offers functions to check character types such as lowercase or uppercase.
2. **Main Function:**
- Initializes a string `vowels` containing "aeiou".
- Initializes an array `counters` with zeroes to hold the count of each vowel.
- Prompts the user to input the file name.
- Contains a loop that iterates over the `vowels` string to output the count of each vowel.
3. **Incomplete Section (marked by `. . .`):**
- The section where the file is opened, read character by character, and the counting logic for each vowel is implemented is missing.
### Usage:
This program template is designed for students learning file I/O operations and character counting in C++. The task is to complete the missing logic to successfully perform the vowel counting.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images

Knowledge Booster
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.Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education