The partial program given below reads in a digit given in letters (e.g. "seven") and is expected to print it as a single number (e.g. 7 in this case). You are to write the important function in this: 'find'. This takes as arguments a two dimensional array in the ith row of which is stored the text name of digit i, number of 'names' in the array i.e. value 10 & a char array that we call 'target'- this would contain the literal/name of the digit input to the program. If the string stored in target equals the string stored in the ith row of the two dimensional array, then find should return i. If the string in target is not stored in any row, find should return -1.
Your function find can use the function compare discussed in the lecture. The function compare as well as the line "include " are stored in the top of the text box already. The main() program is likewise already stored in the bottom part of the text box.You have to write only the find function. Please note that the two dimensional array that find uses - the one defined in the main() function, stores the 'names' of digits in lower case only. For your reference, the function compare & the main() program are also given below.
#include
char compare(const char *a, const char *b)
{
int i=0;
while(true){
if(a[i]=='\0' && b[i]=='\0')
return '=';
if(a[i]
if(a[i]>b[i]) return '>';
i++;
}
}
// function find appears here
int main(){
char digits[10][20] = {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine"};
char target[20];
cin.getline(target,20);
cout <
}
Answers
Answered by
1
Answer:
Declare the array name. ... For economy in code, we often take advantage of Java's default array ... As an example, suppose that you are writing a program that ...
Similar questions