// 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] <

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

// 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;
Transcribed Image Text: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;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY