Write a function that counts the occurrence of each digit in a string using the following header:
int * count(const string &s)
The function counts how many times a digit appears in the string. The return value is an array of ten elements, each of which holds the count for a digit. For example, after executing int counts[] = count("12203AB3"), counts[0] is 1, counts[1] is 1, counts[2] is 2, counts[3] is 2.
Write a main function to display the count for "SSN is 343 32 4545 and ID is 434 34 4323".
```
#include
#include
using namespace std;
int * count(const char * const s)
{
int * counts = new int[10];
for (int i = 0; i < 10; i++)
counts[i] = 0;
for (int i = 0; i < strlen(s); i++)
{
if (isdigit(s[i]))
counts[s[i] - '0'] ++;
}
return counts;
}
int main()
{
int * counts = count("SSN is 343 32 4545 and ID is 434 34 4323");
for (int i = 0; i < 10; i++)
cout << i << " " << counts[i] << endl;
return 0;
}
```
You might also like to view...
Which of the following is considered a patch?
A. software upgrade B. software enhancement C. software version D. software update
A computer that stores and sends out Web pages on the Internet is called a ____.
A. Web server B. client C. DNS D. database
By default, Word sets right-aligned tab stops every 1/2 inch. ____________________
Answer the following statement true (T) or false (F)
In a physical bus topology, why do the ends of the cable have to be terminated?
What will be an ideal response?