I've been struggling with this program for few several days now..
It's an implementation of Data structures. I'm trying to use Linked Lists, Sorting and Searching concepts.
#include<iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
using namespace std;
class videoShopSystem{
public:
bool empty() const;
void displayMainMenu();
void menuChoice(int key);
void addNewRecord();
void displayRecord();
void editRecord(); //editing
void deleteRecord();//deleting
void saveRecord(string filename);//saving
void loadRecord(string filename);//loading
void exit();
videoShopSystem():capacity(10), size(0)
{
head = tail = cur = prev = -1; //list is empty
data = new ListNode[capacity];
}
private:
class ListNode{
public:
int VideoID;
string VideoName;
int next;
ListNode():VideoID(0), next(-1){}
};
ListNode *data;
int size, capacity;
int head, tail, cur, prev;
};
void videoShopSystem::addNewRecord() //implementation of linked list
{
if(size!=capacity)
{
if(head == tail) {head = 0; tail = 0;}
cur = tail;
tail++;
cout << "Video Record ID: ";
cin >> data[cur].VideoID;
cout << "Movie/Video Title: ";
cin.ignore(1, '\n');
getline(cin, data[cur].VideoName);
cout <<endl;
size++;
}
else
cout<< "Capacity reached maximum!!!";
}
void videoShopSystem::displayRecord()
{
cout << "Video ID\t\tVideoName" <<endl;
cout << "------------------------------"<<endl;
for(int i=head; i<size; i++)
cout << data[i].VideoID <<"\t\t" <<data[i].VideoName<<endl;
}
/*
void videoShopSystem::editRecord()
{
cout << "Enter Record ID: ";
cin >> data[cur].VideoID;
}
*/
void videoShopSystem::saveRecord(string filename)
{
ofstream fout(filename.c_str());
if (fout.is_open())
{
if ( empty() )
{
cout << "Nothing on List. No Save" << endl;
system("PAUSE");
}else {
cur = head;//current is at start
while (cur != -1)// not at end
{
fout << data[cur].VideoID;
cur = data[cur].next;//loop to next until =-1(end)
}
}
}
else
{
cerr << "Can't open file " << filename << endl;//incase of error
system("PAUSE");
}
fout.close();
}
void videoShopSystem::displayMainMenu()
{
cout<< "---------------Video Shop System--------------" <<endl;
//cout<< "-----------------" <<endl;
cout<< " 1) Add New Record"<<endl;
cout<< " 2) View All Records"<<endl;
cout<< " 3) Edit Record"<<endl;
cout<< " 4) Delete Record"<<endl;
cout<< " 5) Save Record"<<endl;
cout<< " 6) Load Record"<<endl;
cout<< " 7) Quit"<<endl<<endl;
cout<< "Enter Choice: ";
}
void videoShopSystem::menuChoice(int key)
{
switch(key)
{
case 1: cout<<"# Add New Record #"<<endl;
addNewRecord();
break;
case 2: cout<<"# View All Records #"<<endl;
displayRecord();
break;
case 3: cout<<"# Edit Record #"<<endl;
break;
case 4: cout<<"# Delete Record #"<<endl;
break;
case 5: cout<<"# Save Record #"<<endl;
saveRecord(string filename);
break;
case 6: cout<<"# Load Record #"<<endl;
break;
case 7: cout<<"Game Over!"<<endl;
break;
}
system("pause");
system("cls");
}
int main(){
videoShopSystem obj1;
string filename;
int key;
do{
obj1.displayMainMenu();
cin >>key;
system("cls");
obj1.menuChoice(key);
}while(key!=7);
//system("pause");
return 0;
}
I'm currently working on the save function which is where I've hit a wall. At this point when I compile I get the following error..
In member function `void videoShopSystem::menuChoice(int)':
147 expected primary-expression before "filename"
What's wrong with my code ?