Question 2: Write a C++ program that accepts as input a string and capitalizes the first character of each sentence in the string and convert all other characters to small case.
Question 2: Write a C++ program that accepts as input a string and capitalizes the first character of each sentence in the string and convert all other characters to small case.
/*
Name: Mudassar Ali
Roll: BCSF15M045 [Morning]
Assignment: No# 05
Teacher: Miss Sadia Shahzad
*/
#include <iostream>
using namespace std;
int main()
{
cout<<"\tThis Programme will punctuate the input string!!\n\n";
char str[100]; // To store the sentence string
cout<<"Enter the sentence string:";
cin.getline(str,100) ; // Input the string with spaces.
if(str[0]>= 'a'&& str[0]<='z') // To Convert the First Letter Upper_case from lower_case.
str[0] = str[0]-32; // Storing at fist index value.
for(int i = 1; str[i]!='\0';i++)
{
if(str[i]=='.' || str[i]=='?') // Converting the letters to Upper_case after dot(.) and question (?) mark.
{
i+=2; // Increasing the index value by 2 due to (.) and space.
if(str[i]>='a' && str[i]<='z')
str[i] = str[i]-32; // Conversion of lower_case letters to Upper_case Letters.
}//end of if
else // Converting all others letters to lower_case.
{
if(str[i]>='A'&& str[i]<='Z')
str[i] = str[i]+32;
}//end of else
}//end of For Loop
cout<<"Punctuated string is:"<<str;
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 punctuate the input string!!\n\n";
char str[100]; // To store the sentence string
cout<<"Enter the sentence string:";
cin.getline(str,100) ; // Input the string with spaces.
if(str[0]>= 'a'&& str[0]<='z') // To Convert the First Letter Upper_case from lower_case.
str[0] = str[0]-32; // Storing at fist index value.
for(int i = 1; str[i]!='\0';i++)
{
if(str[i]=='.' || str[i]=='?') // Converting the letters to Upper_case after dot(.) and question (?) mark.
{
i+=2; // Increasing the index value by 2 due to (.) and space.
if(str[i]>='a' && str[i]<='z')
str[i] = str[i]-32; // Conversion of lower_case letters to Upper_case Letters.
}//end of if
else // Converting all others letters to lower_case.
{
if(str[i]>='A'&& str[i]<='Z')
str[i] = str[i]+32;
}//end of else
}//end of For Loop
cout<<"Punctuated string is:"<<str;
return 0;
}
No comments: