Help with a program
From: Joey JoJo Shabadoo Jr (eat_at_joes.com)
Date: 11/26/03
- Next message: ellie fant: "Re: What a translation unit is."
- Previous message: Martijn Lievaart: "{OT} CDC (was Re: about BigEndian and LittleEndian)"
- Next in thread: Artie Gold: "Re: Help with a program"
- Reply: Artie Gold: "Re: Help with a program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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;
}
- Next message: ellie fant: "Re: What a translation unit is."
- Previous message: Martijn Lievaart: "{OT} CDC (was Re: about BigEndian and LittleEndian)"
- Next in thread: Artie Gold: "Re: Help with a program"
- Reply: Artie Gold: "Re: Help with a program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|