#include
#include
#include
#include
using namespace std;
int main() {
//a harfini sanovchi
int countLetter_a = 0;
string line;
//file
fstream myfile;
//matn.txt nomli faylni ochish
myfile.open("matn.txt", ios::trunc | ios::out | ios::in);
while(myfile) {
//matnni kiritish
getline(cin, line);
//agar -1 kiritilsa matn kiritish to'xtaydi
if(line == "-1") break;
//faylga matnni yozadi
myfile << line << endl;
}
//faylni boshlang'ich nuqtasidan boshlash
myfile.seekg(0, ios::beg);
while(myfile) {
//fayldan matnni olish
getline(myfile, line);
//a harfini sonini aniqlash
for(int i = 0; i < line.length(); i++) {
//agar a yoki A harfi kiritilsa a ni sanochi oshib boradi.
if(line[i] == 'a' || line[i] == 'A') {
countLetter_a++;
}
}
}
cout << endl;
// a harfini sonini faylda chiqarish
myfile << "Matndagi a harfi soni = " << countLetter_a << endl;
//a harfini sonini konsolda chiqarish
cout << "Matndagi a harfi soni = " << countLetter_a << endl;
//faylni yopish
myfile.close();
return 0;
}
Fayldagi natija:
Do'stlaringiz bilan baham: |