Implement a custom string class with public functions
1) combine which takes as argument two strings s1, s2 and appends s2 to s1.
2) replace which takes as argument two characters, and replaces all occurrences of the first character by the second character in the string, if the first character is found, otherwise replace returns NOT FOUND.
In the main program take two strings as input (on first line), then take two characters as input. Concatenate the two strings using combine. Replace the first character in the concatenated string (if found) with the second character.
Implement following public functions for the String Class.
Input:
The first two line contains two strings, string1 and string2. The second line contains two characters char1 and char2.
The two strings will contain only letters in English alphabet (both upper and lower case). The two characters will also be English letters.
Output:
First concatenate the two strings. In the result, all occurrences of char1 should be replaced with char2 and that should be printed out.If char1 is not present in the resultant string after concatenation, print NOT FOUND
Solution -:
After deadline is over although you can ask logic
1) combine which takes as argument two strings s1, s2 and appends s2 to s1.
2) replace which takes as argument two characters, and replaces all occurrences of the first character by the second character in the string, if the first character is found, otherwise replace returns NOT FOUND.
In the main program take two strings as input (on first line), then take two characters as input. Concatenate the two strings using combine. Replace the first character in the concatenated string (if found) with the second character.
Implement following public functions for the String Class.
- String String::operator+ (String str) : Create an new String object and copy the base String and then append content of String str.
- void String::replace (char oldChar, char newChar) : Replace the "oldChar" if found with "newChar"
- char * String::getCharArray(): Return a Character array with content of String.
- bool String::find (char c): Return true if the character is present in the string else false.
Input:
The first two line contains two strings, string1 and string2. The second line contains two characters char1 and char2.
The two strings will contain only letters in English alphabet (both upper and lower case). The two characters will also be English letters.
Output:
First concatenate the two strings. In the result, all occurrences of char1 should be replaced with char2 and that should be printed out.If char1 is not present in the resultant string after concatenation, print NOT FOUND
Solution -:
After deadline is over although you can ask logic
String String::operator+ (String str){
ReplyDeleteint i,j,a,b;char c[100];
String newStr;
a=this->size;b=str.size;
for(i=0;is[i];
}
for(j=0;jsize+str.size;
printf("%s",newStr.s);
return newStr;
}
void String::replace (char oldChar, char newChar) {
int a,i;
a=this->size;
for(i=0;is[i]==oldChar)
{
this->s[i]=newChar;
printf("%s",this->s[i]);
}
}
}
bool String::find (char c) {
int i;char *b;
b=this->s;
printf("%c",&b);
for(i=0;isize;i++)
{
if(b[i]==c)
{
return true;}}
return false;
}
char * String::getCharArray(){
char * str = new char[size+1];
str=this->s;
return str;
}
Input Expected Output Actual Output
hello
world
o a
hellawarld
helloworldNOT FOUND
which character gives in printf()???
String String::operator+ (String str){
ReplyDeleteint i,j,a,b;char c[100];
String newStr;
a=this->size;b=str.size;
for(i=0;isize;
for(i=0;is[i]=newChar;
printf("%s",this->s[i]);
}
}
bool String::find (char c) {
int i;char *b;
b=this->s;
printf("%c",&b);
for(i=0;is;
return str;
}
not getting plz help me out
Please anybody provide me code for it. I am helpless. Today is last date and I am not able to do it. Please help.
ReplyDeletehere in question what is the base string please help me
ReplyDeletenumber in a position programme's code ?
ReplyDelete