Database program issue in C++ -
i finished yet tour of debugging , @ loss once more.
the problem when open program , press buttons, takes me whole movie database display, though in 2nd menu.
i sorry bothering silly homework questions, , have 1 more. how display first 5 movies(5 lines) file out program.) how print first 5 lines(the first 5 lines txt fail) , previous 5 again?
my rather pathetic try listed below.example: @ first have memento , godfather. print next 5 godfather ii , shawshank redemption, leon, bittersweet life,se7en.now previous 5:memento, godfather,godfather ii, shawshank redemption, leon.
#include <iostream> #include <string> #include <fstream> using namespace std; void sisend(); /*input*/ string valik(); /*choice*/ void kogukuvand(); /* whole display of database */ void valjumine(); /* program quit*/ void sisendvoivaljumine(); /*quiting output file or not*/ void viisjuurde(); /* input further 5 lines file */ void viismaha(); /* input previous 5 lines file*/ int main() { system ("title filmide andmebaas"); /*movie database*/ system ("cls"); char valik; cout << "vajuta klahv 'j',kui tahad naha jargmist 5 kirjet."<< endl; /* j 5*/ cout << "vajuta klahv 'e',kui tahad naha eelmist 5 kirjet."<< endl; /* e previous 5 lines */ cout << "vajuta klahv 'v',kui tahad lopetada programmi taitumist."<< endl; /* v output */ cin >> valik; if(valik=='j') { viisjuurde(); } else if(valik=='e') { viisjuurde(); } else if(valik=='v') sisendvoivaljumine(); } void viisjuurde() { ifstream filmike("andmebaas.txt"); int n, sum = 5; string film; string vaadatud; int aasta; long int hinne; system ("cls"); cout << "kogu filmide andmebaas"<<endl; cout << "film" << " " << "aasta" << " " <<"hinne"<< " " << "vaadatud" << endl; cout << "------------------------------" << endl; while (filmike>> film >> aasta >> hinne >> vaadatud) { sum += n; cout << film << " " << aasta << " " << hinne << " " << vaadatud << endl; } { system ("pause"); cin.get(); main(); } } void viismaha() { ifstream filmike("andmebaas.txt"); int n, sum = -5; while (filmike >> n) { sum += n; } string film; string vaadatud; int aasta; long int hinne; system ("cls"); cout << "kogu filmide andmebaas"<<endl; cout << "film" << " " << "aasta" << " " <<"hinne"<< " " << "vaadatud" << endl; cout << "------------------------------" << endl; while (filmike>> film >> aasta >> hinne >> vaadatud) { cout << film << " " << aasta << " " << hinne << " " << vaadatud << endl; } system ("pause"); cin.get(); main(); } void sisend() /* user input */ { string nimi; int aasta; long int hinne; string vaadatud; ofstream lisafilm("andmebaas.txt", ios::app); cout <<"sisestage filmi nimi." << endl; /*enter film's name */ cin >> nimi; string film; cout << "sisestage filmi ilmumisaasta." << endl; /* enter film's year */ cin >> aasta; cout << "sisestage filmi hinne." << endl; /* enter film's rating */ cin >> hinne; cout << "kas olete filmi juba vaadanud?" << endl; /* has user seen movie already*/ cout << "vastake 'jah' voi 'ei'" << endl; cin >> vaadatud; cout << film << " " << aasta << " " << hinne << " " << vaadatud << endl; lisafilm<< nimi << " " << aasta << " " << hinne<< " " << vaadatud << endl; lisafilm.close(); main(); cout << "aitah kasutamast andmebaasi." << endl; system("pause"); cin.get (); } void valjumine() /*quiting without output */ { system("cls"); cout << "aitah kasutamast andmebaasi." << endl; system("pause"); cin.get (); } void kogukuvand() /* whole movie database*/ { ifstream filmike("andmebaas.txt"); string film; string vaadatud; int aasta; long int hinne; system ("cls"); cout << "kogu filmide andmebaas"<<endl; cout << "film" << " " << "aasta" << " " <<"hinne"<< " " << "vaadatud" << endl; cout << "------------------------------" << endl; while (filmike>> film >> aasta >> hinne >> vaadatud) { cout << film << " " << aasta << " " << hinne << " " << vaadatud << endl; } system ("pause"); cin.get(); main(); } void sisendvoivaljumine() { char valik2; system ("cls"); cout << "vajuta klahv 'j',kui tahad salvestada kirje ja v2ljuda programmist." << endl; /* output new movie file , quit*/ cout << "vajuta klahv 'e',kui ei taha salvestada kirje ja v2ljuda programmist." << endl; /*just quit, without output file*/ cout << "vajuta klahv 'k',kui tahad naha kogu filmide andmebaasi." << endl; /* display whole movie database*/ cin >> valik2; if(valik2=='j') { sisend(); } else if(valik2=='e') { valjumine(); } else if(valik2=='k') kogukuvand(); }
tricky because don't read language wrong
valik2
should char
.
if(valik='j')
should if(valik=='j')
. if(valik2='j')
should if(valik2=='j')
. common mistake,.same others.
void sisendvoivaljumine() { char valik2; system ("cls"); cout << "vajuta klahv 'j',kui tahad salvestada kirje ja v2ljuda programmist." << endl; /* output new movie file , quit*/ cout << "vajuta klahv 'e',kui ei taha salvestada kirje ja v2ljuda programmist." << endl; /*just quit, without output file*/ cout << "vajuta klahv 'k',kui tahad naha kogu filmide andmebaasi." << endl; /* display whole movie database*/ cin >> valik2; if(valik2=='j') { sisend(); } else if(valik2=='e') { valjumine(); } else if(valik2=='k') kogukuvand();
Comments
Post a Comment