I need this in C please Write a program that will open up a

I need this in C++ please.

Write a program that will open up a text file (open the file in a function), and then read one character at a time until end of file. When done, display how many alphabetic, how many digits, and how many other character that are not alphabetic nor digits.

Solution

Here is the code for you:

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

int main()
{
ifstream file;
string fileName;
char ch;
cout<<\"Enter the file name: \";
cin>>fileName;
file.open(fileName);
int numberOfCharacters = 0;
int numberOfAlphabets = 0;
int numberOfDigits = 0;
file >> noskipws;
while(!file.eof())
{
file>>ch;
numberOfCharacters++;
if(isalpha(ch))
numberOfAlphabets++;
if(isdigit(ch))
numberOfDigits++;   
}
cout<<\"The number of alphabets in the file is: \"<<numberOfAlphabets <<endl;
cout<<\"The number of digits in the file is: \"<<numberOfDigits <<endl;
cout<<\"The number of characters other than alphabets and digits is: \"<<numberOfCharacters - numberOfAlphabets - numberOfDigits<<endl;
}

I need this in C++ please. Write a program that will open up a text file (open the file in a function), and then read one character at a time until end of file.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site