Question 11: Write a program that accepts as input a sentence in which all of the words are run together, but the first character of each word is uppercase. Convert the sentence to a string in which the words are separated by spaces and only the first word starts with an uppercase letter.
Question 11: Write a program that accepts as input a sentence in which all of the words are run together, but the first character of each word is uppercase. Convert the sentence to a string in which the words are separated by spaces and only the first word starts with an uppercase letter.
/*
Name: Mudassar Ali
Roll: BCSF15M045 [Morning]
Assignment: No# 05
Teacher: Miss Sadia Shahzad
*/
#include <iostream>
using namespace std;
int main()
{
cout<<"\tThis programme will convert the string into meaningful form!!\n\n";
char str [500]; // To store the input string.
char strp[500]; // To store the contents of input string after punctuation.
int n=1; // For the output string.
cout<<"Enter the String: ";
cin>>str; // Input String.
strp[0] = str[0]; // Storing the the first content of the input string.
for(int i = 1; str[i]!='\0';i++) // Loop to convert the string
{
if(str[i]>='A'&& str[i]<='Z') // If Upper_case letter appears then converts it to lower-case
{
strp[n++]=' '; // To add space after converting the Second word capital letter into small letter.
strp[n++]=str[i]+32;
}
else // To store lower_case letter of string
{
strp[n]=str[i];
n++;
}
}
strp[n++]='.'; // To add the comma at the end of sentence.
strp[n]='\0'; // Placing the NULL at the end of Converted String.
cout<<"Formatted String Is: "<<strp; // Displaying the Converted String.
return 0;
}
/*
Name: Mudassar Ali
Roll: BCSF15M045 [Morning]
Assignment: No# 05
Teacher: Miss Sadia Shahzad
*/
#include <iostream>
using namespace std;
int main()
{
cout<<"\tThis programme will convert the string into meaningful form!!\n\n";
char str [500]; // To store the input string.
char strp[500]; // To store the contents of input string after punctuation.
int n=1; // For the output string.
cout<<"Enter the String: ";
cin>>str; // Input String.
strp[0] = str[0]; // Storing the the first content of the input string.
for(int i = 1; str[i]!='\0';i++) // Loop to convert the string
{
if(str[i]>='A'&& str[i]<='Z') // If Upper_case letter appears then converts it to lower-case
{
strp[n++]=' '; // To add space after converting the Second word capital letter into small letter.
strp[n++]=str[i]+32;
}
else // To store lower_case letter of string
{
strp[n]=str[i];
n++;
}
}
strp[n++]='.'; // To add the comma at the end of sentence.
strp[n]='\0'; // Placing the NULL at the end of Converted String.
cout<<"Formatted String Is: "<<strp; // Displaying the Converted String.
return 0;
}
No comments: