Write a program that reads in a paragraph up and outputs the paragraph with spac
ID: 3777145 • Letter: W
Question
Write a program that reads in a paragraph up and outputs the paragraph with spacing corrected and with letters corrected for capitalization in C++. In other words, in the output paragraph, all strings of two or more blanks should be compressed to a single blank. The sentences should start with an uppercase letter but should contain no other uppercase letters. Do not worry about proper names; if their first letters are changed to lowercase, that is acceptable. Treat a line break as if it were a blank, in the sense that a line break and any number of blanks are compressed to a single blank. Assume that all the sentences in the paragraph end with a period and contains no other periods, and the paragraph ends with an extra period.
Sample Input:
the Answer to life, the Universe, and everything
IS 42. This program Reads
in a line of text, counts
and outputs the number of words in
the line and the number of occurrences of each letter..
Sample Output:
The answer to life, the universe, and everything is 42. This program reads in a line of text, counts and outputs the number of words in the line and the number of occurrences of each letter.
Explanation / Answer
Here is the below code:
#include "StdAfx.h"
#include <iostream>
#include <cctype>
#include "windows.h"
using namespace std;
void cap(char input[]);
int main()
{
char input[100];
cout << "Greetings!" <<endl;
cout << "This program will ask for you to input a sentence." <<endl;
cout << "After you input your sentence, the program will" <<endl;
cout << "print your sentence back out with the first letter" <<endl;
cout << "of each word in capital form." << endl;
cout << "Please enter up to 99 characters" <<endl;
cin.getline(input, 100);
cap(input);
cout <<endl;
system("PAUSE");
return 0;
}
void cap(char input[])
{
if(input[0] != ' ')
input[0] = toupper(input[0]);
for (int count = 0; count <= 99; count++)
{
if(input[count] == ' ' || input[count]== ',' || input[count]==';' ||input[count]== '.')
input[count+1]=toupper(input[count+1]);
}
cout << input;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.