Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <string>
- using namespace std;
- const char IVEST[] = "Duomenys.txt";
- const char ISVEST[] = "Rezultatai.txt";
- void balses (const char IV[], unsigned &a, unsigned &e) {
- ifstream in(IV);
- char c;
- while((c = in.get()) && in.good())
- if (c=='a')
- a++;
- else if (c=='e')
- e++;
- }
- void isvedimas(const char ISVEST[], unsigned &a, unsigned &e) {
- ofstream out(ISVEST);
- out << "Balsė a tekste pasikartoja " << a << " kartų" << endl;
- out << "Balsė e tekste pasikartoja " << e << " kartų" << endl;
- int proc;
- if (a>e) {
- proc=(a-e)*100.0/a+0.5;
- out << "Balsė e tekste pasikartoja " << proc << " % rečiau" << endl;
- } else if (e>a) {
- proc=(e-a)*100.0/e+0.5;
- out << "Balsė a tekste pasikartoja " << proc << " % rečiau" << endl;
- }
- out.close();
- }
- int main() {
- setlocale(LC_ALL, "Lithuanian");
- string sakinys;
- unsigned a=0, e=0;
- balses(IVEST, a, e);
- isvedimas(ISVEST, a, e);
- return 0;
- }
- /*
- Užduoties sumąstytojo sprendimas:
- // C++
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- const char CDfv[] = "Duomenys.txt";
- const char CRfv[] = "Rezultatai.txt";
- //----------------------------------------
- void Skaitymas(int & na, int & ne);
- void Irasymas (int na, int ne, char chr, double proc);
- void Skaiciavimas(int na, int ne, char & chr, double & proc);
- //----------------------------------------
- int main() {
- int na = 0;
- int ne = 0;
- char chr = '-';
- double proc = 0;
- Skaitymas(na, ne);
- Skaiciavimas(na, ne, chr, proc);
- Irasymas(na, ne, chr, proc);
- system("pause");
- return 0;
- }
- void Skaitymas(int & na, int & ne)
- {
- char chr;
- ifstream fd(CDfv);
- while (fd >> chr)
- {
- if(chr == 'a')
- na = na + 1;
- if(chr == 'e')
- ne = ne + 1;
- }
- fd.close();
- }
- void Skaiciavimas(int na, int ne, char & chr, double & proc)
- {
- if (na == 0){chr = 'e'; proc = ne*100; return;}
- if (ne == 0){chr = 'a'; proc = na*100; return;}
- if(na < ne)
- {
- proc = ((double)(ne-na)*100/(double)ne);
- chr='a';
- }
- else
- {
- proc = ((double)(na-ne)*100/(double)na);
- chr='e';
- }
- }
- void Irasymas (int na, int ne, char chr, double proc)
- {
- ofstream fr(CRfv);
- fr << "Raidë a pasikartoja tekste " << na << " kartø."<< endl;
- fr << "Raidë e pasikartoja tekste " << ne << " kartø."<< endl;
- if(na != 0 && ne != 0)
- fr << "Raidë " << chr << " pasikartoja "<< proc << "% reèiau."<<endl;
- fr.close();
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment