a) write c++ program that stops read a line of text when a period is entered and
ID: 3534183 • Letter: A
Question
a) write c++ program that stops read a line of text when a period is entered and displays the sentence with correct spacing and capitalization . for this program correct spacing mean only one space between words, and all letters should be lowercase , except the first letter. for example , if thr user enters the text i am going to Go To The movies..the displayed sentence should be I am going to go to the movies .
b) determine what characters , if any, are not displayed by program you ceated for exercise (a)
Explanation / Answer
#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<ctype.h>
void main()
{
clrscr();
int i,c=0,d=0;
char str[100],str1[100],str2[100];
cout<<"Enter a string:";
cin>>str;
i=0;
while(str[c]!='')
{
if(!(str[c]==' ' && str[c+1]==' '))
{
str1[d]=str[c];
d++;
}
c++;
}
str1[d]='';
int l=strlen(str1);
for(int j=0;j<l;j++)
{
str2[j]=tolower(str1[j]);
}
str2[0]=toupper(str2[0]);
for(j=0;j<strlen(str2);j++)
cout<<str2[j];
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.