The problem is not the lower and upper case the problem is the quotation marks. The sentence, "StopAndSmellTheRoses" prints as " stop and smell the roses", I need it to print "Stop and smell the roses". Both of these codes print the same output.
Can an expert please rewrite one of these codes so that the first character read as upper case and still read the quotation marks, please.
input: "StopAndSmellTheRoses"
output: "Stop and smell the roses"
Could you please rewrite the program in C++ according to the instructions and criteria that accepts as input a sentence in which all the words are run together, but the first character of each word is upper cases. Convert the sentence to a string in which the words are separated by spaces and only the first word starts with an upper-case letter. For example, the string "StopAndSmellTheRoses." would be converted to "Stop and smell the roses." This program reads the " as the first character, so the output is " stop and smell the roses." I need it to read "Stop and smell the roses."
Criteria
1) program compiles
2) program solves problem according to specification
3) program declares, creates, or initializes static or dynamic array correctly
4) if required program defines function or functions with array parameters or array returns
5) program uses arrays to solve problem
6) program destroys any dynamic arrays
#include <iostream>
using namespace std;
int main()
{
char sentence[1000],answer[1000];
cout<<"Enter sentence:"<<endl;
cin>>sentence;
answer[0]=sentence[0];
int j=1;
for(int i=1;sentence[i]!='\0';i++)
{
if((int)sentence[i]>=65 && (int)sentence[i]<=90)
{
answer[j]=' ';
j=j+1;
answer[j]=sentence[i]+32;
}
else
answer[j]=sentence[i];
j++;
}
for(int i=0;i<answer[i]!='\0';i++)
{
cout<<answer[i];
}
}
Expert Answer
The problem with the above solution is, you have copied the first character as it is in the final array.
answer[0] = sentence[0]; will copy the first character as it is without changing it to upper case.
To change the lower case character to upper case, we can use built-in function of string.h library "toupper()"
Hence, the updated lines will be:
answer[0] = toupper(sentence[0]);
Updated code:
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char sentence[1000],answer[1000];
cout<<"Enter sentence:"<<endl;
cin>>sentence;
answer[0] = toupper(sentence[0]);
int j=1;
for(int i=1;sentence[i]!='\0';i++)
{
if(isupper(sentence[i]))
{
answer[j]=' ';
j=j+1;
answer[j]=sentence[i]+32;
}
else
answer[j]=sentence[i];
j++;
}
for(int i=0;i<answer[i]!='\0';i++)
{
cout<<answer[i];
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
- Select all alternatives that are correct related to variable names. a. It can have symbols in the middle or at the end. O b. It can not have digits at the end. C. It cannot start with a symbol, except__. O d. It can start with a digit. e. It can start with a capital letter.arrow_forwardWrite code in python using repetition to create the following patterns 999999999888888887777777666666555554444333221Note; create means you must create with program code, not just assign it as a literal. The problemWrite a program that asks the user for an integer between 1 and 25 and then generates the pattern that many times. Advice: there are two issues to deal with for this program – getting the number and printing out the pattern that many times. A systematic approach is to 1. get your program working to print the pattern once, (a loop)2. expand your program to print it multiple times, (nested loop_)3. Expand to include the request for the number of times.arrow_forwardI want solution with stepsarrow_forward
- In each question below, provide a brief explanation, a formula and the numerical value for your answer (exact if the answer is an integer, approximate otherwise). There are 94 printable characters on a standard North American keyboard, comprised of the 26 upper case letters A-Z, the 26 lower case letters a-z, the 10 numerical digits 0-9 and the 32 special characters. For our purposes, passwords are strings consisting of printable characters. The length of a password is the number of characters in the password. Suppose we want a password space with entropy 128 bits, assuming that each pass- words is equally likely, i.e. a total of 2^128 passwords (this number is typical for key space sizes of modern cryptosystems). Assuming no restrictions on the characters appearing in passwords ex- cept that they be printable, what is the minimum password length that guarantees a password space with entropy 128?arrow_forwardYou will be reading in a series of names from the keyboard. Count how many matching pairs there are – a matching pair is when two consecutive names are equal regardless of their case - and print the pairs. Input stops when the word ‘end’ is entered (also ignoring case). For example, Jack Jose jose Faith Robert Cynthia cynthia Cynthia Pierre ENd would print: Jose jose Cynthia cynthia cynthia Cynthia There were 3 matching pairs.arrow_forwardCan you give me two ways to do itarrow_forward
- Im stuck on this java code. The code is supposed to ask user for a string. Characters that are number, are doubled and replaced with the sum. The characters that are upper are replaced with lower and lower are replaced with upper. It should keep asking user for string until user input Q to end the program. example 1: original: 3rD converted: 6Rd ex 2: original: 6sJ converted: 3Sj (when a value is doubled and its than 9, the two digits are added. so 6 * 2 is 12. And then add the two digits. so 1 + 2 = 3.) I'm having problem with the code that its not reading where it replace the lower to upper and vice versa. this is my code so far: import java.util.Scanner;public class Convert {public static void main(String[] args) {Scanner input = new Scanner(System.in);String original, converted;while (true) {System.out.print("Original String (input):");original = input.nextLine();if (original.equals("q") || original.equals("Q")) {break;}char[] chars = original.toCharArray();for (int i = 0; i <…arrow_forwardPlease do not give solution in image format thanku Write a python program that does the following. Make sure it works and can interface with the user in PyCharm. Write a function word count that will take a sentence (string) and return to you the number of words in the sentence. Show it works by calling it with “Cinderella must get to the ball without her slippers.” (Answer should be 9)arrow_forwardComplete the following program that collects an input word from the keyboard and finds if the word is palindrome. A word is palindrome if the sequence of characters are the same from left-to-right and right-to-left, for example, "dad", "racecar" or "rotor" are all palindrome words because they can be read the same either forward or backward. word = input ("Entera word: ") 1s_palindrome = True i = -1 for if word[j] != word[1]: if not is palindrome: else: i-1 is palindrome = False print ("word is palindrome") jin range(len(word)) i+1 -1 print ("word is not palindrome") len(word) jin wordarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education