Question

What should the return type of the following function be? [returnType] printName(string fName, string lName){ cout...

What should the return type of the following function be?

[returnType] printName(string fName, string lName){


cout << fName << " " << lName << endl;


}

Homework Answers

Answer #1

ANSWER: For this given function name printName() return type should be void because in this function no operations are performed and not returning anything from it simply you are printing the first name and last name so here return type should be void. Below is the code and output for your reference please do upvote or comment on it if you still have any doubt.

CODE:

#include <iostream>

using namespace std;
void printName(string fName, string lName){

cout << fName << " " << lName << endl;

}
int main()
{
string fName,lName;
cout<<"Enter first name and last name:";// Here I am taking input for first name and last name.
cin>>fName>>lName;
  
printName(fName,lName);

return 0;
}

OUTPUT:

Know the answer?
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
Similar Questions
Data Structures using C++ Consider the definition the following function template: template <class Type> Type func(Type...
Data Structures using C++ Consider the definition the following function template: template <class Type> Type func(Type list[], int size) {        Type x = list[0];        Type y = list[size - 1];        for (int j = 1; j < size / 2; j++)        {               if (x < list[j])                      x = list[j];               if (y > list[size - 1 - j])                      y = list[size - 1 - j];        }        return x + y; }...
C++ Write a function that returns a string of 1's and 0's. This needs to be...
C++ Write a function that returns a string of 1's and 0's. This needs to be the binary representation of a number. Do not use loops. Use only recursion. Do not change the function's parameters or add more parameters. Do not change the main program. #include #include string bin(int number) { //Code here } int main() {    cout << bin(43) << endl; // Should be 101011    return 0; }
Rewrite the following C++ class into Java, don't forget to put main into the Student class....
Rewrite the following C++ class into Java, don't forget to put main into the Student class. class Student { std::string lname; std::string fname; int age; double gpa; Student(const std::string& lname, const std::string& fname, int age, double gpa); std::string lname() const; std::string fname() const; int age() const; double gpa() const; friend std::ostream& operator<<(std::ostream& os, const Student& st); }; int main(int argc, const char* argv[]);
C++ Write a recursive function that reverses the given input string. No loops allowed, only use...
C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. I had asked this before but the solution I was given did not work. #include #include using namespace std; void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sammy";    reverse(name);    cout << name << endl; //should display...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any type dynamic arrays (replace string by the template in all instances below). • The class should have: – A private member variable called dynamicArray that references a dynamic array of type string. – A private member variable called size that holds the number of entries in the array. – A default constructor that sets the dynamic array to NULL and sets size to 0....
Define a function SetHeight, with int parameters feetVal and inchesVal, that returns a struct of type...
Define a function SetHeight, with int parameters feetVal and inchesVal, that returns a struct of type WidthFtIn. The function should assign WidthFtIn's data member numFeet with feetVal and numInches with inchesVal. #include <iostream> using namespace std; struct WidthFtIn {    int numFeet;    int numInches; }; /* Your code goes here */ int main() {    WidthFtIn objectSize;    int feetVal;    int inchesVal;    cin >> feetVal >> inchesVal;    objectSize = SetHeight(feetVal, inchesVal);    cout << "Size: "...
I'm having a warning in my visual studio 2019, Can anyone please solve this warning. Severity  ...
I'm having a warning in my visual studio 2019, Can anyone please solve this warning. Severity   Code   Description   Project   File   Line   Suppression State Warning   C6385   Reading invalid data from 'DynamicStack': the readable size is '(unsigned int)*28+4' bytes, but '56' bytes may be read.   Here is the C++ code were I'm having the warning. // Sstack.cpp #include "SStack.h" // Constructor SStack::SStack(int cap) : Capacity(cap), used(0) {    DynamicStack = new string[Capacity]; } // Copy Constructor SStack::SStack(const SStack& s) : Capacity(s.Capacity), used(s.used)...
How can this PHP code be changed to use a parameter to the function that you...
How can this PHP code be changed to use a parameter to the function that you would then pass $students in? (instead of using a global). Also, can you show how to use a loop to handle any length of array? (instead of an array that is 3 elements). <?php $students = array(     array('FName'=>'Jane', 'LName'=>'Doe', 'ClassScore'=>90),     array('FName'=>'Bob', 'LName'=>'Joe', 'ClassScore'=>50),     array('FName'=>'John', 'LName'=>'Doe', 'ClassScore'=>20)     );     //1. CalculateSum() Function     function CalculateSum()     {         // Use $students array throughout the function.         global $students;         // Add...
#Write a function called has_a_vowel. has_a_vowel should have #one parameter, a string. It should return True...
#Write a function called has_a_vowel. has_a_vowel should have #one parameter, a string. It should return True if the string #has any vowels in it, False if it does not. def has_a_vowel(a_str): print("Starting...") for letter in a_str: print("Checking", letter) if letter in "aeiou": print(letter, "is a vowel, returning True") return True else: print(letter, "is not a vowel, returning False") return False print("Done!")       #Below are some lines of code that will test your function. #You can change the value of...