1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std ;
int main()
{
string content ; int choice , _count = 0 , exit_program ;
char ch , letter , word[30] , word_to_count[30] ;
fstream f1 ;
f1.open("DATA.TXT" , ios :: out) ;
cout<<"\nEnter The Content For The File : " ;
getline(cin,content) ;
f1 << content ;
f1.close() ;
cout<<"\tPress 0 To Use MENU AGAIN AND 1 TO EXIT THE PROGRAM!!" ;
system("cls") ;
do
{
cout<<"\t\nMENU - : \n1.Count Occurrence Of A Single Letter\n2.Count Number Of Vowels \n3.Count Number Of Times a word appears \n4. Substitute A Character(ON SCREEN ONLY,OPTION 8 FOR FILE FORMATTING)" ;
cin>>choice;
{
switch(choice)
{
case 1 : f1.open("DATA.TXT" , ios :: in) ;
cout << "\nEnter The Letter You Want To Count " ;
cin >> letter ;
while(f1.get(ch))
{
if (letter == ch)
_count++;
}
cout<<"\nThe Number OF Times " << "'" << letter << "' appears is = " <<_count ;
f1.close() ;
cout<"\n" ;
cin>>exit_program ;
break ;
case 2 : f1.open("DATA.TXT" , ios :: in) ;
while(f1.get(ch))
{
if ((ch== 'a' || ch == 'A' || ch == 'e' || ch =='E' || ch == 'o' || ch == 'O' || ch == 'I' || ch == 'i' || ch == 'u' || ch == 'U'))
_count++;
}
cout<<"\nNumber Of VOWELS IN THE FILE ARE : " << _count ;
f1.close() ;
cout<"\n";
cin>>exit_program ;
break ;
case 3 : f1.open("DATA.TXT" , ios :: in) ;
cin.ignore() ;
cout << "\nEnter The WORD Whose Occurrence You Want To Count : " ;
gets(word_to_count) ;
while(f1 >> word)
{
if(strcmp(word_to_count,word) )
_count++;
}
cout << "\nNumber Of Times " << word_to_count << "Appears is = " << _count ;
f1.close() ;
cout<"\n" ;
cin>>exit_program ;
break ;
case 4 : char to_replace , to_be_replaced ;
f1.open("DATA.TXT" , ios :: in ) ;
cout<<"\nEnter The Letter You Want To REPLACE : " ;
cin>>to_replace ;
cout<<"\nEnter The Letter To Be Replaced : " ;
cin>>to_be_replaced ;
while(f1.get(ch))
{
if (ch == to_replace)
ch = to_be_replaced ;
cout<< ch ;
}
while(f1.get(ch))
{
cout << ch ;
}
cout<"\n" ;
cin>>exit_program ;
f1.close() ;
}
}
} while (exit_program == 0) ;
return 0 ;
}
|