You are working on a text mining project where you have to do some operations on text.  Develop a C++ console application that does the following:   Prompt for and get two strings from the user (each string has more than 10 characters). Print the length of each string. Convert the 5th character of the first string to an uppercase character and print it. Convert the 10th character of the second string to a lowercase character and print it. Output values should be printed with left and right justified label Look at the sample input and output and check your console with two different inputs.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question

You are working on a text mining project where you have to do some operations on text.  Develop a C++ console application that does the following:

 

  1. Prompt for and get two strings from the user (each string has more than 10 characters).
  2. Print the length of each string.
  3. Convert the 5th character of the first string to an uppercase character and print it.
  4. Convert the 10th character of the second string to a lowercase character and print it.
  5. Output values should be printed with left and right justified label
  6. Look at the sample input and output and check your console with two different inputs.
Expert Solution
Step 1

Below is the required C++ program: -

Explanation: -  

  • Importing the essential headers and namespace.
  • Defining the main function.
  • Declaring the variables.
  • Prompts the user to enter two strings.
  • Using the while-loop that continuously ask the user to enter the strings with more than 10 characters.
  • Displaying the length of both strings.
  • Using the two for-loop to iterate over the both strings and displaying the 5th character of first string as uppercase and 10th character of second string as lowercase letter.
Step 2

Code: -

//headers

#include <iostream>

#include <iomanip>

#include <string.h>

//namespace

using namespace std;

//Defining the main function

int main()

{

    //Declaring the variables

    string str1;            //to store first string

    string str2;            //to store second string

    //Prompts the user to enter two strings

    cout<<"Enter two strings with more than 10 characters:\n";

    //Storing the strings

    cin>>str1>>str2;

   //continuously ask the user to enter the string with more than 10 characters

    while(!(str1.length() > 10 && str2.length() > 10))

    {

        cout<<"Please enter the both strings with more than 10 characters:\n"<<endl;

        //Storing the strings

        cin>>str1>>str2;

    }

    //Displaying the length of both strings

    cout<<"The length of both string are: "<<left<<str1.length()<<setw(10)<<right<<str2.length()<<endl;

    //cout<<left<<setw(10)<<"The length of second string is: "<<str2.length()<<endl;

    //Using the first for-loop to iterate over the first string

    for(int i = 0; i<str1.length(); i++)

    {

        //for the character stored at 4 index(5th character)

        if(i==4)

        {

            //Displaying the 5th character as uppercase

            cout<<"The fifth character as uppercase is: "<<left<<setw(10)<<(char)toupper(str1[i])<<right<<endl;

        }

    }

    for(int i = 0; i<str2.length(); i++)

    {

        //for the character stored at 9 index(10th character)

        if(i==9)

        {

            //Displaying the 10th character as lowercase

            cout<<"The tenth character as lowercase is: "<<left<<setw(10)<<(char)tolower(str2[i])<<right<<endl;

        }

    }

}

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning