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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education