The problem is when I open the program and press any buttons, it always takes me to the whole movie database display, even though it is in the 2nd menu.
I am sorry with bothering you with silly homework questions, and I even have one more. How to display first 5 movies(5 lines) from the file out to program.) How to print the first 5 lines(the first 5 lines from the txt fail) and then the previous 5 again?
My rather pathetic try is listed below.Example: At first you have Memento , Godfather. You print the next five Godfather II , Shawshank Redemption, Leon, A 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(); /* the whole display of the database */
void valjumine(); /* program quit*/
void sisendvoivaljumine(); /*quiting with output to file or not*/
void viisjuurde(); /* input further 5 lines from the file */
void viismaha(); /* input previous 5 lines from the 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 to get extra 5*/
cout << "Vajuta klahv 'e',kui tahad naha eelmist 5 kirjet."<< endl; /* e for previous 5 lines */
cout << "Vajuta klahv 'v',kui tahad lopetada programmi taitumist."<< endl; /* v for the 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 the user seen the 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() /* the 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()
{
int valik2;
system ("CLS");
cout << "Vajuta klahv 'j',kui tahad salvestada kirje ja v2ljuda programmist." << endl; /* output new movie to file and quit*/
cout << "Vajuta klahv 'e',kui ei taha salvestada kirje ja v2ljuda programmist." << endl; /*just quit, without any output to file*/
cout << "Vajuta klahv 'k',kui tahad naha kogu filmide andmebaasi." << endl; /* display the whole movie database*/
cin >> valik2;
if(valik2=='j')
{
sisend();
}
else if(valik2=='e')
{
valjumine();
}
else if(valik2=='k')
kogukuvand();
}
This post has been edited by needhelpest: 18 March 2013 - 01:44 AM

New Topic/Question
Reply



MultiQuote





|