Pages

Saturday, 29 July 2017

CBSE Class 12 - Computer Science - C++ Practical File Handling Snippet-6 (#cbseNotes)

C++ Practical
File Handling Snippet-6

CBSE Class 12 - Computer Science - C++ Practical Class Design Snippet-6 (#cbseNotes)

Question :  Write a program in C++ to count number of uppercase alphabets present in a text file "ARTICLE.TXT"


Answer:




//  Write a program in C++ to count number of uppercase alphabets
// present in a text file "ARTICLE.TXT"

#include <iostream.h>
#include <fstream.h>
#include <process.h>
#include <ctype.h>

int main()
{
 ifstream fin("ARTICLE.TXT", ios::in);
 if (!fin)
 {
  cout << "Error opening file ARTICLE.TXT\n Exiting..." << endl;
  exit(1);
 }
 char ch;
 int count=0;
 while(!fin.eof())
 {
  fin.get(ch);
  if(isalpha(ch))
   {
     if (ch >= 'A' && ch <= 'Z')
       count++;
   }
 }
 cout<<"Number of UPPERCASE alphabets in file are " << count << endl;
 fin.close();
 return 0;
}



Screen Output:

CBSE Class 12 - Computer Science - C++ Practical Class Design Snippet-6 (#cbseNotes)

No comments:

Post a Comment

We love to hear your thoughts about this post!

Note: only a member of this blog may post a comment.