Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

willing to give lifesaver Write a program that will read in a sentence of up to

ID: 3547541 • Letter: W

Question

willing to give lifesaver


Write a program that will read in a sentence of up to 100 characters and output

the sentence with spacing corrected and with letters corrected for capitalization.

In other words, in the output sentence all strings of two or more blanks should be

compressed to a single blank. The sentence should start with an uppercase letter

but should contain no other uppercase letters. Do not worry about proper names;

if their first letter is 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 the sentence ends with a period and contains

no

other periods. For example, the input

    

the    Answer to life, the Universe, and  everything

IS 42.

   should produce the following output:

   

The answer to life, the universe, and everything is 42.

Explanation / Answer

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cctype>
#include <cstdlib>
using namespace std;


char *RemoveSpaces(char *source);

string makeUpper (const string& s);

string makeLower (const string& s);



char *RemoveSpaces(char *source)
{
char *dest, *ret = dest = source;
while( *(isspace(*source) ? dest : dest++) = *source++ );

return ret;
}


//Uses <cctype> and <string>
string makeUpper(const string& s)
{
string temp(s);
char c = toupper('a');
printf ("c");

for (int i = 0; i < s.length(); i++)
temp[i] = toupper(s[i]);

return temp;
}

string makeLower(const string& s)
{
string temp(s);
char c = tolower('A');
printf ("c");

for (int i = 1; i < s.length(); i++)
temp[i] = tolower(s[i]);

return temp;

}


int main()

{
char str[100];
printf ("Enter a sentence");

scanf("%s%d", str);

return 0;
}
// OUTPUT
//Enter a sentence dsgsdgsf s ds gs
//Press any key to continue . . .