The program will start by asking the user to enter a multi-word sentence. The program will then the
program will rotate the sentence and print out the rotated sentence. Moreover, the first letter of each word of sentence must be capitalized. All other words must be in lower case.
program will rotate the sentence and print out the rotated sentence. Moreover, the first letter of each word of sentence must be capitalized. All other words must be in lower case.
#include "stdafx.h"
#include <iostream>
#include "conio.h"
#include "vector"
#include <sstream>
using namespace std;
int _tmain(int argc)
{
char sentence[1000];
bool cap_it = true;
cout << "enter your sentence.\n";
cin.getline(sentence, 1000);
for (int i = 0; i < strlen(sentence); i++)
{
if (isalpha(sentence[i]) && cap_it == true)
{
sentence[i] = toupper(sentence[i]);
cap_it = false;
}
else
if (isspace (sentence[i]))
cap_it = true;
}
cout << endl << endl;
istringstream converter(sentence);
vector<string> words((istream_iterator<string>(converter)), istream_iterator<string>());
copy(words.rbegin(), words.rend(), ostream_iterator<string>(cout, " "));
getch();
return 0;
}
No comments:
Post a Comment