mam taki koncept programu, w którym jest do przerobienia prawie wszystko od dodania menu, interface (np Tekran z syfonii), posprzątanie maina, et cetera, et cetera... (jak bym widział celowość to przerobię i wrzucę na gita, ale na moje potrzeby wystarczy więc celowości na razie nie ma). Działa tak że jeżeli jest plik words.txt w pliku katalogu (słowo_angielskie/ polskie słowa .. parę lini musi być), wychodzi się wpisując "exit(0)";
#include <iostream>
#include <string>
class line {
using string=std::string;
public:
bool checkEN (const string & TapeWord) {
// bool correct= wordEN.find(TapeWord)==string::npos ?0:1;
if(TapeWord =="exit(0)") exit(0);
bool correct = (wordEN==TapeWord) ?1:0;
if (correct) {
errors--;
} else
errors++;
return correct;
}
int getcharnum () {
return charnum;
}
void setcharnum (int i) {
charnum=i;
}
int geterrors() {
return errors;
}
void coutPL() {
std::cout<<wordsPL<<"("<<errors<<")"<<'-';
}
void coutEN() {
std::cout<<wordEN<<'\n';
}
private:
int errors=3;
string wordEN;
string wordsPL;
int charnum;
char sepENPL = '/';
friend std::istream & operator >> (std::istream & is, line & l) {
getline (is,l.wordEN,l.sepENPL);
getline(is,l.wordsPL);
l.setcharnum(l.wordsPL.size()+1+l.wordEN.size()+2);
return is;
}
friend std::ostream & operator << (std::ostream & os, const line & l) {
return os<<l.wordEN<<std::endl<<l.wordsPL<<std::endl;//<<l.errors<<std::endl;
}
}l;
#include <fstream>
class fgetline {
public:
fgetline (std::string name,int ptr=0):namef(name),ptrtellg(ptr){
file.open(namef);
if(file) {
file.seekg(0,file.end);
sizeoffile=file.tellg();
file.seekg(0,file.beg);
if(ptrtellg>sizeoffile){
std::cout<<"zbyt duza liczba\n zaczynamy od poczatku pliku"<<std::endl;
ptrtellg=0;
}
file.seekg(ptrtellg);
std::string byte;
getline(file,byte);
ptrtellg+=byte.size()+2;
file.close();
} else {
std::cout<<"nok konstruktor";
exit(1);
}
}
void open (line & l) {
if(!file.is_open())
file.open(namef);
if(file) {
file.seekg(ptrtellg);
file>>l;
// std::cout<<l;
ptrtellg+=l.getcharnum();
// std::cout<<ptrtellg<<std::endl;
} else {
std::cout<<"nok open";
std::cout<<ptrtellg<<std::endl;
exit(1);
}
}
void close () {
file.close();
}
bool endoffile() {
return ptrtellg<sizeoffile?1:0;
}
private:
line l;
int ptrtellg;
int sizeoffile;
std::string namef;
std::ifstream file;
}f("words.txt",10);
#include <algorithm>
#include <random>
#include <vector>
using namespace std;
int main() {
std::random_device randomDevice;
std::mt19937 generator(randomDevice());
int amountofwords=4;
int sectionsofword=10;
vector <line> v(amountofwords);
for(auto &x:v) {
f.open(l);
x=l;
}
f.close();
//for(auto x:v)
// cout<<x;
while (1/*sectionsofword--*/) {
std::shuffle(begin(v), end(v), generator);
for( auto &x:v)
if(x.geterrors()) {
bool reperatwordbool=1;
while(reperatwordbool) {
x.coutPL();
string s;
cin>>s;
if(x.checkEN(s)) {
reperatwordbool=0;
} else {
x.coutPL();
x.coutEN();
}
}
} else {
f.open(l);
x=l;
f.close();
}
}
return 0;
}
edit:: jak by kogoś interesowało czemu wczytanie zaczyna się od 2 linii. W pierwszej miał być zapisywany postęp nauki. I przepraszam wszystkich co znają trochę C++, bo ten kod aż kuje w oczy, a przede wszystkim budowa klas i pewnie 1000 innych rzeczy o których nie mam pojęcia (powstał porostu z potrzeby chwili)