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

I would really appreciate it if someone could help me with the following assignm

ID: 3601317 • Letter: I

Question

I would really appreciate it if someone could help me with the following assignment. thanks!

(starting code below)

#include <iostream>

#include <cstdlib>

#include <string>

using namespace std;

int main()

{

string str1;

string str2;

string str3;

string str4;

string str5;

str1 = "TodayIsTheFirstDayOfTheRestOfYourLife";

str2 = "AnAttitudeOfGratitude";

str3 = "AbsenceMakesTheHeartGrowFonder";

str4 = "AnAppleADayKeepsTheDoctorAway";

str5 = "ThisLabIsNowFinished";

return(0);

}

1) Write a C++ program using the initial C++ snippet attached as a starting point.

2) The snippet contains 5 different sentence strings, Each sentence string contains no spaces and a Capital Letter used to begin each word in each sentence. You are to write a function that will accept each string (one at a time) as input and output a new sentence string beginning with a capital letter and appropriate spaces between the new sentence structure.

3) You will need to write the above described function (step 2) and call it 5 times from the MAIN, once for each string defined in the snippet. For each sentence string print out the before and after sentence structure with the function call in between as proof the program and function are working properly.

Explanation / Answer

#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;
void convert(string s)   
{
int j=1,count=-1;
for(int i=0;i<s.length();i++) //This function counts number of capital letters which is later used to count number of white spaces required in the program
{
if(s[i]>=65&&s[i]<=90)
{
count++;
}
}
int tmp_size=s.length()+count; //size of temp should be equal to length of original string + number of white spaces to be inserted
char temp[tmp_size]; //array of character is declared
temp[0]=s[0]; //starting letter should be capital thus it is stored as it is
for(int i=1;i<s.length();i++)
{
if(s[i]>=65&&s[i]<=90) // if capital letter is encountered
{
temp[j]=' '; // white space is inserted
j++;
temp[j]=s[i]+32; //the capital letter is converted into small letter
j++;
}
else
{
temp[j]=s[i]; //if small letter is encountered it is stored as it is
j++;
}
}
cout<<"After Structure: ";
for(int i=0;i<tmp_size;i++)   
cout<<temp[i];
cout<<endl;
return;
}
int main()
{
string str1;
string str2;
string str3;
string str4;
string str5;

str1 = "TodayIsTheFirstDayOfTheRestOfYourLife";
str2 = "AnAttitudeOfGratitude";
str3 = "AbsenceMakesTheHeartGrowFonder";
str4 = "AnAppleADayKeepsTheDoctorAway";
str5 = "ThisLabIsNowFinished";

cout<<"Before Structure: "<<str1<<endl;
convert(str1);
cout<<"Before Structure: "<<str2<<endl;
convert(str2);
cout<<"Before Structure: "<<str3<<endl;
convert(str3);
cout<<"Before Structure: "<<str4<<endl;
convert(str4);
cout<<"Before Structure: "<<str5<<endl;
convert(str5);
return(0);

}