Got a program code so far to:
I need it to delete words that are made of two numerals and which sum is less or equal to 9. (basicaly if its 18/15/71 it deletes that word, if its 91 it wont because its more than 9). Think im pretty much done getting program to do so, theres a problem - If there's more than 1 word that meets my criteria in single line, program returns only last word from that line to analyzis.txt while i need it to return every single one of it.. Any ideas?Code:#include <string> #include <fstream> #include <iomanip> #include <iostream> using namespace std; //---------------------------------------------------------------------------- const char Cdat[] = "Data.txt"; const char Crez[] = "Rezult.txt"; const char Canalyzis[] = "Analyzis.txt"; //---------------------------------------------------------------------------- void TrimmText(const char dfv[], const char rfv[], const char afv[]); void AnalyzeLine(string &lin, string & TwoNumeral, int & TwoStart, unsigned int & TwoSum); void EditLine(string &lin, int TwoStart, int TwoSum); int main() { TrimmText(Cdat, Crez, Canalyzis); } //---------------------------------------------------------------------------- // Text reading by line // dfv - original text data file name, rfv - edited text data file name // afv - analyzis data file name void TrimmText(const char dfv[], const char rfv[], const char afv[]) { string TwoNumeral; int TwoStart; unsigned int TwoSum; ifstream fd(dfv); ofstream fr(rfv); ofstream fa(afv); string L; fa << "---------------------------\n"; fa << "| Word | Start | Sum |\n"; fa << "---------------------------\n"; while(!fd.eof()) { getline (fd, L); { AnalyzeLine(L, TwoNumeral, TwoStart, TwoSum); fr << L << endl; if (TwoSum <= 9 && TwoSum != 0) { fa << "| " << left << setw(5) << TwoNumeral << " | " << right << setw(7) << TwoStart; fa << " | " << setw(5) << TwoSum << " |\n"; } } } fa << "---------------------------\n" << endl; fd.close(); fd.close(); fa.close(); } //---------------------------------------------------------------------------- // Function which finds words that are made of two numerals and its sum // lin - line, in which search is being made // TwoNumeral - word which is made of two numerals // TwoStart - return its start // TwoSum - returns its numerals sum void AnalyzeLine(string &lin, string & TwoNumeral, int & TwoStart, unsigned int & TwoSum) { string Skirt = " .,!?:;()\t"; string Numbers = "0123456789"; string Word; int zpr = 0, zpb = 0; int skaiciukai[2]; char skirstymas[2]; TwoNumeral = ""; TwoStart = 0; TwoSum = 0; while ((zpr = lin.find_first_not_of(Skirt, zpb)) != string::npos) { zpb = lin.find_first_of(Skirt, zpr); Word = lin.substr(zpr, zpb - zpr); if(Word.length()==2 && !Word.find_first_of(Numbers,0)) { TwoNumeral = Word; TwoStart = zpr; skirstymas[0]=Word[0]; skirstymas[1]=Word[1]; char sk1=skirstymas[0]; char sk2=skirstymas[1]; skaiciukai[0]=atoi(&sk1); skaiciukai[1]=atoi(&sk2); TwoSum = skaiciukai[0]+skaiciukai[1]; if (TwoSum <= 9 && TwoSum != 0) { EditLine(lin, TwoStart, TwoSum); } } } } //---------------------------------------------------------------------------- // function which deletes words that are made of two numerals and which sum is less or equal to 9 // lin - line, which is being changed // TwoStart - the start of word made of two numerals void EditLine(string & lin, int TwoStart, int TwoSum) { string Numbers = "0123456789"; if (Numbers.find_first_of(lin[TwoStart]) != string::npos) { lin.erase(TwoStart, 2); } }
Heres data file example:
Rezults file:Code:Ne vieno antikos 18 autorių veikaluose 17 esama likę 567 nupasakojimų, kaip kvapiosios substancijos keliavo 1900 mylių aplink Viduržemio jūrą. **** 14 12 13 99 125 *** Iš šių 105 įvairių aprašymų matyti, jog Egiptas, ypač faraonų laikais, 05 labai daug *** 76 kvapiųjų substancijų (kai kurių nūdienos 10 archeologų skaičiavimais gal net **** 80 %) 01 atsigabendavo iš tolimų ir ne tokių tolimų kraštų: iš Arabijos, iš Viduržemio jūros 55 salų – Kipro, Chijo ir Kretos, iš Nilo aukštupio. Ypač 333 kvepalų importas 22 Egipte suklestėjo XIII a. pr. m. e, kai šalį valdė Ramzis Didysis.
Analyzis file:Code:Ne vieno antikos autorių veikaluose esama likę 567 nupasakojimų, kaip kvapiosios substancijos keliavo 1900 mylių aplink Viduržemio jūrą. **** 99 125 *** Iš šių 105 įvairių aprašymų matyti, jog Egiptas, ypač faraonų laikais, labai daug *** 76 kvapiųjų substancijų (kai kurių nūdienos archeologų skaičiavimais gal net **** %) atsigabendavo iš tolimų ir ne tokių tolimų kraštų: iš Arabijos, iš Viduržemio jūros 55 salų – Kipro, Chijo ir Kretos, iš Nilo aukštupio. Ypač 333 kvepalų importas Egipte suklestėjo XIII a. pr. m. e, kai šalį valdė Ramzis Didysis.
also if i put 01 in front of 125 in data file, I get **** 99 1 *** in rezults file which shouldnt happen.Code:--------------------------- | Word | Start | Sum | --------------------------- | 17 | 37 | 8 | | 25 | 24 | 7 | | 10 | 64 | 1 | | 01 | 33 | 1 | | 22 | 27 | 4 | ---------------------------



LinkBack URL
About LinkBacks



