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

I am stuck on this for my programming assignment Write a function that takes a s

ID: 3703703 • Letter: I

Question

I am stuck on this for my programming assignment

Write a function that takes a string s and returns a new string that contains the first character of each word in s (you may assume that words are separated by a single space) but capitalized. For example, if we call this function with the string "International Business Machines" it should return "IBM" . If we call it with the string "Flint Lockwood Diatonic Super Mutating Dynamic Food Replicator" it should return "FLDSMDFR"

char * acronymizer(const char *s);

Explanation / Answer

#include<iostream>

using namespace std;

///////////////////// Declaration of the function ///////////////////////

string acronymizer(const string s);

/////////////////// Main Method ////////////////////////////////////////

int main()

{

///////////////////////// Input String /////////////////////////////////

string str = "Flint Lockwood Diatonic Super Mutating Dynamic Food Replicator";

  

///////////////////////// Function call ////////////////////////////////

cout << acronymizer(str);

return 0;

}

//////////////////////////// Definition of the function ///////////////////

string acronymizer(string s)

{

  

//////////////////// Declaring resultant string ////////////////

string output = "";

/////////////////// Traverse the string. ////////////////////////////

bool boo = true;

for (int i=0; i<s.length(); i++)

{

//////////////////// If it is space, set v as true. ///////////////////

if (s[i] == ' ')

boo = true;

//////////////////// else ///////////////////////////

//////////// If true, copy character in output string and set v as false. ///////

else if (s[i] != ' ' && boo == true)

{

output.push_back(s[i]);

boo = false;

}

}

////////////////// return output string to calling function ////////////////

return output;

}

//////////////////////////////////////// If you have any doubt please let me know in comment section ///////////////////////////////

//////////////////////////// Thank you ! Good Luck /////////////////////////

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote