Question
Could anyone help?
Thank you.

B.6 - 10 pts string* callMe(string& s) { s = Senorita; return &s; int main() { string s = Senor; string* str = callme(s);
0 0
Add a comment Improve this question Transcribed image text
Answer #1

output : -

call me 'Senorita'

program with explanation :-

#include<iostream> // for input output
#include<string> // for string class
using namespace std; //for cin cout

// assigns "Senorita" this value to passing string argument i.e it overides at return the same string
string* callme(string& s){
s = "Senorita";
return &s;
}

// entry point of the program
int main(){
// declare string s with value "Senor"
string s = "Senor";
  
// assign return value of callme function to string str
string* str = callme(s);
  
// concate and prints the output
std::cout << " call me \'" + *str + "\'";
  
return 0;
}

Flow wise explanation : -

1. program execution starts from main() function

2. string s = "Senor"; this expression assigns value "Senor" to suppose xyz location

3. string* str = callme(s); this expression (only rigth part execute now) calls function callme() with pointer to string s.No memory updation

4. s = "Senorita"; this expression overides value "Senorita" to xyz location. It means it changes the value at this location.

5. return &s; this expression returns address of string s i.e xyz

6. string* str = callme(s); (left part execute now) here str points to the location xyz now i.e str is string pointer to xyz location

7. " call me \'" + *str + "\'" this expression concates output with value represeting by string pointer str

8. std::cout << it prints output to the console

6.

Add a comment
Know the answer?
Add Answer to:
Could anyone help? Thank you. B.6 - 10 pts string* callMe(string& s) { s = "Senorita";...
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
  • I have this project for C++ programming and I was wondering if anyone could help point...

    I have this project for C++ programming and I was wondering if anyone could help point me in the right direction. Not sure what a template-based function is or how I can count occurences if I don't know the type. Write a template-based function frequency that will return the count of the occurrences of an item in an array of items. 1. Test the template with the types int, double, and string. 2. The program will NOT prompt for any...

  • Can anyone help me? Thank you very much. Question 10 1 pts The constructor below is...

    Can anyone help me? Thank you very much. Question 10 1 pts The constructor below is very similar to the one you used for the last assignment. What is its time complexity in terms of N, where N is the number of lines in the Input Stream (the word file)? public Doublets (Inputstream in) try t lexicon. new TreeSet String O; Scanner s new Scanner (new BufferedReader new I (in))) while (s hasNext String str s next boolean added lexicon....

  • when i run it is still be "false" i don't know why. could you help me...

    when i run it is still be "false" i don't know why. could you help me fix it and tell me which part is wrong??? specific answer is better thanks!!! Problem 6: (4 pts): Write a function that takes as an input parameter a string. It should return a Boolean value indicating whether the string is a palindrome or not. INPUT: “mom"->true “palindrome”->false “amanaplanpanama"->true 3 #include <iostream> #include <string.h> I using namespace std; string function(string str); int main() { function("palindrome");...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • Can someone help me . This program needs to run in visual studio and written in...

    Can someone help me . This program needs to run in visual studio and written in c++. I want to call to the function string eraseChar in the main function to use the variables str and ch. I cannot use global variables. #include<iostream> #include <string> using namespace std; string eraseChar(char ch = 'e', string str = "the bike fell in the water");    int main() {    int pos;    pos = str.find(ch);    while (pos != string::npos)    {...

  • C++ NEED HELP WITH MY REVERSE STRING FUNCTION IN LINK LIST A function Reverse, that traverses...

    C++ NEED HELP WITH MY REVERSE STRING FUNCTION IN LINK LIST A function Reverse, that traverses the linked list and prints the reverse text to the standard output, without changing the linked list. ( Pass the linked list by value, you have the freedom to create a doubly linked list that is a copy of the original list in your program before you call the function) #include "pch.h" #include <iostream> #include <string.h> #include <string> using namespace std; #define MAX 512...

  • c++ Consider the following statement string str "Now is the time for the party!" What is...

    c++ Consider the following statement string str "Now is the time for the party!" What is the output of the following statements? (Assume that all parts are independent of each other.) a. cout <str·size ( ) end 1 ; b. Cout << str. substr (7, 8) <<endl: c. string: :size type indstr.find'£') string s str. substr (ind 4, 9); d. cout << str insert (11,"best " <<endl e. str.erase (16, 14) str.insert (16, "to study for the exam? ") cout...

  • #include <iostream> #include <sstream> #include <string> using namespace std; int main() {    const int index...

    #include <iostream> #include <sstream> #include <string> using namespace std; int main() {    const int index = 5;    int head = 0;    string s[index];    int flag = 1;    int choice;    while (flag)    {        cout << "\n1. Add an Item in the Chores List.";        cout << "\n2. How many Chores are in the list.";        cout << "\n3. Show the list of Chores.";        cout << "\n4. Delete an...

  • can you please split this program into .h and .cpp file #include <iostream> #include<string> #include<fstream> #define...

    can you please split this program into .h and .cpp file #include <iostream> #include<string> #include<fstream> #define SIZE 100 using namespace std; //declare struct struct word_block {    std::string word;    int count; }; int getIndex(word_block arr[], int n, string s); int main(int argc, char **argv) {    string filename="input.txt";    //declare array of struct word_block    word_block arr[SIZE];    int count = 0;    if (argc < 2)    {        cout << "Usage: " << argv[0] << "...

  • The following code is a C Program that is written for encrypting and decrypting a string....

    The following code is a C Program that is written for encrypting and decrypting a string. provide a full explanation of the working flow of the program. #include <stdio.h> int main() { int i, x; char str[100]; printf("\n Please enter a valid string: \t"); gets (str); printf ("\n Please choose one of the following options: \n"); printf ("1 = Encrypt the given string. \n"); printf("2 = Decrypt the entered string. \n"); scanf("%d",&x); // using switch case statements switch (x) {...

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