Ask Question
27 June, 08:49

Implement the function lastChars () that takes a list of strings as a parameter and prints to the screen the last character of each string, one per line. If the list provided as a parameter is empty, the function prints a message to that effect. If any of the strings are empty, they are skipped in the display. The information below shows how you would call the function lastChars () and what it would display for a couple of parameters:

+2
Answers (1)
  1. 27 June, 11:14
    0
    The following program is in C++.

    #include

    using namespace std;

    void lastChars (string s)

    {

    int l=s. length ();

    if (l!=0)

    {

    cout<<"The last character of the string is: "<
    }

    }

    int main () {

    string s; //declaring a string ...

    getline (cin, s); //taking input of the string ...

    lastChars (s); //calling the function ...

    return 0;

    }

    Input:-

    Alex is going home

    Output:-

    The last character of the string is: e

    Explanation:

    In the function lastChars () there is one argument that is a string. I have declared a integer variable l that stores the length of the string. If the length of the string is not 0. Then printing the last character of the string. In the main function I have called the function lastChars () with the string s that is prompted from the user.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Implement the function lastChars () that takes a list of strings as a parameter and prints to the screen the last character of each string, ...” in 📘 Engineering if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers