Please help me with this C++ Program?Strings Can you please help me with this, I
ID: 3559359 • Letter: P
Question
Please help me with this C++ Program?Strings
Can you please help me with this, Im trying but i cant figure it out
: In this experiment you will investigate the declaration, initialization, and implementation of C++ style strings.
#include
#include
using namespace std;
int main()
{
string my_name = "Thomas Jefferson";
string her_name("Michelle Obama");
string his_name = my_name;
cout << "my_name = " << my_name << endl;
cout << "The length of my_name is " << my_name.length() << endl;
cout << "The size of my_name is " << sizeof(my_name) << endl << endl;
cout << "her_name = "<
cout << "The length of her_name is " << her_name.length() << endl;
cout << "The size of her_name is " << sizeof(her_name) << endl << endl;
his_name = "Barack Obama";
cout << "his_name = " << his_name << endl;
cout << "The length of his_name is " << his_name.length() << endl;
cout << "The size of his_name is " << sizeof(his_name) << endl << endl;
string their_name;
their_name = my_name + " " + her_name
+ " " + his_name + " " + my_name + " ";
cout << "their_name = " << their_name << endl;
cout << "The length of their_name is " << their_name.length() << endl;
cout << "The size of their_name is " << sizeof(their_name) << endl;
return 0;
}
Question 1: What does the length obtained from the stringname.length() member function represent? Is it the same or different for each string?
Question 2: What does the size obtained from the sizeof() function represent? Is it the same or different for each string? Why?
Question 3: Please write three statements from the program which a constructor is used. Name the type of each constructor (explicit-value, copy, etc).
Question 4: Whats the name of the types of string operations that were performed in the program.
Explanation / Answer
1. It reprasents the total lenght of the string Ex:- my_name.lenght = 16 as "Thomas Jefferson" has 16 characters.
2.It reprasents the amount of memory(in bytes) used for that string. As char takes two bytes in my computer it outputs 8 for the size of my_name.
3.
string her_name("Michelle Obama"); this is explicit value constructor
string my_name = "Thomas Jefferson"; same as above but written differently
string their_name; This is empty string constructor (default constructor) :-Constructs an empty string, with a length of zero characters.
4.
the operations used are called appending operations as the append more than one string
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.