C++ Program Help
Prompt your user to enter a length of a word to search from a
string. Use forking to spawn a child process to perform the
counting task. Allow the child process to finish and output the
number of words found (if any), before prompting the user for the
next length. Count all words in the string with this
length and output the number of words that correspond to this
length. Program keeps asking user for length till user enters "0"
which terminates the program
EXAMPLE:
String: Hello I am posting on Chegg Study!
Output:
Enter word length : 5
Count: 3
Enter word length : 2
Count: 2
Enter word length : 0
Program ended
// do comment if any problem arises
// code
#include <iostream>
#include <sys/wait.h>
#include <unistd.h>
using namespace std;
int main()
{
// string to search for
string temp = "Hello I am posting on Chegg Study!";
while (true)
{
cout << "Enter word length: ";
int length;
// read length of word to search
cin >> length;
// exit condition
if (length == 0)
break;
// fork a child
if (fork() == 0)
{
// count is number of matches found
int count = 0;
// current length of current word while traversing string
int current = 0;
for (int i = 0; i < temp.length() + 1; i++)
{
// space or end of string
if (temp[i] == ' ' || temp[i] == '\0')
{
if (current == length)
count++;
current = 0;
}
else
{
// ignore punctuations
if (temp[i] == ',' || temp[i] == '.' || temp[i] == '!')
continue;
else
current++;
}
}
cout << "Count: " << count << endl;
exit(0);
}
else
{
wait(NULL);
}
}
cout << "Program ended\n";
}
Output:

Enter word length: 5 Count: 3 Enter word length: 2 Count: 2 Enter word length: 0 Program ended
C++ Program Help Prompt your user to enter a length of a word to search from...
Write a java program that keeps asking the user to enter a number until the user quits and prints how many even and how many odd numbers entered by the user. The loop terminates if the user enters -1 (it indicates that there will be no more number entering by the user). In other words, as long as the user doesn’t enter -1, the loop will be executed. Please add comments to the program to understand/ explain the code.
(1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue! You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews...
write a python program a) The program will prompt the user to enter the length of the two vertical sides. b) The length of the two horizontal sides will be twice as long as the length of the two vertical sides. c) The rectangle will be filled with the color green
Your program must prompt the user to enter a string. The program must then test the string entered by the user to determine whether it is a palindrome. A palindrome is a string that reads the same backwards and forwards, such as "radar", "racecar", and "able was I ere I saw elba". It is customary to ignore spaces, punctuation, and capitalization when looking for palindromes. For example, "A man, a plan, a canal. Panama!" is considered to be a palindrome....
write a program C++ that asks a user to enter a word from the following list (turtle, tree, tin). If they entered the word turtle, tell them they picked an animal. If they entered the word tree, tell them they picked a plant. If they entered the word tin, tell them they picked a mineral. If they did not enter one of these words, output an error message.
C++ please! (1) Prompt the user to enter the name of the input file. The file will contain a text on a single line. Store the text in a string. Output the string. Ex: Enter file name: input1.txt File content: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue! (2) Implement a PrintMenu() function,...
Write a C program where user enter a string input, tokenizer the string using space character. Calculate the lengh of string. Find word start. Find word end. Count words.
Hello, I have a assignment where the user inputs a word and the out will then tell the user how many of the five vowels are in the word so for example if I typed the word hello, it would output {0 1 0 0 0 } since there is only one vowel and that is e which is in the second row, I have most of it done, but I can't seem to figure out how to get the...
Python Error: Writing a program to complete the following: Prompt the user for the name of an input file. Open that file for input. (reading) Read the file using a "for line in a file" loop For each line, o print the line and compute and print the average word length for that line. Close the input file Sample output: MY CODE IS WRONG AND NEED HELP CORRECTING IT!!! ------------------------------------------------------------------------------------------------------------------------ DESIRED OUTPUT: Enter input file name: Seasons.txt Thirty days hath September...
This program asks the user to enter a word. It then tries to create a string with the minimum number of repetitions of the word necessary to make a string of length at least 20. Right now, it ends up making too long of a string in certain cases. For example, if you enter a word with eight letters, like "computer", the result should only have three copies of the word in order to meet the length requirement of 20:...