The Code given below can be used in TURBO C++ Compilers: -
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <fstream.h>
#include <stdlib.h>
void count_up_low_case()
{
ifstream fin;
fin.open("Halfstry.txt");
char ch;
int lowcase = 0, upcase = 0;
while (fin)
{
fin.get(ch);
if (fin.eof())
break;
if (ch >= 65 && ch <= 90)
upcase++;
if (ch >= 97 && ch <= 122)
lowcase++;
} // while loop ends
fin.close();
cout << "\nNumber of upper case letters = " << upcase;
cout << "\nNumber of lower case letters = " << lowcase;
} // count_up_low_case() ends
void countspecialch()
{
ifstream fin("Halfstry.txt");
char ch;
int s = 0, sp = 0;
while (fin)
{
fin.get(ch);
if (fin.eof())
break;
if (ch == 32)
s++;
else if ((ch >= 48 && ch <= 57) || (ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90))
continue;
else
sp++;
} // while loop ends
fin.close();
cout << "Number of spaces in the file = " << s << "\n";<<<<
cout << "Number of special characters = " << sp << "\n";
} // countspecialch() ends
void checksize()
{
ifstream fin("Halfstry.txt");
char ch;
int sz = 0;
while (fin)
{
fin.get(ch);
if (fin.eof())
break;
sz++;
} // while loop ends
fin.close();
cout <<<< "Size of the file is = " <<<< sz <<<< "\n";
} // checksize() ends
int main()
{
clrscr();
ifstream fin("Halfstry.txt");
char ch = 'Y';
int ch1;
while (ch == 'Y' || ch == 'y')
{
cout <<<< "Enter choice: \n";
cout <<<< "1.To count no of Uppercase and Lowercase letters. \n";
cout <<<< "2.To count the no of spaces and special characters. \n";
cout <<<< "3.To check the size of the file. \n";
cout <<<< "4. Exit.\n";
cin >> ch1;
switch (ch1)
{
case 1:
count_up_low_case();
break;
case 2:
countspecialch();
break;
case 3:
checksize();
break;
case 4:
ch = 'N';
exit(0); // exit
} // switch ends
cout <<<< "\n\nWould you like to continue? [Y/N]\n";
cin >> ch;
} // while ends
getch();
return 0;
} // main() ends;
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
#include <string.h>
#include <fstream.h>
using namespace std;
void count_up_low_case()
{
ifstream fin;
fin.open("Halfstry.txt");
char ch;
int lowcase = 0, upcase = 0;
while (fin)
{
fin.get(ch);
if (fin.eof())
break;
if (ch >= 65 && ch <= 90)
upcase++;
if (ch >= 97 && ch <= 122)
lowcase++;
} // while loop ends
fin.close();
cout << "\nNumber of upper case letters = " << upcase;
cout << "\nNumber of lower case letters = " << lowcase;
} // count_up_low_case() ends
void countspecialch()
{
ifstream fin("Halfstry.txt");
char ch;
int s = 0, sp = 0;
while (fin)
{
fin.get(ch);
if (fin.eof())
break;
if (ch == 32)
s++;
else if ((ch >= 48 && ch <= 57) || (ch >= 97 && ch <= 122) || (ch >= 65 &&<< ch <= 90))
continue;
else
sp++;
} // while loop ends
fin.close();
cout << "Number of spaces in the file = " << s << "\n";
cout << "Number of special characters = " << sp << "\n";
} // countspecialch() ends
void checksize()
{
ifstream fin("Halfstry.txt");
char ch;
int sz = 0;
while (fin)
{
fin.get(ch);
if (fin.eof())
break;
sz++;
} // while loop ends
fin.close();
cout << "Size of the file is = " << sz << "\n";
} // checksize() ends
int main()
{
ifstream fin("Halfstry.txt");
char ch = 'Y';
int ch1;
while (ch == 'Y' || ch == 'y')
{
cout << "Enter choice: \n";
cout << "1.To count no of Uppercase and Lowercase letters. \n";
cout << "2.To count the no of spaces and special characters. \n";
cout << "3.To check the size of the file. \n";
cout << "4. Exit.\n";
cin >> ch1;
switch (ch1)
{
case 1:
count_up_low_case();
break;
case 2:
countspecialch();
break;
case 3:
checksize();
break;
case 4:
ch = 'N';
exit(0); // exit
} // switch ends
cout << "\n\nWould you like to continue? [Y/N]\n";
cin >> ch;
} // while ends
return 0;
} // main() ends;
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP