I need help Specifying which member function is being called in everyline that h
ID: 3814932 • Letter: I
Question
I need help Specifying which member function is being called in everyline that has a //? at the end of it!
Please this is due by the end of the day!
Problem 2. Specify which member function is being called in each line.
#include <iostream>
#include <string>
using namespace std;
void main()
{
//Specify which member function is being called in the following lines
string s1("ABCD"); // ?
string s2; // ?
s2 = "XYZ"; // ?
string s3 = s1; // ?
s1 = s2; // ?
s2 = 'O'; //?
cout << "s1=" << s1 << endl;
cout << "s2=" << s2 << endl;
cout << "s3=" << s3 << endl;
}
/* string class member functions
(1) string ();
(2) string (const string & str);
(3) string (const char * s);
(4) string & operator= (const string & str);
(5) string & operator= (const char * s);
(6) string & operator= (char c);
*/
Explanation / Answer
HI, I have specified corresponding function call at each line.
#include <iostream>
#include <string>
using namespace std;
void main()
{
//Specify which member function is being called in the following lines
string s1("ABCD"); // (3) string (const char * s);
string s2; // (1) string ();
s2 = "XYZ"; // (5) string & operator= (const char * s);
string s3 = s1; // (2) string (const string & str);
s1 = s2; // (4) string & operator= (const string & str);
s2 = 'O'; //(6) string & operator= (char c);
cout << "s1=" << s1 << endl;
cout << "s2=" << s2 << endl;
cout << "s3=" << s3 << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.