1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Galina-37 [17]
3 years ago
6

Write a recursive, int-valued function, len, that accepts a string and returns the number of characters in the string. The lengt

h of a string is: 0 if the string is the empty string (""). 1 more than the length of the rest of the string beyond the first character.
Computers and Technology
1 answer:
Svet_ta [14]3 years ago
6 0

Answer:

The program to this question can be given as:

Program:

#include<iostream> //include header file.

using namespace std; //using namespace

int len(string s) //define method.

{

if(s=="") //if block

{

return 0; //return value.

}

else //else block

{

return 1+len(s.erase(0,1)) ; //return value.

}

}

int main() //main method.

{

   string s; //define variable.

   int X1; //define variable.

   cout<<"Enter string value: "; //message.

   cin>>s; //input string value.

   X1=len(s); //calling function that holds value in x1 variable

   cout<<X1; //print variable x value.

   return 0;

}

Output:

Enter string value: xxth

4

Explanation:

The description of the above C++ language program can be given as:

  • In the program first, we include the header file then we define the method that is "len" in this method we pass the string variable that is "s".  
  • Inside the len() method, we define a conditional statement in the if block we check if the value of s variable is equal to ("") empty. It will return 0 else it will return the count value of s variable.
  • Then we define a main method inside the main method we define two variable that is "s and X1".
  • s is a string variable that is used to take user input from the user and pass this variable into function.
  • X1 is an integer variable that is used for hold function return value and print its value.
You might be interested in
Convert the Binary Number to a Decimal Number
Korolek [52]
There are convertors online for this but the answer is 5
<span />
8 0
4 years ago
Which of the following best describes professional behavior in the IT field?
Ray Of Light [21]
Answer - teaching others about technology in order to increase IT knowledge in the community
4 0
3 years ago
If a document reaches you, and requires you to perform some action, you should do it immediately if ________. a. It is from your
tatyana61 [14]
C is the answer to this
8 0
4 years ago
Pls help its not school work i just need this fixed
Bingel [31]

Answer:

This just means that you have no file in your computer named 'Requirments' hence it is not able to retrieve any data from there.

6 0
3 years ago
Which is an example of synchronous communication. Text message e-mail voicemail telephone conversation
enot [183]

Answer:

Text Messages

Explanation:

Synchronous communication is a simultaneous communication between two people. This is the type of serial communication where two person can communicate at the same time. This type of communication exclude face to face communication and phone communication.

for example

during Chat when we are taking to someone he also can reply the same time.

3 0
3 years ago
Read 2 more answers
Other questions:
  • The purpose of the img element's ________ attribute is to provide a method for a browser to display different images depending o
    7·1 answer
  • What type of camera is a cell phone camera
    14·2 answers
  • How do i stream from my chromebook to my tv?
    8·1 answer
  • In the lab, the Ethernet II detail of the provided packet capture file indicated that Wireshark had determined that the ________
    5·1 answer
  • PLEASE HELPPPPPPP
    15·1 answer
  • 7) The small slots on the front, back, or side of your computer that allow you to connect devices (such as a keyboard, mouse, or
    11·1 answer
  • To print the number of elements in the array named ar, you can write :
    10·1 answer
  • For what reasons do readers use text-to-speech tools? Check all that apply.
    8·2 answers
  • What does XD mean? I keep seeing people say it and I dont know what it means
    6·2 answers
  • You compared each letter in the correct word to the letter guessed.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!