Do not prompt the user for input during the execution of your program. Write a p
ID: 3692180 • Letter: D
Question
Do not prompt the user for input during the execution of your program.
Write a program named Lab3.cpp. The program should satisfie the requirements specified in chapter 10, program challenge #5, Sentence Capitalizer with the following exceptions: instead of asking the user to input a string and passing it to the function, initialize the C-string with the following string:
"no, not tonight. it's a very popular place and you have to make reservations in advance. besides, it's expensive, and I don't have any money."
The modified string should look like:
"No, not tonight. It's a very popular place and you have to make reservations in advance. Besides, it's expensive, and I don't have any money."
The punctuation marks that signal the end of a sentence are the period, the question mark and the exclamation mark.
So your code should work with sentences that end with the question mark and the exclamation mark too.
Yes, your program needs to include the main function that prepares the C-string and calls the function as written there in the book.
Explanation / Answer
#include<iostream>
#include<stdio.h>
#include<ctype.h>
#include <stdlib.h>
using namespace std;
int main()
{
int i;
char a[]="no, not tonight. it's a very popular place and you have to make reservations in advance. besides, it's expensive, and I don't have any money";
for(i=0;a[i]!='';++i)
{
if(i==0)
{
if(islower(a[i]))
a[i]=toupper(a[i]);
}
else
{
if(a[i] == '.' || a[i] == '?')
{
int k=i+1;
while(k <= i+3){//after '.' or '?' it sees for 4 non empty positions only(ex: i am. i do)
if(a[k] != ' '){
if(islower(a[k])){
a[k]=toupper(a[k]);
break;
}
}
k++;
}
}
/*else
{
i++;
if(islower(a[i]))
a[i]=toupper(a[i]);
}*/
}
}
cout<<" New string is: "<<a;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.