Question

How to return a form of the string in C++?? I know that string function has...

How to return a form of the string in C++??

I know that string function has to return a string like an int function returns an int variable.    

let's say I have a function named string printCircle(int number). In this function, how to return a form of the string as a circle?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

2 3 #include <iostream> #include <string> using namespace std; string printCircle(int number) string result = Radius of the

#include <iostream>
#include <string>
using namespace std;

string printCircle(int number)
{
string result = "Radius of the circle is ";
  
// changing the number to string and adding it to the result string
result += to_string(number);
  
return result;
}

int main() {
cout << printCircle(5);
}

/*
*** EXPLANATION ***

Define a string variable
Put the text whichever you needed in that
Return the string
*/

// Please up vote.

Add a comment
Know the answer?
Add Answer to:
How to return a form of the string in C++?? I know that string function has...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and...

    help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and an int parameter. If both string parameters represent binary numbers and the int parameter is equal to a positive number less than or equal to the length of the longest string parameter, the function should return a binary string whose length is equal to two times the length of the maximum length of the two string parameters whose value is equal to the sum...

  • How do I do this? -> string print() const; Function to output the data, return the...

    How do I do this? -> string print() const; Function to output the data, return the output in the form of string, with all elements in the hash table included and each seperated by a space this is my code: template <class elemType> string hashT<elemType>::print() const { for (int i = 0; i < HTSize; i++){        if (indexStatusList[i] == 1){        cout <<HTable[i]<< " " << endl;        }   }    } **********Rest of the code...

  • Define a Python function named getResponse() that takes a string as its only argument and returns...

    Define a Python function named getResponse() that takes a string as its only argument and returns a new string. If the argument ends with a question mark and has an even number of characters, the function should return the string "Yes". If the argument ends with a question mark and contains an odd number of characters, the function should return the string "No". If the argument ends with an exclamation point, the function should return the string "Wow". Otherwise, the...

  • How to find the length of an integer string in C language? I know that the...

    How to find the length of an integer string in C language? I know that the strlen() function only works for finding the length of a regular string, but I want to know how to find the length of an integer string in C language.

  • C++ ONLY Write a function, int flip(string a[], int n); It reverses the order of the...

    C++ ONLY Write a function, int flip(string a[], int n); It reverses the order of the elements of the array and returns n. The variable n will be greater than or equal to zero. Example: string array[6] = { "a", "b", "", "c", "d", "e" }; int q = flip(array, 4); // returns 4 // array now contains: "c" "" "b" "a" "d" "e" Write a function, int flip(string a[], int n); It reverses the order of the elements of...

  • Using recursion only (no loops allowed!), write a C++ function of the form int count7s(int)

    please do in c++Q4. Using recursion only (no loops allowed!), write a C++ function of the form int count7s(int) that when passed a non-negative integer, returns the number of occurrences of the digit 7 in the number. So, for example: count7s(717) → 2 count75(7) →1 count7s(123) → 0 Q5. Write a C++ function of the form string mirrorEnds(string)that when given a string, looks for a mirror image (backwards) string at both the beginning and end of the given string. In other words, zero or...

  • Help with programming in C++ Phase 1 is complete, please help with phase 2. Thank you....

    Help with programming in C++ Phase 1 is complete, please help with phase 2. Thank you. Phase 1 You must design 3 algorithms, and provide both a flow chart and pseudo code for the algorithms.    Algorithm descriptions: Given an integer parameter named current_number and two constant global variables: const int MIN_NUMBER = 1; const int MAX_NUMBER = 8; Create an algorithm named forward, that will advance ONE value through a sequence of numbers 1, 2, 3 ... MAX_NUMBER. In...

  • c++ microsoft visual studio Write a function that given a string it will return the number...

    c++ microsoft visual studio Write a function that given a string it will return the number of vowels in the string. Function prototype is given by: int getNumVowels(string s1);

  • Can you make this a function? Thank you. int locationOfMin(const string a[], int n): Return the...

    Can you make this a function? Thank you. int locationOfMin(const string a[], int n): Return the position of a string in the array such that that string is < = every string in the array. If there is more than one such string, return the smallest position of such a string. Return -1 if the array has no elements. Here's an example: string people[5] = { "samwell", "jon", "margaery", "daenerys" "tyrion" }: int j = locationOfMin(people, 5);//returns 3, since daenerys...

  • C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (Strin...

    C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT