Question

In: Computer Science

Write a progrm that accepts two strings as input, then indicates if the two strings are...

Write a progrm that accepts two strings as input, then indicates if the two strings are equal when the case of individual letters is ignored.

Sample runs are shown below. Use C++

Enter two strings.
String 1: PROgraM
String 2: proGram

PROgraM and proGram are equal.
Enter two strings.
String 1: litter
String 2: LittLe

litter and LittLe are not equal.

Solutions

Expert Solution

C++ code:

#include <iostream>
using namespace std;
int main(){
//initializing 2 strings
string string1,string2;
//asking for them
cout<<"Enter two strings."<<endl;
//asking for String 1
cout<<"String 1: ";
//accepting it
cin>>string1;
//asking for String 2
cout<<"String 2: ";
//accepting it
cin>>string2;
//checking if their lengths are not equal
if(string1.length()!=string2.length())
//printing they are not equal
cout<<"\n"<<string1<<" and "<<string2<<" are not equal."<<endl;
else{
//initializing flag as 0
int flag=0;
//looping till the end of the string
for(int i=0;i<string1.length();i++){
//converting current character of both strings to lower case and checking if they are equal
if(tolower(string1[i])!=tolower(string2[i]))
//setting flag as 1
flag=1;
}
//checking if flag is 0
if(flag==0)
//printing they are equal
cout<<"\n"<<string1<<" and "<<string2<<" are equal."<<endl;
else
//printing they are not equal
cout<<"\n"<<string1<<" and "<<string2<<" are not equal."<<endl;
}
return 0;
}


Screenshot:


Input and Output:


Related Solutions

Write code for a short method that does the following: accepts two strings as parameters, first...
Write code for a short method that does the following: accepts two strings as parameters, first name, and last name; Outputs the following message, concatenated together in one line of output:
Write a JAVA program that compares two strings input to see if they are the same?
Write a JAVA program that compares two strings input to see if they are the same?
Write an application that accepts up to 20 Strings, or fewer if the user enters the...
Write an application that accepts up to 20 Strings, or fewer if the user enters the terminating value ZZZ. Store each String in one of two lists—one list for short Strings that are 10 characters or fewer and another list for long Strings that are 11 characters or more. After data entry is complete, prompt the user to enter which type of String to display, and then output the correct list. For this exercise, you can assume that if the...
Write a program that reads two strings from an input file (The first line is X,...
Write a program that reads two strings from an input file (The first line is X, the second line is Y), compute the longest common subsequence length AND the resulting string. You will need to write 2 methods 1) return LCS length in iterative function // return the length of LCS. L is the 2D matrix, X, Y are the input strings, m=|X|, n=|Y| int lcs_it(int **C, string X, string Y, int m, int n ) 2) return LCS resulting...
Code in c# Write a recursive method called isReverse(String s1, String s2) that accepts two strings...
Code in c# Write a recursive method called isReverse(String s1, String s2) that accepts two strings as parameters and returns true if the two strings contain the same sequence of characters as each other but in the opposite order and false otherwise. • The recursive function should ignore capitalization. (For example, the call of isReverse("hello", "eLLoH") would return true.) • The empty string, as well as any one letter string, should be its own reverse. Write a driver program that...
Write a program that accepts a string and character as input, then counts and displays the...
Write a program that accepts a string and character as input, then counts and displays the number of times that character appears (in upper- or lowercase) in the string. Use C++ Enter a string: mallet Enter a character: a "A" appears 1 time(s) Enter a string: Racecar Enter a character: R "R" appears 2 time(s)
Write about strings and input (python). Explain with 2 examples
Write about strings and input (python). Explain with 2 examples
Write a complete MiniMIPS program that accepts a seqeunce of integers at input and after the...
Write a complete MiniMIPS program that accepts a seqeunce of integers at input and after the receipt of each new input value, displays the largest and smallest integers thus far. An input of 0 indicates the end of input values and is not an input value itself. Note that you do not need to keep all integers in memory.
Write a program that accepts as input the mass, in grams, and density, in grams per...
Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of the object using the formula: volume = mass / density. Format your output to two decimal places. ** Add Comments
Assume that a minus sign in the input indicates pop the stack and write the return...
Assume that a minus sign in the input indicates pop the stack and write the return value to standard output, and any other string indicates push the string onto the stack. Further, suppose that the following input is processed: it was - the best - of times - - it was - the - - 1/ What is written to the standard output? 2/What are the contents (top to bottom) left on the stack?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT