HW4 - Chapter 5 - Loops a Collapse context Strings Write a program that finds the number of times a specific word appears in a text file. The program should accept the following inputs from the user: • The word that you are looking for. The word length should be 3 or more otherwise the program should print Too short. The word should not have a space character. The name of the file that contains the text • The type of the search 0 for case senstive search • 1 for case insensitive search For any other input the program should output Invalid o Note that the word should be preceded and succeeded by spaces.
HW4 - Chapter 5 - Loops a Collapse context Strings Write a program that finds the number of times a specific word appears in a text file. The program should accept the following inputs from the user: • The word that you are looking for. The word length should be 3 or more otherwise the program should print Too short. The word should not have a space character. The name of the file that contains the text • The type of the search 0 for case senstive search • 1 for case insensitive search For any other input the program should output Invalid o Note that the word should be preceded and succeeded by spaces.
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
write a code only in C++ language, don't copy solution of java language please
![HW4 - Chapter 5 - Loops a Collapse context
Strings
Write a program that finds the number of times a specific word appears in a
text file. The program should accept the following inputs from the user:
• The word that you are looking for. The word length should be 3 or more
otherwise the program should print Too short. The word should not
have a space character.
• The name of the file that contains the text
• The type of the search
o 0 for case senstive search
o 1 for case insensitive search
• For any other input the program should output Invalid
• Note that the word should be preceded and succeeded by spaces.
Note: Assume for all sample test cases that thecontent of F1.txt is:
C++ is a general-purpose programming language created by Bjarne
Stroustrup as an extension of the C programming language, or "C with
Classes". The language has expanded significantly over time, and modern
C++ now has object-oriented, generic, and functional features in addition to
facilities for low-level memory manipulation. It is almost always implemented
as a compiled language, and many vendors provide c++ compilers, including
the Free Software Foundation, LLVM, Microsoft, Intel, Oracle, and IBM, so it is
available on many platforms.
1/0
Program Input:
• A single line that takes in the word that you are searching for
●
A single line that takes in the name of the file that contains the
text
• A single line that takes in the type of the search
Program Output:
• A single line that outputs either the number of occurences of the
word in the textfile.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Feffdb143-691e-409b-99be-a253dfb80097%2F4f646d45-2b35-47e6-b177-0fc84ca4090e%2Fy5w7xs_processed.jpeg&w=3840&q=75)
Transcribed Image Text:HW4 - Chapter 5 - Loops a Collapse context
Strings
Write a program that finds the number of times a specific word appears in a
text file. The program should accept the following inputs from the user:
• The word that you are looking for. The word length should be 3 or more
otherwise the program should print Too short. The word should not
have a space character.
• The name of the file that contains the text
• The type of the search
o 0 for case senstive search
o 1 for case insensitive search
• For any other input the program should output Invalid
• Note that the word should be preceded and succeeded by spaces.
Note: Assume for all sample test cases that thecontent of F1.txt is:
C++ is a general-purpose programming language created by Bjarne
Stroustrup as an extension of the C programming language, or "C with
Classes". The language has expanded significantly over time, and modern
C++ now has object-oriented, generic, and functional features in addition to
facilities for low-level memory manipulation. It is almost always implemented
as a compiled language, and many vendors provide c++ compilers, including
the Free Software Foundation, LLVM, Microsoft, Intel, Oracle, and IBM, so it is
available on many platforms.
1/0
Program Input:
• A single line that takes in the word that you are searching for
●
A single line that takes in the name of the file that contains the
text
• A single line that takes in the type of the search
Program Output:
• A single line that outputs either the number of occurences of the
word in the textfile.
![Input:
C++
F1.txt
1
Output:
3
Sample Testcase 1:
Input:
C++
F1.txt
0
Output:
1
Sample Testcase 2:
Input:
C++
F1.txt
2
Output:
Invalid
1 #include <iostream>
2 #include <fstream>
3 using namespace std;
4
5
6
int main()
7
{
8
char filename [20]; // Use this variable to
read the name of the file that contains the
text.
int mode;
string word;
cin>>word>> filename>>mode;
9
10
11
12
13 }
14](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Feffdb143-691e-409b-99be-a253dfb80097%2F4f646d45-2b35-47e6-b177-0fc84ca4090e%2F6et03xj_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Input:
C++
F1.txt
1
Output:
3
Sample Testcase 1:
Input:
C++
F1.txt
0
Output:
1
Sample Testcase 2:
Input:
C++
F1.txt
2
Output:
Invalid
1 #include <iostream>
2 #include <fstream>
3 using namespace std;
4
5
6
int main()
7
{
8
char filename [20]; // Use this variable to
read the name of the file that contains the
text.
int mode;
string word;
cin>>word>> filename>>mode;
9
10
11
12
13 }
14
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
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](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education