Write a C++ program that gets two strings from input and stores them in variables such as str1 and str2. Then you should delete all possible str1 in str2. Note that after deletion of str1 in str2, you need to check again the inclusion of str1 in str2. That means the final printed result at the screen shouldn’t include any str1.
Str1? ab
Str2? sksaabbkjsdaabbksjkabksjsababaaab
Result? skskjsdksjkksjsaa
Solution-
#include<conio.h> #include<iostream> #include<String.h> #include<stdio.h> using namespace std; //-------defining global variables and initializing them------------- string str1,str2; char str3[256]; bool a= true; void String1(); int main() { char redo; //--------Printing my name on screen---------------- cout<< "Welcome to the program 2.3 written by Your Name"<<endl; cout<<"**************************************************************************"<<endl; cout<<endl<<endl<<endl; //--here do loop is used so that the program can be used more then one time //without exiting the run screen--------------------------- cout<<"\nEnter the First string: "; cin>>str1; cout<<"\nEnter the Second string:"; cin>>str2; while(a) { String1(); } cout<<"New String after deleting first string from second : "<<endl<<str2; cout<<endl<<endl; cout<<"enter y or Y to continue:"; cin>>redo; cout<<endl<<endl; getch(); } void String1() { //-------defining local variables and initializing them------------- int len1,len2; int len3,k=0,b=0, match=0,i,j,count=0; len1=str1.length(); len2=str2.length(); for(i=0;i<len2;i++) { b=i; for(j=0;j<len1;j++) { if(str2[b]==str1[j]) { match= match+1; b=b+1; } else break; } if(match!=len1) { match=0; str3[count]=str2[i]; count++; } else { match=0; a=true; i=i+len1-1; } } str2=str3; if(str2.length()==len2) { a=false; } str3[0]='\0'; for(int i=0;i<len2;i++) str3[i]='\0'; }
- C++ Simple Programs And Examples
- C++ – Hello World Program
- C++ – Simple calculator
- C++ – Even and Odd
- C++ – Swap two numbers
- C++ – Prime Number
- C++ – Find Perfect Number
- C++ – Factorial of Number
- C++ – Fibonacci Series
- C++ – Human Resource Management Program
- C++ – Calculate number of characters, words, sentences
- C++ – Subtract two Strings
- C++ – Processing of the Students structure
- C++ – Program with Matrices
- C++ – Calculate Equation
- C++ – Arrange Numbers in Ascending order
- C++ – Check Armstrong Number
- C++ – HCF and LCM
- C++ – Square Root of a Number
- C++ – Cube Root of a Number
- C++ – ASCII Code for Characters and numbers
- C++ – Check Palindrome Number
- C++ – Bubble sort
- C++ – Random Number Generator
- C++ – Sum of ODD Numbers in the Given Range
- C++ – Display current date and time
- Formula Based Programs
- C++ – Leap Year
- C++ – Surface Area and volume of cone
- C++ – Solve Quadratic equation
- String Based Programs
- C++ – String into Upper case or lower case
- C++ – Concatenate Strings
- Array Based Programs
- C++ – Program with Matrices
- Print Any Patterns
- C++ – Print 5 rows of 10 Stars (*)
- C++ – Half Pyramid of Stars (*)
- C++ – Half Pyramid of numbers
- C++ – Print Triangle of Stars
- C++ – Display Reverse pyramid.
- C++ – Print Alphabet Pattern
- C++ – Diamond of Star
- C++ – Pascal Triangle
- C++ – Floyd Triangle
- C++ Conversion
- C++ – Convert decimal to Hexadecimal
- C++ – Decimal to Binary
- C++ Sorting algorithms & Techniques
- C++ – Bubble Sort
- C++ – Insertion Sort
- C++ – Selection Sort
- C++ – Merge Sort
- C++ – Quick Sort
- C++ Handling Files
- C++ – How to get Current Directory in Linux/Windows
- C++ – How Create a Text File and Write in It
Leave a Reply