
// 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;](https://content.bartleby.com/qna-images/question/6bf2d9af-bce8-4161-8d1c-58cb73ffb3e0/4a91b6bf-6ca8-424c-9a08-31df877ffb83/38nm2m5_thumbnail.png)

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- #include <iostream> #include <string> #include <cstdlib> using namespace std; template<class T> class A { public: T func(T a, T b){ return a/b; } }; int main(int argc, char const *argv[]) { A <float>a1; cout<<a1.func(3,2)<<endl; cout<<a1.func(3.0,2.0)<<endl; return 0; } Give output for this code.arrow_forwardC++ 6.34 #include <iostream>#include <cstdlib>#include <ctime>using namespace std; void guessGame(); // function prototypebool isCorrect( int, int ); // function prototype int main(){srand( time( 0 ) ); // seed random number generatorguessGame();} // end main // guessGame generates numbers between 1 and 1000 and checks user's guessvoid guessGame(){int answer; // randomly generated numberint guess; // user's guesschar response; // 'y' or 'n' response to continue game // loop until user types 'n' to quit gamedo {// generate random number between 1 and 1000// 1 is shift, 1000 is scaling factoranswer = 1 + rand() % 1000; // prompt for guesscout << "I have a number between 1 and 1000.\n" << "Can you guess my number?\n" << "Please type your first guess." << endl << "? ";cin >> guess; // loop until correct numberwhile ( !isCorrect( guess, answer ) ) cin >> guess; // prompt for another gamecout << "\nExcellent! You guessed the…arrow_forward#include <iostream>#include <cmath>#include <iomanip>using namespace std; int main() { double x; double y; double z; cin >> x; cin >> y; /* Your code goes here */ cout << fixed << setprecision(1); // setprecision(1) outputs z with 1 decimal place. cout << z << endl; return 0;} having trouble with this code in C++arrow_forward
- cout<<"Team name is is "< cout<<"The team got "<<no for (int i=0;i<no_of_medal cout<<medals[i]<< cout<<endl; Sport_team::~Sport_team() { delete []medals; cout<<"Memory free"<<endl } void f(Sport_team o) { cout<<"Team info print by o.print(); } void main() { Sport_team s; string n; int m; cout<<"Enter the sport's cin >>n ; cout<<"Enter number of me cin>>m; . set(n, m) ; s.print(); f(s) ; s.print();arrow_forward// Fix this program that works// Use welcome function that display the message in diffreent color// Use Draw function to diplay table in gree/yellow// Remove, add, any code that you believe is not useful#include <iostream>#include <windows.h> using namespace std;char mat[3][3];void table(); //function to print the tablevoid welcome(); //function for welcome screenint main(){ int i, j, m, n, sum = 0; char ch; welcome(); system("pause"); for (m = 0; m < 3; m++) for (n = 0; n < 3; n++) mat[m][n] ='W'; table(); while (sum < 10) { //================== for player 1 =================== cout << "Player 1 is X Choose the position : "; cout << "Row:"; cin >> i; cout << "Coloumn:"; cin >> j; //============== if position is wrong ============ for (; i > 3 || i < 1 || j>3 || j < 1 || ('x' == mat[i - 1][j - 1] || 'o'…arrow_forward#include<iostream> #include <cmath> using namespace std; int main() { float sp_Radius, sp_sa, sp_Volume; cout << "\nPlease Enter the radius of a Sphere = "; cin >> sp_Radius; sp_sa = 4 * M_PI * sp_Radius * sp_Radius; sp_Volume = (4.0/3) * M_PI * sp_Radius * sp_Radius * sp_Radius; cout << "\nThe Surface Area of a Sphere = " << sp_sa; cout << "\nThe Volume of a Sphere = " << sp_Volume; return 0; } C++ use this code and separate the program into three files. The main program containing the main function should be named main.cpp. The function definition file containing a function for the volume calculation and a function for the surface area calculation should be named SphereCalc.cpp. The function declaration file containing function declarations for the functions should be named SphereCalc.h. Make sure you include a Header Guard. Read the Radius from the Keyboard. If a negative number is provided, set the calculated value to zero.arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





