I am new here. Any idea how I can get this function in c++?
a.) Member function name: generateUsername
b.) Parameters: 2 strings. First parameter is first name and the second represents last name respectively
c.) Return Type: string
d.) Purpose: should return the first letter of the person’s first name combined with their last name. So, a person who has a first name, Joe and last name, Crow, will get the username JCrow.
the string + operator works with individual letters.
you can say
gen = fname + lname;
to do this -- just wrap that up in a function as per your book/notes on functions. Give it a try... post your effort if you get stuck again.
string Converter::generateUsername(string fname, string lname)
fname = fname.substr( 0, 1); // get the first letter in fname
username = fname + lname; // joing fname and lname string to form username
would this be correct?
'works' - yes. Correct - no.
fname, lname are passed by value rather than by ref - so a copy is undertaken. There is no need to have a separate variable username. Also jonnin comments.