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
What is the default text-wrapping option when inserting images into a Word document?
JulijaS [17]

Answer:

In line with the text

Explanation:

8 0
4 years ago
Read 2 more answers
1. Which tool is used for hardware to stand on to prevent static
GalinKa [24]

Answer:

An anti-static mat tool.

Explanation:

To prevent, static electricity from building up an anti-static mat tool is used. This is the tool that is used to prevent static electricity from building up. However, if you don't have the anti-static mat, an antistatic wrist strap can be used.

5 0
2 years ago
Assign a variable madLib to a function expression that has five parameters in the order: an adverb, two nouns, an adjective and
hoa [83]

Answer:

<em>The function is written in C++:</em>

void madLib(string adjective,string noun1,string adverb,string verb,string noun2){

   cout<<"The "+verb+" "+noun1+" "+adjective+" "+noun2+" the "+adverb;

}

Explanation:

This line defines the function

void madLib(string adjective,string noun1,string adverb,string verb,string noun2){

This line generates and returns the output string

   cout<<"The "+verb+" "+noun1+" "+adjective+" "+noun2+" the "+adverb;

<em>NB: I've added the full source code as an attachment where you can test various input strings</em>

Download cpp
6 0
4 years ago
A group of students take hundreds of digital photos for a science project about weather patterns. Each photo file contains data
lesya [120]

Analyzing the metadata would be more appropriate than analyzing the data when: determining the likelihood that the photo was taken at a particular public event.

<h3>What is a data?</h3>

A data can be defined as a representation of instructions or information in a formalized manner, especially as a series of binary digits (bits).

<h3>What is a metadata?</h3>

A metadata can be defined as the data that provides information about one or more aspects of a given data, so as to provide a structured reference that helps to sort and identify all of its attributes such as:

  • Author
  • Date created
  • Date modified
  • File type
  • File size

In this scenario, analyzing the metadata would be more appropriate than analyzing the data when determining the likelihood that the photo was taken or created at a particular public event.

Read more on data here: brainly.com/question/25558534

6 0
2 years ago
Which visualization is good to represent values that change with change in time?
mojhsa [17]

Answer:

???

i would help but gotta explain more

Explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • How many nibbles are in 18 bytes??
    5·1 answer
  • What is the simplest way to permanently get rid of an unwanted file? A. Go to the Start menu and then delete the file. B. Erase
    5·1 answer
  • Before you enable data deduplication, what tool can you use to determine if data deduplication would benefit the tested volumes
    11·1 answer
  • A bakery collects data on sales. Each sales record includes the date of the sale and some metadata about the items that were par
    11·1 answer
  • Is www part of every url address?
    6·1 answer
  • 1) Type a statement that gets an input value into variable numBers. Assume scnr already exists and numBers has been declared.
    9·1 answer
  • How to follow accounts on brainy
    11·1 answer
  • What does l m a o actually mean?
    6·1 answer
  • Which of the following is the fastest computer processing speed?
    10·1 answer
  • Please explain what is Ribbon?  give examples​
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!