Question: With relation to the code I have given below can you guys help me answer these questions? #include #include #include using namespace std; int main()
With relation to the code I have given below can you guys help me answer these questions?
#include
#include
#include
using namespace std;
int main()
{
string name, rname;
string fname, mname, lname;
fname = mname = lname = "";
cout
cout
getline(cin, name);
fname = name.substr(0, name.find(' '));
if (fname.length()>0){
name = name.substr(fname.length()+1);
mname = name.substr(0, name.find(' '));
}
if (mname.length()>0){
if(mname.length() == name.length())
lname = "";
else
lname = name.substr(mname.length()+1);
}
if (lname.length()>0)
{
//Make all charecters lower first
for(unsigned short i=0;i
{
lname[i]=tolower(lname[i]);
}
for(unsigned short i=0;i
{
fname[i]=tolower(fname[i]);
}
for(unsigned short i=0;i
{
mname[i]=tolower(mname[i]);
}
//make first charecter upper
lname[0] = toupper(lname[0]);
fname[0] = toupper(fname[0]);
mname[0] = toupper(mname[0]);
rname = lname + ", " + fname + " "+ mname[0] + ".";
}
else
{
for(unsigned short i=0;i
{
fname[i]=tolower(fname[i]);
}
for(unsigned short i=0;i
{
mname[i]=tolower(mname[i]);
}
fname[0] = toupper(fname[0]);
mname[0] = toupper(mname[0]);
rname = mname + ", " + fname;
}
cout
cout
cout
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
