OK. heres the code (i used two limit files)
Code:
#include <iostream>
#include <fstream>
#include <math.h>
#include <time.h>
#include <iomanip>
#include <conio.h>
#include <string>
#include <cmath>
#include <cstdlib>
#include <stdlib.h>
#include <limits.h>
#include <limits>
#include <stdio.h>
#include <cctype>
#include <ctype.h>
#include <cstdlib>
#include <windows.h>
using namespace std;
bool checkFile(char filename[255])
{
ifstream check (filename);
if (check)
return 0;
else
return 1;
}
class movie
{
public:
string title;
string cat;
string genre;
movie *next;
};
int mainMenu()
{
int option;
cout << "+-----------------------------+" << endl;
cout << "| MAIN MENU |" << endl;
cout << "+-----------------------------+" << endl <<
"| 1. Enter a new movie |" << endl <<
"| 2. Show media |" << endl <<
"| 3. Search media |" << endl <<
"| 4. Help |" << endl <<
"| 5. About |" << endl <<
"| 6. Quit |" << endl <<
"+-----------------------------+" << endl <<
"| :ENTER AN OPTION: |" << endl <<
"+-----------------------------+" << endl;
cin >> option;
cin.ignore(numeric_limits<streamsize>::max(),'\n');
return option;
}
void decide(int opt, movie *head)
{
string title;
string cat;
string genre;
int a = 0;
ifstream check ("movie.ini");
if (!check)
{
a = 1;
}
check.close();
if (opt == 1)
{
cout << "Enter movie title: ";
getline(cin,title,'\n');
cout << "Enter movie category: ";
getline(cin,cat,'\n');
cout << "Enter movie genre: ";
getline(cin,genre,'\n');
ofstream fOut ("movie.ini", ios::app);
if (a != 1)
fOut << endl;
fOut << title << endl << cat << endl << genre;
fOut.close();
}
if (opt == 2)
{
int cnt = 1;
movie *list;
list = head;
system("cls");
cout << setw(3) << left << "#" << setw(40) << left << "Movie" << setw(17) << left << "Category" << setw(17) << left << "Genre\n" << endl;
while (list != NULL)
{
cout << setw(3) << left << cnt << setw(40) << left << list->title << setw(17) << left << list->cat << setw(17) << left << list->genre << endl;
list = list->next;
cnt++;
}
}
if (opt == 4)
cout << endl << endl << " -- Error opening help file!" << endl << endl;
if (opt == 5)
MessageBox(NULL,"(C) 1991-2006 Matt Nesterenko","About Media Manager",MB_OK);
if (opt == 6)
exit(0);
}
void menu(string menu, movie *head)
{
int opt;
if (menu == "main")
opt = mainMenu();
decide(opt, head);
}
void orderInsert(movie *head, movie *mNode)
{
bool done = false;
movie *prev;
movie *curr;
prev = curr = head;
if (mNode->title <= head->title)
{
mNode->next=head;
head=mNode;
}
else
{
while (curr != NULL && !done)
{
if (mNode->title <= curr->title)
{
mNode->next = curr;
prev->next = mNode;
done = true;
}
prev = curr;
curr = curr->next;
}
if (!done)
prev->next = mNode;
}
}
int main (int argc, char *argv[])
{
movie *head;
movie *mNode;
movie *tail;
char title[255], cat[255], genre[255];
while (1)
{
ifstream input( "movie.ini");
head = tail = NULL;
if (input)
{
while (input.getline(title, 255, '\n') &&
input.getline(cat, 255, '\n') &&
input.getline(genre, 255, '\n'))
{
mNode = new movie;
mNode->title = title;
mNode->cat = cat;
mNode->genre = genre;
mNode->next = NULL;
if (head == NULL)
head = mNode;
else
orderInsert(head,mNode);
}
}
menu("main", head);
cout << endl << endl;
system("pause");
system("cls");
}
system("pause");
return 0;
}