Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help to finish this program please. thank you ... Write a program to read

ID: 3620067 • Letter: I

Question

I need help to finish this program please. thank you ...

Write a program to read a huge integer value with 50 digits,
find the digit that appears most frequently in the huge integer, and
print the digit and the number of its occurrences. If two digits appear the
same amount of times in the huge integer, output the larger digit.
*/

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main( )
{
const int DigitNum = 50; //array capacity
int hugeInt[DigitNum]; //array holding the huge integer
int frequency[10]; // occurrence frequency of each digit 0..9
// i.e. frequency[0] the number of times 0 appears in hugeInt
// i.e. frequency[1] the number of times 1 appears in hugeInt
// ...
// i.e. frequency[9] the number of times 9 appears in hugeInt

char digit; // holding current digit during the reading
int freqIndex; //holding the digit occuring most frequently

//read digits in the huge integer value into the array hugeInt
read digits in the huge integer value into the array hugeInt

//Print the array that has been read
cout << "The huge integer value is ";
for( int i=0; i<DigitNum; i++ )
cout << hugeInt[i];
cout << endl<< endl;

//1) initialize the frequency array
//2) calculate the occurrence frequency of each digit
//3) find the digit with the highest occurrence frequency
1) initialize the frequency array 2) calculate the occurrence frequency of each digit 3) find the digit with the highest occurrence frequency

cout << freqIndex <<" appears most frequently in the huge integer." << endl
<< "It appears " << frequency[freqIndex] << " times." << endl;

return 0;
}

Explanation / Answer

please rate - thanks

it was a misplaced }


#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main( )
{
const int DigitNum = 50; //array capacity
int hugeInt[DigitNum]; //array holding the huge integer
int frequency[10]; // occurrence frequency of each digit 0..9
// i.e. frequency[0] the number of times 0 appears in hugeInt
// i.e. frequency[1] the number of times 1 appears in hugeInt
// ...
// i.e. frequency[9] the number of times 9 appears in hugeInt

char digit; // holding current digit during the reading
int freqIndex; //holding the digit occuring most frequently

//read digits in the huge integer value into the array hugeInt
for (int i= 0; i < DigitNum; i++)
{ cin >> digit;
hugeInt [i] = digit - '0';
}
//Print the array that has been read
cout << "The huge integer value is ";
for( int i=0; i<DigitNum; i++ )
cout << hugeInt[i];
cout << endl<< endl;

//1) initialize the frequency array
//2) calculate the occurrence frequency of each digit
//3) find the digit with the highest occurrence frequency



for (int i=0 ;i < 10; i++)
{
frequency [i] =0;
}



for ( int i=0; i < DigitNum ; i++)
{ switch (hugeInt [i])
{
case 1: frequency [1]++;
break;
case 2: frequency [2]++;
break;
case 3: frequency [3]++;
break;
case 4: frequency [4]++;
break;
case 5: frequency [5]++;
break;

case 6: frequency [6]++;
break;
case 7: frequency [7]++;
break;
case 8: frequency [8]++;
break;
case 9: frequency [9]++;
break;
default: frequency [0]++;
break;
}
}


digit = frequency [0];

for ( int i=0; i <10; i++)
{
if (digit <= frequency [i])

{
digit = frequency [i];
freqIndex = i;
}

//}

}


cout << freqIndex <<" appears most frequently in the huge integer." << endl
<< "It appears " << frequency[freqIndex] << " times." << endl;
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote