Asked Mar 22, 2020

I need a function that takes in a string& and returns a void that outputs a string with "my" at the beginning such as "Boat" becoming "my Boat".

Please help me with this problem using c++.


Expert Answer

Step 1: C++ Source Code

Note: Comments have been added in the source code itself to have a better understanding of the code.


//import the required package

#include <iostream>

using namespace std;

//write the prototype of the function

void display(string &str);

//definition of the main function

int main()


    //declare the required variable

    string a;

    //prompt the user to enter a word

    cout<<"Enter a word:";

    //get the input from the user


    //cll the function



    return 0;


//end of the main function


//definition of the function

void display(string &str)


    //declare and initialize the variable

    string result="my";

    //display the result

    cout<<result<<" "<<str<<endl;


Step 2: Screenshot of the Code

Computer Science homework question answer, step 2, image 1


Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A

Q: What are implicit heap-dynamic variables, when, how and why are they used, when should they not be u...

A: Implicit heap-dynamic variable: Implicit heap-dynamic variable is a bound which is executed in the ...


Q: Code an application that determines how many gallons of water is needed for a pool. Create Void Meth...

A: The program calculates the gallons of water required for completely filling the pool as per user des...


Q: A pentagonal number is defined as n(3n−1) ∕ 2 for n = 1, 2, . . ., etc.. Therefore, the first few nu...

A: //define a main class public class Pentagonal_Number {             //define the main function       ...


Q: What is the difference between the Screen and Overlay blending mode effect in Photoshop?

A: Difference between Screen and Overlay blending mode Screen blending mode is Photoshop’s most popular...


Q: What symbol is used in UML to denote inheritance? Group of answer choices a filled square a fille...

A: UML: UML stands for Unified Modeling Language. UML is an object-oriented analysis and design languag...


Q: hey I was wondering if someone could help me with e throght f in the document below thank you

A: Click to see the answer


Q: What is listed in the attributes section of a class diagram? The algorithms of the class The met...

A: The “variables” of the class are listed in the attributes section of a class diagram.


Q: PLEASE INCLUDE STEP BY STEP EXPLANATION52) For IEEE 754 single-precision floating point, what is the...

A: Since the answer is complex we include the solution to only the first part (a) Step 1: convert from ...


Q: ..• 6. Modify the following program so that it terminates, printing "Invalid input" as soon as an in...

A: PROGRAM: //Defining the header file import java.util.Scanner;   //Declaring the class with the name ...