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
Schach [20]
3 years ago
14

Given an alphanumeric string made up of digits and lower case ASCII characters only, find the sum of all the digit characters in

the string. The function signature for 'sum Digits' is -
(define sumDigits ...)

1. Constraints -
- Not allowed to use library functions. This means no import statement.
- No loops or list comprehension. The solution must be recursive.
- Do not use length of string in any function.


2. Input to function 'sumDigits -
- An alphanumeric string.


3. Output of function -
-Sum of all the digits in the string.


4. Sample test case
Test case 1
calling sumDigits ab1c2d3e54 outputs 15 = 1 + 2 + 3 + 5 + 4
Computers and Technology
1 answer:
lara31 [8.8K]3 years ago
3 0

Answer:

C++.

Explanation:

#include <iostream>

#include <string>

using namespace std;

////////////////////////////////////////////////////////////////////////////

int sumDigits(string alphanumeric) {

   if (alphanumeric.length() == 1) {

       if ((int(alphanumeric[0]) >= 48) && (int(alphanumeric[0]) <= 57)) {

           cout<<int(alphanumeric[0]) - 48<<endl;

           return (int(alphanumeric[0]) - 48);

       }

       else

           return 0;

   }

   else {

       if ((int(alphanumeric[0]) >= 48) && (int(alphanumeric[0]) <= 57)) {

           cout<<int(alphanumeric[0]) - 48<<endl;

           return int(alphanumeric[0]) - 48 + sumDigits(alphanumeric.substr(1, alphanumeric.length()-1));

       }

       else

           return 0 + sumDigits(alphanumeric.substr(1, alphanumeric.length()-1));

   }

}

////////////////////////////////////////////////////////////////////////////

int main() {

   cout<<"Sum: "<<sumDigits("ab1c2d3e54");

   return 0;

}

You might be interested in
You've added a clip art image to your slide. Now you want to add a border. Which tab would you use to make this change?
Vinvika [58]
<span>If you want to add a border you have to use 'Insert' tab to make this change. Then you have to click on</span> "Picture" that is placed in the Insert menu, and choose "Clip Art." You can use the search box at the top of the Clip Art gallery in order to find a suitable border. When you finally found it, click on it, then select the button "Insert".
6 0
3 years ago
Read 2 more answers
TRUE OR FALSE!!!!!
KatRina [158]

Answer:

True

Explanation:

Using CCleaner, it's revealed that there are trackers within "secure" websites/apps such as Google and Tiktok. The manufacturer(s) of these websites/apps can share your information with whoever they're working with. Since people often look past the terms and conditions when installing an app and or program, they don't see that companies can easily retrieve all of your data within a couple clicks.

6 0
3 years ago
Write an expression that will cause "greater or equal to -10" to print if the value of userNum is greater than or equal to -10.
Lilit [14]

Answer:

Expression for the above problem in python language:

userNum=int(input("Enter the value of user_Num")) #it is used to take input.

if(userNum>(-10)): #if statement

   print("The value of the userNum is greator")

elif(userNum==(-10)): #elif statement

   print("The value of the userNum is equal to -10")

else: #else statement.

   print("The value of the userNum is small")

Output:

  • If the user input is (-10), it will print equal.
  • If the user input 10, it will print greator message.

Explanation:

  • The above program or expression is in python language, where the first line is used to render a message to the user take the input and store it into a userNUM variable.
  • Then the second line is used to check the user num value to be greater with the help of if statement.
  • Then the third statement is used to check the user num value to be equal with the help of elif statement.
  • Then the else statement will execute when the if and the elif statement will not true.
6 0
3 years ago
Device management is the process of managing what kinda devices? :)
Anika [276]
Device management is the process of managing "Physical Devices" like <span>ports and interfaces of a computer or server

Hope this helps!</span>
4 0
3 years ago
Which category best represents: during class, students use their mobile phones to share answers to an assignment?
Studentka2010 [4]
The best category is cheating
5 0
3 years ago
Read 2 more answers
Other questions:
  • What is a technology that exists inside another device called
    11·1 answer
  • major m,ajorrr points helpppppppppppppppppppppppppppi have a question i hit a few buttons and now my computer is saying everythi
    11·2 answers
  • Populate a one-dimensional array with the following grades in this order: 90, 61, 74, 42, 83, 51, 71, 83, 98, 87, 94, 68, 44, an
    15·1 answer
  • Imagine that you have a friend who has expressed interest in designing and programming video games. He loves to play video games
    10·1 answer
  • Who created apple and in what year was it created
    9·2 answers
  • Which of the following is the most reliable way to check the accuracy of a website?
    13·1 answer
  • In a well-developed paragraph - using domain-specific vocabulary and academic writing - address the following writing prompt:
    12·1 answer
  • When you ____ an exception, you send a message that an error has occurred to another part of the program.
    7·2 answers
  • Explain the pros and cons of touchscreen, non-touchscreen, and hybrid devices:
    12·1 answer
  • Write code that declares a variable named minutes, which holds minutes worked on a job,
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!