PLEASE HELP IMMEDIATELY Write a C program to count the numbe

PLEASE HELP IMMEDIATELY!

Write a C++ program to count the number of ASCII characters in a text file. Your program needs an array for 128 integers, each corresponding to one ASCII character. The values in the array will be counters for the occurrences of ASCII characters in the text file. Your program must read a text file one character a time. After reading the character, you need to update the appropriate counters in the array. Now, you need to ask the user which character counter the user wants to display and display the number of occurrences of the character that you have stored in your array. It will be easier for you to program, if the array index number corresponds with the ASCII value of the character. Use ‘HW5Prob1.txt’ file for this problem. For example, there are 20 ‘A’ and 11 ‘.’ in the text file. Your array needs to have locations to put the counters for ‘A’ and ‘.’, and the corresponding values must be 20 and 11. And, finally, if the user enters ‘A’, you’ll need to display 20. It will be easy for you to program if you put the counter for ‘A’ in array index number 65.

Here is a given paragraph in\"HW5Prob1.txt\" file:

Solution

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


int main()
{
//file handle to read data from file containing Ascii characters
ifstream in;
//array to store number of occurances of 128 Ascii characters
int arr_ocuurance[128]={0},i=0,num,j=0;
   char c;
  
in.open(\"HW5Prob1.txt\");
if( in == NULL )
{
cout<<\"unableto open file for reading\ \";
exit(-1);
}
while(!in.eof())
{
       in>>noskipws >> c;
       num = c;
++arr_ocuurance[num] ;
i++;
}

   while(1)
   {
       cout<<\"Enter character counter the user wants to display or \'q\' to quit \"<<endl;
       cin>>c;
       if( c == \'q\')
           break;
       for(j = 0 ; j < 128 ; j++)
       {
      
           num = c;
           if( j == num)
           {
               cout<<\"Character \"<<c<<\" has occured \"<< arr_ocuurance[j]<<\" times in the file\ \"<<endl;
               break;
           }
       }
   }
}

PLEASE HELP IMMEDIATELY! Write a C++ program to count the number of ASCII characters in a text file. Your program needs an array for 128 integers, each correspo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site