Write a C++ ProgramString Processing: Use the string processing functions we covered in class (length(), size(), find(  ), substr(  ), at( ), erase( ), insert( ), replace( ) and append in the problems below. Remember if you need to reset a file to the beginning you can use infile.seekg(0, ios::beg);1.0 Given the text file UAH_sample.txt(details below) write a program that performs the following tasks:Find and count all words that are from 1 to 10 letters long. Print the results to the screen as a table.Special circumstances:You should not count punctuation at the end of the sentence as part of the word. Just erase the punctuation or subtract 1 from the length.Do not count numbers as words.You do not need to remove apostrophes. Just count that as part of the length.Multiple words connected by dashes, like state-of-the-art, can be counted as one long word.                                       Count the number of times each letter (A_Z, a-z) appears in the file. Print (to the screen) a table of each letter and the number of times it appears. You do not need separate counts for upper and lowercase. Ignore all characters that are not letters. Given an input letter find and print to the screen all words that begin with that letter. Check for both uppercase and lowercase letters beginning a word. Show results for letters a, r and u.Using the original UAH_sample.txt file replace each occurrence of UAHuntsville with UAH. Create a new file with the updated text. Upload the new file to canvas along with your other documents.UAH_sample.txt - Being a Charger is about more than just fitting in; it's about standing out and being a leader on campus and in the community. To help, we've created a strong leadership program to enable you to excel outside of the classroom and make a smooth transition from collegian to careerist skills you can also learn by joining one of UAHuntsville's many student-run organizations or holding a position in the Student Government Association. No matter what role you choose, at UAHuntsville your student experience is just as valuable as your education.

Question
Asked Feb 13, 2020
1 views

Write a C++ Program

String Processing: Use the string processing functions we covered in class (length(), size(), find(  ), substr(  ), at( ), erase( ), insert( ), replace( ) and append in the problems below. Remember if you need to reset a file to the beginning you can use infile.seekg(0, ios::beg);

1.0 Given the text file UAH_sample.txt(details below) write a program that performs the following tasks:

  • Find and count all words that are from 1 to 10 letters long. Print the results to the screen as a table.
    • Special circumstances:
      • You should not count punctuation at the end of the sentence as part of the word. Just erase the punctuation or subtract 1 from the length.
      • Do not count numbers as words.
      • You do not need to remove apostrophes. Just count that as part of the length.
      • Multiple words connected by dashes, like state-of-the-art, can be counted as one long word.                                       

Count the number of times each letter (A_Z, a-z) appears in the file. Print (to the screen) a table of each letter and the number of times it appears. You do not need separate counts for upper and lowercase. Ignore all characters that are not letters. 

  • Given an input letter find and print to the screen all words that begin with that letter. Check for both uppercase and lowercase letters beginning a word. Show results for letters a, r and u.
  • Using the original UAH_sample.txt file replace each occurrence of UAHuntsville with UAH. Create a new file with the updated text. Upload the new file to canvas along with your other documents.

UAH_sample.txt - Being a Charger is about more than just fitting in; it's about standing out and being a leader on campus and in the community. To help, we've created a strong leadership program to enable you to excel outside of the classroom and make a smooth transition from collegian to careerist skills you can also learn by joining one of UAHuntsville's many student-run organizations or holding a position in the Student Government Association. No matter what role you choose, at UAHuntsville your student experience is just as valuable as your education.

check_circle

Expert Answer

Program description

Due to the complex and multipart nature of the problem we have attempted to provide solution to only the first few subparts of the problem. The program has been described in detail by inlined comments.

C++ Program
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
//create file inputstream object to read data file
ifstream inData;
inData.open("UAH_sample.txt");
//declare variable to read each input word
string word;
//declare and initialize word count
int wordCount = 0;
//declare variables to hold the word length of each input word
//and the last character of each input word to be used in the
//while loop below
int wordLength;
char lastChar;
//read the words in the data file in the while loop
while(!inData.eof()){
inData >> word;
//find if the word is a number by reading the first character
//here it is assumed that words with starting character as a digit
//is a number. If the word is a number then ignore this word and
//go to the next iteration of the loop
if(isdigit(word.at(0)))
continue;
//find the word length
wordLength = word.length();
//find the last character of the current word
char lastChar = word.at(wordLength-1);
//update the word length by ignoring the special characters at the end
if(lastChar == ';' || lastChar == '.' || lastChar == ',' || lastChar == '?'){
wordLength--;
//update the word by stripping the last special character
word = word.substr(0,wordLength);
}
//if the word length is less than equal to 10 then output the word
//and update the word count
if (wordLength <= 10){
cout << word << endl;
wordCount++;

}
}
//output the word count
cout << "The number of words having length less than equal to 10: " << wordCount << endl;

inData.close();
return0;
}
Program image

Computer Science homework question answer, step 3, image 1

...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: INPUT CONTROLS ANDNETWORKINGA global manufacturing company has over 100subsidiaries worldwide report...

A: Data security problems and control procedures: Problem 1:The headquarters received transmitted data ...

question_answer

Q: "Should information systems be designed with society's needs for security in mind as well as that of...

A: Security:Security aspect of information system is one of the important factors to be consider.Mainta...

question_answer

Q: A file named prices.txt contains an unknown number of lines, each consisting of a literal float valu...

A: Following questions ask about to calculate the following things in the python file :Creating the fil...

question_answer

Q: What are patches and service packs?

A:  Patches: A patch is a small piece of software that is used to correct a problem in another software...

question_answer

Q: What happens if you try to multiply a string by a string, "a" * "b"?

A: In certain languages like python, multiplying a string with an int is allowed. However, multiplying ...

question_answer

Q: How do regular Data Back-ups help to protect businesses from threats like Ransomware?

A: Ransomware is a malware type that encrypts the files of a victim. The attacker then asks the victim ...

question_answer

Q: 1.  Discuss  the  activies  involved  in  designing  a  website. 2.Discuss  a  site  map  and  its  ...

A: We are authorized to answer one question at a time, since you have not mentioned which question you ...

question_answer

Q: Explain the difference between “A” and ‘A’ in C source code

A: The difference between “A” and ‘A’: The difference is, ‘A’ is a character and “A” is a string. The c...

question_answer

Q: Systems Analysis and Design   What is an effective way to assess user requests for additional featur...

A: Effective way to user assessment:For bringing in additional features and functions, user feedback ab...