Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I wrote this program to see how these commands effect my program but can you ple

ID: 3622936 • Letter: I

Question

I wrote this program to see how these commands effect my program but can you please explain how the last one works? In other words, can you tell me what this mean? yourName.middle = myName.middle.at(0) + ".";

This is my program:

#include<iostream>
#include<string>
using namespace std;
int main()
{
struct Name

{
string first;
string middle;
string last;

};
Name yourName;
Name myName;

yourName.first = "George";
cout<<"After entering yourName.first = 'George' "<<endl<<endl<<
"The data in yourName.first is: "<<yourName.first<<endl<<
"The data in yourName.middle is: "<<yourName.middle<<endl<<
"The data in yourName.last is: "<<yourName.last<<endl<<
"The data in myName.first is: "<<myName.first<<endl<<
"The data in myName.middle is: "<<myName.middle<<endl<<
"The data in myName.last is: "<<myName.last<<endl<<endl;
yourName.last = "Smith";
cout<<"After entering yourName.last = 'Smith' "<<endl<<endl<<
"The data in yourName.first is: "<<yourName.first<<endl<<
"The data in yourName.middle is: "<<yourName.middle<<endl<<
"The data in yourName.last is: "<<yourName.last<<endl<<
"The data in myName.first is: "<<myName.first<<endl<<
"The data in myName.middle is: "<<myName.middle<<endl<<
"The data in myName.last is: "<<myName.last<<endl<<endl;
myName = yourName;
cout<<"After entering myName = yourName, "<<endl<<endl<<
"The data in yourName.first is: "<<yourName.first<<endl<<
"The data in yourName.middle is: "<<yourName.middle<<endl<<
"The data in yourName.last is: "<<yourName.last<<endl<<
"The data in myName.first is: "<<myName.first<<endl<<
"The data in myName.middle is: "<<myName.middle<<endl<<
"The data in myName.last is: "<<myName.last<<endl<<endl;
myName.middle = "Nathaniel";
cout<<"After entering myName.middle = 'Nathaniel', "<<endl<<endl<<
"The data in yourName.first is: "<<yourName.first<<endl<<
"The data in yourName.middle is: "<<yourName.middle<<endl<<
"The data in yourName.last is: "<<yourName.last<<endl<<
"The data in myName.first is: "<<myName.first<<endl<<
"The data in myName.middle is: "<<myName.middle<<endl<<
"The data in myName.last is: "<<myName.last<<endl<<endl;
yourName.middle = myName.middle.at(0) + ".";
cout<<"After entering yourName.middle = myName.middle.at(0) + '.';,"<<endl<<endl<<
"The data in yourName.first is: "<<yourName.first<<endl<<
"The data in yourName.middle is: "<<yourName.middle<<endl<<
"The data in yourName.last is: "<<yourName.last<<endl<<
"The data in myName.first is: "<<myName.first<<endl<<
"The data in myName.middle is: "<<myName.middle<<endl<<
"The data in myName.last is: "<<myName.last;





cin.get();cin.get();
return 0;
}

Explanation / Answer

please rate - thanks

that instruction isn't working properly, so I've rewritten it as 2 instructions--see red below

the + means concatenate, put them together

myName.middle.at(0) means take the first character (characters are counted starting at 0) of myName.middle, so take the first character of Nathaniel (take the N)

yourName.middle=yourName.middle + ".";

means add a . after the name.

so if my middle name is Nathaniel your middle name is N.


#include<iostream>
#include<string>
using namespace std;
int main()
{
struct Name

{
string first;
string middle;
string last;

};
Name yourName;
Name myName;

yourName.first = "George";
cout<<"After entering yourName.first = 'George' "<<endl<<endl<<
"The data in yourName.first is: "<<yourName.first<<endl<<
"The data in yourName.middle is: "<<yourName.middle<<endl<<
"The data in yourName.last is: "<<yourName.last<<endl<<
"The data in myName.first is: "<<myName.first<<endl<<
"The data in myName.middle is: "<<myName.middle<<endl<<
"The data in myName.last is: "<<myName.last<<endl<<endl;
yourName.last = "Smith";
cout<<"After entering yourName.last = 'Smith' "<<endl<<endl<<
"The data in yourName.first is: "<<yourName.first<<endl<<
"The data in yourName.middle is: "<<yourName.middle<<endl<<
"The data in yourName.last is: "<<yourName.last<<endl<<
"The data in myName.first is: "<<myName.first<<endl<<
"The data in myName.middle is: "<<myName.middle<<endl<<
"The data in myName.last is: "<<myName.last<<endl<<endl;
myName = yourName;
cout<<"After entering myName = yourName, "<<endl<<endl<<
"The data in yourName.first is: "<<yourName.first<<endl<<
"The data in yourName.middle is: "<<yourName.middle<<endl<<
"The data in yourName.last is: "<<yourName.last<<endl<<
"The data in myName.first is: "<<myName.first<<endl<<
"The data in myName.middle is: "<<myName.middle<<endl<<
"The data in myName.last is: "<<myName.last<<endl<<endl;
myName.middle = "Nathaniel";
cout<<"After entering myName.middle = 'Nathaniel', "<<endl<<endl<<
"The data in yourName.first is: "<<yourName.first<<endl<<
"The data in yourName.middle is: "<<yourName.middle<<endl<<
"The data in yourName.last is: "<<yourName.last<<endl<<
"The data in myName.first is: "<<myName.first<<endl<<
"The data in myName.middle is: "<<myName.middle<<endl<<
"The data in myName.last is: "<<myName.last<<endl<<endl;
yourName.middle = myName.middle.at(0);
yourName.middle=yourName.middle + ".";
cout<<"After entering yourName.middle = myName.middle.at(0) + '.';,"<<endl<<endl<<
"The data in yourName.first is: "<<yourName.first<<endl<<
"The data in yourName.middle is: "<<yourName.middle<<endl<<
"The data in yourName.last is: "<<yourName.last<<endl<<
"The data in myName.first is: "<<myName.first<<endl<<
"The data in myName.middle is: "<<myName.middle<<endl<<
"The data in myName.last is: "<<myName.last;





cin.get();cin.get();
return 0;
}