DSA5_Activity_C_String (1)
DSA5_Activity_C_String (1)
Syntax A #include<iostream>
#include<iostream> #include<string>
#include<string> using namespace std;
using namespace std;
void TestA(string);
void sample(string); void TestB(string);
int main() int main()
{ {
string first; string myString;
cout<<"Enter some string: "; cout<<"Enter some string: ";
getline(cin,first); getline(cin,myString);
for (int X = 0; X<first.size(); X++) cout<<myString<<endl;
{ TestA(myString);
cout<<first[X];
continuation
}
cout<<endl; TestB(myString);
for (int X = 0; X<first.size(); X++) return 0;
{ }
cout<<first.at(X);
} void TestA(string A){
return 0; A.erase(2,5);
} cout<<A<<endl;
}
#include<iostream>
#include<string>
using namespace std;
void testSearch(string,string);
int main()
{
string haystack = "I am who I am";
string needle = "who";
testSearch(haystack,needle);
needle = "WHO";
testSearch(haystack,needle);
return 0;
}
Syntax K
#include<iostream>
#include<string>
using namespace std;
int main()
{
string first, second;
cout<<"Enter first string: ";
getline(cin,first);
cout<<"Enter second string: ";
getline(cin,second);
if(first.compare(second)==0){
cout<<"Identical Strings";
Syntax J }
#include<iostream> else{
#include<string> cout<<"Not Identical";
using namespace std; }
return 0;
int main() }
{
string A = "j";
string B = "J";
cout<<A.compare(B)<<endl;
cout<<B.compare(A)<<endl;
cout<<B.compare("J")<<endl;
return 0;
}
Instructions: Provide the answer for the following tables. Provide solution for the programming problems below.
str.size()
str.length()
str.empty()
str.clear()
str[index]
str.at(index)
str.append(string)
str.assign(string)
str.assign(str,int,int)
str.push_back(char)
str.insert(int,string)
str.erase(int,int)
str.replace(int,int,string)
str.swap(string)
str.substr(int,int)
str.find(string)
str.rfind(string)
str.find_first_of(string)
str.find_last_of(string)
str.compare(string)
stoi(string)
to_string(int)
Programming:
Provide your analysis and solution of the following problems by writing and executing a C++ syntax.
Upload the screenshot of your program output in a legal-size document.
Upload your C++ codes in text editor file (ex. Notepad) with Courier New Size 11 single space
font