Help with a program

From: Joey JoJo Shabadoo Jr (eat_at_joes.com)
Date: 11/26/03


Date: Wed, 26 Nov 2003 01:22:49 GMT

Im working on a little program that allows a person to add/delete/list
movies to a database and I keep on getting these errors
program.cpp(16) : error C2511: 'movie::movie' : overloaded member function
'void (class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >,class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >,class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >,int,struct movie *)' not found in 'movie'
program.cpp(6) : see declaration of 'movie'

and

program.cpp(265) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

Now I know the last error is connected to the first, but I can't figure out
what Im doing wrong to get the first error. Any help will be welcome, thanks
Heres the source code:

#include <string>
#include <fstream>
using namespace std;

struct movie
{
 string title;
 string star;
 string genre;
 int year;
 movie* next;
 movie(string, string, string, int, string, movie*);
};

movie::movie(string tempTitle, string tempStar, string tempGenre, int
tempYear, movie* tempNext)
:title(tempTitle), star(tempStar), genre(tempGenre), year(tempYear),
next(tempNext)
{}

typedef movie* moviPtr;

void getline(istream &stream, string &str, char delimiter)
{ char temp[500];

 stream.get(temp, 500, delimiter);
 stream.ignore(500, delimiter);
 str = temp;
}

void getline(istream &stream, int &num, char delimiter)
{ int temp;

 stream >> temp;
 stream.ignore(500, delimiter);
 num= temp;
}

void readFile(moviPtr &root);
void insert (moviPtr &root);
void delTitle(moviPtr &root);
moviPtr locateNode(moviPtr temp, string titl);
void searchTitle(moviPtr temp);
void printList(moviPtr temp);
void saveFile(moviPtr temp);
int countNodes(moviPtr temp);

int main()
{
 int choice;
 moviPtr root = NULL;
 readFile(root);

 do
 {
  cout << "Menu- Go Ahead make my day\n\n";
  cout << "(1) Add a movie to the list\n";
  cout << "(2) Delete a movie\n";
  cout << "(3) Search for a movie.\n";
  cout << "(4) List all movies.\n";
  cout << "(5) Quit.\n\n";
  cout << "Choose, but choose wisely ---> ";

  cin >> choice;

  if (1 <= choice && choice <= 4)
  {
   switch (choice)
   {
   case 1:
    insert(root);
    break;
   case 2:
    delTitle(root);
    break;
   case 3:
    searchMovie(root);
    break;
   case 4:
    printList(root);
    break;
   default:
    cout << "That does not compute. Try again.\n\n";
    break;
   }
  }
 }
 while (choice != 5);
 saveFile(root);
 return 0;
}

void readFile(moviPtr &root)
{
 int numMovies, yea;
 string titl, star, genr;
 ifstream infile ("movies.dat", ios::in);
 infile >> numMovies;
 infile.ignore(500,'\n');
 for (int count = 0; count < numMovies; count++)
 {
  getline(infile, titl, '\n');
  getline(infile, star, '\n');
  getline(infile,genr, '\n');
  getline(infile,yea, '\n');

  root = new movie (titl, star, genr, yea, root);
 }
}

void insert (moviPtr &root)
{
 string titl, star, genr;
 int yea;

 cout << "Title:\t\t\t";
 cin.ignore(500,'\n');
 getline(cin, titl, '\n');
 cout << "Star:\t\t\t";
 getline(cin, star, '\n');
 cout << "Genre:\t\t";
 getline(cin, genr, '\n');
 cout << "Year:\t\t\t";
 getline(cin,yea, '\n');

 root = new movie (titl, star, genr, yea, root);
}

void delTitle(moviPtr &root)
{
 string titl;

 cout << "Movie Title:\t\t\t";
 cin.ignore(500,'\n');
 getline(cin, titl, '\n');

 moviPtr p = locateNode(root, titl);

 if (p == NULL)
  cout << "\nCannot be deleted.\n\n";
 else if (root == p)
  root = p->next;
 else
 {
  moviPtr q = root;
  while (q->next != p)
   q = q->next;
  q->next = p->next;
 }
 delete p;
}

moviPtr locateNode(moviPtr temp, string titl)
{
 while (temp != NULL)
 {
  if (temp->title == titl)
  {
   return temp;
  }
  temp = temp->next;
 }
 return NULL;
}

moviPtr locateNodeTitle(moviPtr temp, string titl)
{
 while (temp != NULL)
 {
  if (temp->title == titl)
  {
   return temp;
  }
  temp = temp->next;
 }
 return NULL;
}

void searchTitle(moviPtr temp)
{
 string titl;

 cout << "Movie Title:\t\t\t";
 cin.ignore(500,'\n');
 getline(cin, titl, '\n');

 while (temp != NULL)
 {
  if (titl == temp->title)
  {
   cout << temp->title << "\n";
   cout << temp->star << "\n";
   cout << temp->genre << "\n";
   cout << temp->year << "\n";
  }
  temp = temp->next;
 }
 cout << "\n";
}

void printList(moviPtr temp)
{
 while (temp != NULL)
 {
  cout << temp->title << "\n";
  cout << temp->star << "\n";
  cout << temp->genre << "\n";
  cout << temp->year << "\n\n";
  temp = temp->next;
 }
 cout << "\n";
}

void printStar(moviPtr temp)
{
 string star;

 cout << "Stars name:\t\t\t";
 cin.ignore(500,'\n');
 getline(cin, star, '\n');

 while (temp != NULL)
 {
  if (temp->star == star)
  {
   cout << temp->title << "\n";
   cout << temp->star << "\n";
   cout << temp->genre << "\n";
   cout << temp->year << "\n\n";
  }
  temp = temp->next;
 }
 cout << "\n";
}

void saveFile(moviPtr temp)
{
 int count = countNodes(temp);
 ofstream outFile("saved.dat",ios::out);

 outFile << count << "\n";
 while (temp != NULL)
 {
  outFile << temp->title << "\n";
  outFile << temp->star << "\n";
  outFile << temp->genre << "\n";
  outFile << temp->year << "\n";
  temp = temp->next;
 }
 cout << "\n";
}

int countNodes(moviPtr temp)
{
 int countB = 0;
 while (temp != NULL)
 {
  countB++;
  temp = temp->next;
 }
 return countB;
}



Relevant Pages

  • RE: FileSearch to locate the latest (last saved) file
    ... Dim sReport As Workbook, sDashboard As Workbook ... Dim fLdr As String, Fil As String, FPath As String, x As String, _ ... FileDates= temp ... For i = 1 To NewestFile ...
    (microsoft.public.excel.programming)
  • Re: Please explain the one string
    ... So we read the input files name and temp in a loop that much is clear from ... The formatting of the output is done is done in the first string. ... we are still in the file 'temp' but the line does not start with ALTER TABLE ... in a small script where you add comments and make sure that the file names ...
    (perl.beginners)
  • Re: locating strings approximately
    ... > I'd like to see if a string exists, even approximately, in another. ... > have looked at edit distance, but that isn't a good choice for finding ... if temp < dist: dist = temp ... dprev, dcurr = dcurr, dprev ...
    (comp.lang.python)
  • Re: Importing data from a textfile
    ... I don't know how many different types of string there are beforehand. ... temp = textscan; ... You can use it to break an arbitrarily long comma delimited list into a cell array of parts, then operate at will on the parts. ... Another think you might experiment with to speed things up is to read the entire file into memory with the 'fileread' command, and then use regex and cellfun to search the contents in memory. ...
    (comp.soft-sys.matlab)
  • Re: Unmanaged code(dll) function: int myfunc (char* temp)
    ... //Assigning an value to temp ... I am using char* not TCHAR* ... Can you help me how to get the value of temp when using string builder ... int myfunc ...
    (microsoft.public.dotnet.framework.compactframework)