// Program 4.8.1 #include #include using namespace std; int main () { char str1[10] = "Hello"; char str2[10] = "World"; char str3[10]; string str4 = "Hello"; string str5 = "World"; string str6; int len1, len2 ; cout << "==============================="<< endl; cout << "Copy string"<< endl; cout << "-------------------------------"<< endl; str6 = str4; cout << "str6 : " << str6 << endl; strcpy( str3, str1); cout << "strcpy( str3, str1) : " << str3 << endl< "<< str4 < "<< str4 < "; cout << str4[4] <
// Program 4.8.1
#include <iostream>
#include <cstring>
using namespace std;
int main ()
{
char str1[10] = "Hello";
char str2[10] = "World";
char str3[10];
string str4 = "Hello";
string str5 = "World";
string str6;
int len1, len2 ;
cout << "==============================="<< endl;
cout << "Copy string"<< endl;
cout << "-------------------------------"<< endl;
str6 = str4;
cout << "str6 : " << str6 << endl;
strcpy( str3, str1);
cout << "strcpy( str3, str1) : " << str3 << endl<<endl;
cout << "==============================="<< endl;
cout << "Concatenates string"<<endl;
cout << "-------------------------------"<< endl;
str6 = str4 + str5;
cout << "str4 + str5 : " << str6 << endl;
strcat( str1, str2);
cout << "strcat( str1, str2): " << str1 << endl<<endl;
cout << "==============================="<< endl;
cout << "String Length"<< endl;
cout << "-------------------------------"<< endl;
len2 = str6.size();
cout << "str6.size() : " << len2 << endl;
len1 = strlen(str1);
cout << "strlen(str6) : " << len1 << endl;
cout << "str6.length() : " << str6.length()<<endl<<endl;
cout << "==============================="<< endl;
cout << "Insert String"<< endl;
cout << "-------------------------------"<< endl;
str4 = str5 ;
str4.insert (5, "s");
cout << "str4.insert (5, ''s'') World --> "<< str4 <<endl<<endl;
cout << "==============================="<< endl;
cout << "Erase String"<< endl;
cout << "-------------------------------"<< endl;
str4.erase (3);
cout << "str4.erase (3), Worlds --> "<< str4 <<endl<<endl;
cout << "==============================="<< endl;
cout << "Capture String"<< endl;
cout << "-------------------------------"<< endl;
str4.insert (3, "lds");
cout << "str4[4] , Worlds --> ";
cout << str4[4] <<endl<<endl;
cout << "==============================="<< endl;
cout << "Compare String"<< endl;
cout << "-------------------------------"<< endl;
char str7 [20]= "Dog";
char str8 [20]= "Chicken";
char str9 [20]= "Cow";
cout << "str7=" << str7 << " , strlen(str7) : " << strlen(str7)<< endl;
cout << "str8=" << str8 << " , strlen(str8) : " << strlen(str8)<< endl;
cout << "str9=" << str9 << " , strlen(str9) : " << strlen(str9)<< endl<<endl;
cout << "strcmp(str7, str8) : " << strcmp(str7, str8) <<endl;
cout << "strcmp(str8, str9) : " << strcmp(str8, str9) <<endl;
cout << "strcmp(str7, str9) : " << strcmp(str7, str9) <<endl<<endl;
cout << "==============================="<< endl;
return 0;
}
TASK
1. Explain in details what the program does?
2. What is the output
![4.8
Strings 1
cout < "strien(str6) :"<< len1 << endl;
cout << "str6.length(): "<< str6.length()<cendiccendl;
// Program 4.8.1
#include <iostream>
#include <cstring>
cout << " I----
"<< endl;
using namespace std;
cout < "Insert String"<< endl;
cout <<
"<< endl;
int main ()
str4 = strs;
str4.insert (5, "s");
cout << "str4.insert (5, "s") World --> "<< stra <cendi<cendl;
char str1[10] = "Hello":
char str2[10] = "World";
char str3(10);
string str4 = "Hello";
string str5 = "World";
string str6;
cout << " u---
="<< endl;
cout << "Erase String"<< endl;
cout ce "-
"< endl;
str4.erase (3);
cout << "str4.erase (3), Worlds --> "<< stra <cendl<cendl;
int len1, len2 ;
cout << "w -
"< endl;
cout << "mu=------
="c< endl;
cout < "Copy string"<< endl;
cout << "Capture String"<< endl;
cout <<
"<< endl;
cout <<
"< endl;
str4.insert (3, "Ids");
cout <« "stra[4], Worlds --> ";
cout << stra[4] <cendi<cendl;
str6 - str4;
cout << "str6
:"<« str6 << endl;
strcpy( str3, stri);
cout < "strcpy( str3, str1) : "<< str3 <« endikcendl;
cout << "a ------------=-----------="<< endl;
cout « "Compare String"<< endl;
cout << "s =--------
"<< endi;
cout << ".
"<< endl;
cout < "Concatenates string"<cendl;
-"«< endl;
char str7 [20]= "Dog";
char str8 (20]= "Chicken";
char str9 (20]= "Cow";
Cout <e ".
str6 - str4 + str5;
cout << "strd + strs
:" << str6 << endl;
cout << "str7u" << str7 <<"
strlen(str7) : "<< strlen(str7)<< endl;
cout << "str8=" c< str8 < ", strien(str8) : "<< strlen(str8)<< endl;
cout << "str9="<< str9 <<"
strcat( stri, str2);
cout << "strcat( str1, str2): "<< stri << endikcendl;
, strlen(str9) : "<< strien(str9)<< endkcendl;
"< endl;
cout << "w
cout < "String Length"<< endl;
cout « "strcmp(str7, str8) : "<< strcmp(str7, str8) <<endl;
cout << "strcmp(str8, str9) : "<< strcmp(str8, str9) <cendl;
cout « "strcmp(str7, str9) : "<< strcmp(str7, str9) <<endkcendl;
cout <<
"< endl;
len2 = str6.size();
cout << "str6.size() : "<< len2 < endl;
leni = strlen(str1);
cout << "= -------------------------"<< endi;
return 0;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6bf2d9af-bce8-4161-8d1c-58cb73ffb3e0%2F4a91b6bf-6ca8-424c-9a08-31df877ffb83%2F38nm2m5_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









