Answer to Question #236032 in C++ for SOM

Question #236032

 Create a class which stores a string and its length as data members. Include all the constructors. Include a member function to join two strings and display the 

concatenated string. 

1
Expert's answer
2021-09-11T23:39:57-0400
#include <iostream>


using namespace std;


class StringA{
    private:
        string str;
        int length;
    public:
        StringA (string s ){
            str=s;
        }
        
        void conc_string(string s2){
            string s3=str+s2;
            cout<<"\nConcatenated string= "+s3;
        }
};
int main()
{
    StringA s("Hello");
    s.conc_string(" world");


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS