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. 

February 13, 2019
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;
}

No comments:

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();
Powered by Blogger.