Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions 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
Check Mark
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;

        }

    }

}

bartleby

Step by stepSolved in 3 steps with 1 images

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