In this task you are required to find the common characters between strings according to certain rules and print out the result on the screen.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section: Chapter Questions
Problem 9PP
icon
Related questions
Question

In this task you are required to find the common characters between strings according to certain rules and print out the result on the screen.

 

In this task you are required to:

Write a program which takes two string inputs Str1 and Str2 in addition to the mode integer value.

If the value of the mode operation is not 0 or 1 then you have to print "Invalid"

According to mode value you have to do the following

mode=0: you have to print out the alphapatical characters that appears in Str1 but not in Str2. This operation is case sensitive which means that the lowercase and the uppercase of the same character are not the same. If the number of characters that meet this condition is 0 then you have to print None.

mode=1: you have to print out the alphapatical characters that appear in Str1 and Str2. This operation is case insensitive which means that you treat the uppercase and the lowercase letters the same. If the number of characters that meet this condition is 0 then you have to print None.

IMPORTANT NOTE

Do not add any cout statements except for the final answers as specified above.

Do not add "Enter a number", "the number of digits is" or any similar prompts.

Also note that it is case-sensitive; so "NONE" is wrong but "None" is correct.

Do not add any unnecessary spaces inside the strings of cout statements " " unless we ask you to.

You may add any libraries needed.

I/O

Program Input:

Two strings and one Integer number

Program Output:

One line that contains the characters that meet the operation specified by the mode without separations (not spaces)

Sample Testcase 0:

Input:

 

WElcome to C++

 

ear

 

0

 

Output:

 

WElcomtoC

Sample Testcase 1:

Input:

 

Welcome to C++

 

ear

 

1

 

Output:

 

ee

Sample Testcase 2:

Input:

 

Welcome to C++

 

ear

 

2

 

Output:

 

Invalid

Sample Testcase 3:

Input:

 

Welcome to C++

 

java

 

1

 

Output:

 

None

 

int main()

{

1

#include <iostream>

2

#include <ctime> // for time function

3

#include <cstdlib> // for rand and srand functions

4

using namespace std;

5

6

int main()

7

{

8

  string Str1, Str2;

9

  int mode;

10

  getline(cin, Str1);

11

  getline(cin, Str2);

12

  cin>>mode;

13

  //Your code Starts Here

14

15

16

  return 0;

17

18

}

19

20

Expert Solution
steps

Step by step

Solved in 2 steps with 5 images

Blurred answer
Knowledge Booster
Types of Expressions
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++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning