Click to See Complete Forum and Search --> : Anyone help with Sentance program?


Daywalker-
October 31st, 2007, 04:25 PM
Can anyone help me, i dont know where to start or what to do for this program. Any help would be greatly appricated!


Write a C++ main program that stops reading text when a period is entered. The program then displays the “sentence” with corrected spacing and capitalization. This means only one blank between words, no blank before punctuation, no blanks before the first word, only the first letter of the first word capitalized and all the other letters in lower case. The program should allow multi-line entry.

For example,
This program removes extra spaces and corrects capitalization
Please enter a sentence ending with a period.
iT cErtainly DOES nO good to TeLl a
fruStrateD user THAt : the prOGram, quite clearly
, teLLS you TO enter AN integeR .
It certainly does no good to tell a
frustrated user that: the program, quite clearly,
tells you to enter an integer.
Press any key to continue

Use cout for prompting the user and output. I would recommend cin.get() for character by character checking but you can use any method that works for you.

Daywalker-
October 31st, 2007, 04:48 PM
bump?

dglienna
October 31st, 2007, 06:20 PM
Sounds like homework to me. Try it yourself, and post in the C++ forum when you get stuck. Doesn't sound too hard.

Daywalker-
October 31st, 2007, 06:22 PM
Lol been on it for 2 hours, i got somewhat far.. but dont know a useful and fast codeing method. Especially to get rid of the extra spaces.

Daywalker-
October 31st, 2007, 06:57 PM
Really could use help.

Daywalker-
October 31st, 2007, 08:59 PM
I have a program but i am still running into problems from the objective sentence.

Also is there an easier way of writing these functions or a different way?
void fixspaces(string& sntc, int offset)//function for space
{
for(int i = offset; i < sntc.length(); i++)
{
sntc[i]=sntc[i+1];
}
sntc.resize( sntc.length() - 1 );// putting string to the left
}

int main()
{

int i;
string sntc = "";
char tmp;




cout << "Type in a sentence:";

do
{
tmp = cin.get();
sntc = sntc + tmp;
}while(tmp != '.');// sta
int ispunct(tmp) ;
cin.sync();

while (isspace(sntc[0]))
{
fixspaces(sntc, 0);
}

for(i=1;i<int(sntc.length());i++)

{


sntc[i]=tolower(sntc[i]);


}
for(i=1;i<int(sntc.length());i++)
{
if( isspace(sntc[i]) && isspace(sntc[i+1]) )
{
fixspaces(sntc, i);
i = 0;
}

}

for(i=0;i<(sntc.length());i++)
{

if( isspace(sntc[i]) && (sntc[i+1] == '.') )
{
sntc.erase(i,1);

i = 0;
}

}

sntc[0]=toupper(sntc[0]);

cout<< "The correct punctuation of what has been entered is:"
<<sntc<<endl;
return 0;
}