I've been trying to convert my Modular programming code from array to link list.. the whole program is kinda messy now.. could anyone help me figure out what problem am having with the code?
PS: am using Vc++6 to compile...
Thanks in Advance
I've been trying to convert my Modular programming code from array to link list.. the whole program is kinda messy now.. could anyone help me figure out what problem am having with the code?
PS: am using Vc++6 to compile...
Thanks in Advance
#include "vcdrec.h"
struct TListNode{
vcdRec_T vcd;
int element;
int n;
TListNode *next;
};
typedef TListNode* TptrNode;
void EmptyList (TptrNode &head);
void Insert (vcdRec_T n, TptrNode &head);
void InsertEnd (vcdRec_T n, TptrNode &head);
void InsertFront (vcdRec_T n, TptrNode &head);
void DisplayAll(TptrNode head);
void Delete (vcdRec_T &n, TptrNode &head, int &element);
void DeleteEnd (vcdRec_T &n, TptrNode &head);
void DeleteFront(vcdRec_T &n, TptrNode &head);
bool Search (TptrNode &head, int element);
int Length(TptrNode head);
#include <iostream>
#include "prompt.h"
#include <string>
using namespace std;
Get_int_from_prompt(string prompt, int &num)
{
cout<<prompt<<"==>";
cin>>num;
return 0;
}
Get_string_from_prompt(string prompt, string &title)
{
cout<<prompt<<"==>";
cin>>title;
return 0;
}
Get_double_from_prompt(string prompt, double &price)
{
cout<<prompt<<"==>";
cin>>price;
return 0;
}
Get_copy_from_prompt(string prompt, int ©)
{
cout<<prompt<<"==>";
cin>>copy;
return 0;
}
#include <string>
using namespace std;
Get_int_from_prompt(string prompt, int &num);
Get_string_from_prompt(string prompt, string &title);
Get_double_from_prompt(string prompt, double &price);
Get_copy_from_prompt(string prompt, int ©);
#include "vcdDB.h"
#include <iostream>
#include <fstream>
using namespace std;
// PRE: true
// POST: vcdDB initialised
void Init_vcdDB(vcdDB_T &vcdDB)
{
EmptyList(vcdDB.head);
cout<<"Reinitializing the Pooter VCD library system"<<endl;
}
// PRE: true
// POST: IF vcdDB is empty
// RETURNS TRUE
// ELSE
// RETURNS FALSE
bool Q_Empty_vcdDB(vcdDB_T vcdDB)
{
return (vcdDB.head==NULL);
}
// PRE: true
// POST: IF vcdDB is full
// RETURNS TRUE
// ELSE
// RETURNS FALSE
/*bool Q_Full_vcdDB(vcdDB_T vcdDB)
{
return (vcdDB.vcdIndex == maxSize);
}*/
// PRE: true
// POST: IF vcd with number Num in vcdDB
// RETURNS TRUE
// ELSE
// RETURNS FALSE
bool Q_Present_vcdDB(int num, vcdDB_T vcdDB)
{
if (Search( vcdDB.head, num))
{
return true;
}
else
{
return false;
}
}
// PRE: NOT Q_Full_vcdDB(VCD) AND
// NOT Q_Present_vcdDB(Get_num(CRec), vcdDB, _)
// POST: CRec is added
void Add_vcd(vcdRec_T &vcd, vcdDB_T &vcdDB)
{
InsertEnd(vcd,vcdDB.head);
}
// PRE: Q_Present(vcdno, vcdDB, _)
// POST:IF vcd with number Num deleted from vcdDB
// RETURNS TRUE
// ELSE
// RETURNS FALSE
void Delete_vcd(int num, vcdDB_T &vcdDB, vcdRec_T &vcd)
{
Delete(vcd, vcdDB.head, num);
}
// PRE: true
// POST: All records printed to screen
void Print_All_vcdDB(vcdDB_T vcdDB)
{
DisplayAll(vcdDB.head);
}
// PRE: true
// POST: Save Records to a File
/*void Save_vcdDB_To_Text_file(vcdDB_T &vcdDB, ofstream &files)
{
int i;
for(i=1;i<=vcdDB.vcdIndex;i++)
{
Save_Record_To_File(files, vcdDB.vcdRecords[i]);
cout<<"File saved to VCD.dat"<<endl;
cout<<"#";
}
cout<<endl;
}
void Load_vcdDB_from_Text_file(vcdDB_T &db, ifstream &files)
{
vcdRec_T Next;
while (!files.eof() && !Q_Full_vcdDB (db))
{
Load_Record_From_File(files,Next);
Add_vcd(Next, db);
cout<<"#";
}
cout<<"File loading from VCD.dat"<<endl;
files.close();
}*/
//#include "vcdrec.h"
#include <fstream>
#include "List.h"
#define maxSize 20
struct vcdDB_T{
TptrNode head;
int n;
};
// PRE: true
// POST: vcdDB initialised
void Init_vcdDB(vcdDB_T &vcdDB);
// PRE: true
// POST: IF vcdDB is empty
// RETURNS TRUE
// ELSE
// RETURNS FALSE
bool Q_Empty_vcdDB(vcdDB_T vcdDB);
// PRE: true
// POST: IF vcdDB is full
// RETURNS TRUE
// ELSE
// RETURNS FALSE
bool Q_Full_vcdDB(vcdDB_T vcdDB);
// PRE: true
// POST: IF vcd with number Num in vcdDB
// RETURNS TRUE
// ELSE
// RETURNS FALSE
bool Q_Present_vcdDB(int num, vcdDB_T vcdDB);
// PRE: NOT Q_Full_vcdDB AND
// NOT Q_Present_vcdDB(Get_vcdno(CRec), vcdDB, _)
// POST: CRec is added
void Add_vcd(vcdRec_T &vcd, vcdDB_T &vcdDB);
// PRE: Q_Present(vcdno, vcdDB, _)
// POST:IF vcd with number Num deleted from vcdDB
// RETURNS TRUE
// ELSE
// RETURNS FALSE
void Delete_vcd(int num, vcdDB_T &vcdDB, vcdRec_T &vcd);
// PRE: true
// POST: All records printed to screen
void Print_All_vcdDB(vcdDB_T vcdDB);
//void Add_vcd(vcdDB_T &db, vcdRec_T &vcd);
//void Save_vcdDB_To_Text_file(vcdDB_T &vcdDB, ofstream &files);
//void Load_vcdDB_from_Text_file(vcdDB_T &db, ifstream &files);
#include "vcdDB.h"
#include "prompt.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void main_loop(vcdRec_T &vcd, vcdDB_T &db);
//void Init_vcdDB(vcdDB_T vcdDB);
void User_write_vcdRec(vcdDB_T vcdDB)
{
Print_All_vcdDB(vcdDB);
//write_vcdRec(vcd);
}
void User_Add_vcd(vcdRec_T &vcd, vcdDB_T &vcdDB)
{
int num, copy;
string title;
double price;
system("cls");
Get_int_from_prompt ("vcd num", num);
if (! Q_Present_vcdDB (num, vcdDB ))
{
Get_string_from_prompt ("vcd title", title);
Get_double_from_prompt ("vcd price", price);
Get_copy_from_prompt ("vcd copies", copy);
Set_num(vcd, num);
Set_title (vcd,title);
Set_price(vcd, price);
Set_copy(vcd, copy);
Add_vcd(vcd, vcdDB);
}
else
cout<<"num already exist"<<endl;
}
void User_Delete_vcd(vcdRec_T &vcd, vcdDB_T &vcdDB)
{
int num;
if (!Q_Empty_vcdDB(vcdDB))
{
Get_int_from_prompt("VCD number", num);
if (Q_Present_vcdDB (num, vcdDB))
{
Delete_vcd(num, vcdDB, vcd);
}
else
cout<<"ID is not exist."<<endl;
}
else
cout<<"Product DB is empty."<<endl;
}
/*void User_Save_vcdDatabase_To_Text_file(vcdDB_T &vcdDB)
{
ofstream files;
if(!Q_Empty_vcdDB(vcdDB))
{
files.open("vcd.dat");
Save_vcdDB_To_Text_file(vcdDB, files);
files.close();
}
else
cout<<"Empty database, There is nothing to save!"<<endl;
}
void User_Load_vcdDatabase_From_Text_file(vcdDB_T &db)
{
ifstream files;
if(!Q_Empty_vcdDB(db))
{
files.open("vcd.dat");
Load_vcdDB_from_Text_file(db, files);
}
else
cout<<"There's no data to load"<<endl;
}*/
int main()
{
vcdRec_T vcd;
vcdDB_T db;
Init_vcdDB(db);
main_loop(vcd, db);
return 0;
}
void main_loop(vcdRec_T &vcd, vcdDB_T &db)
{
char Option;
Option='m';
while (Option !='x')
{
cout<<"==========VCD Menu ==========================\n";
cout<<"== (r)einitialize all database to empty ==\n";
cout<<"== (a)dd vcd to DB =======\n";
cout<<"== (d)isplay vcd =======\n";
cout<<"== d(e)lete vcd =======\n";
cout<<"==(s)ave record =======\n";
cout<<"==(l)oad record =======\n";
cout<<"==(m)enu =======\n";
cout<<"==e(x)it =======\n";
cout<<"================================================\n";
cout<<"Please Enter Option: "<<endl;
cin>>Option;
switch (Option)
{
case 'r': case 'R': Init_vcdDB(db); break;
case 'a': case 'A': User_Add_vcd(vcd, db); break;
case 'd': case 'D': User_write_vcdRec(db);break;
case 'e': case 'E': User_Delete_vcd(vcd, db); break;
// case 's': case 'S': User_Save_vcdDatabase_To_Text_file(db); break;
// case 'l': case 'L': User_Load_vcdDatabase_From_Text_file(db); break;
}
}
}
#include "vcdrec.h"
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
void Set_num(vcdRec_T &vcd, int num)
{
vcd.num=num;
}
void Set_title(vcdRec_T &vcd, string title)
{
vcd.title=title;
}
void Set_price(vcdRec_T &vcd, double price)
{
vcd.price=price;
}
void Set_copy(vcdRec_T &vcd, int copy)
{
vcd.copy=copy;
}
// Get value
int Get_num(vcdRec_T vcd)
{
return vcd.num;
}
string Get_title(vcdRec_T vcd)
{
return vcd.title;
}
double Get_price(vcdRec_T vcd)
{
return vcd.price;
}
int Get_copy(vcdRec_T vcd)
{
return vcd.copy;
}
// write
void write_vcdRec(vcdRec_T vcd)
{
cout<<"NUMER"<< vcd.num<<endl;
cout<<"TITLE"<< vcd.title<<endl;
cout<<"PRICE"<< vcd.price<<endl;
cout<<"COPIES"<< vcd.copy<<endl;
}
void Load_Record_From_File(ifstream &files, vcdRec_T &vcd)
{
files>>vcd.num;
files>>vcd.title;
files>>vcd.price;
files>>vcd.copy;
}
void Save_Record_To_File(ofstream &files, vcdRec_T vcd)
{
files<<vcd.num<<endl;
files<<vcd.title<<endl;
files<<vcd.price<<endl;
files<<vcd.copy<<endl;
}
#include <string>
//#include <ofstream>
using namespace std;
struct vcdRec_T{
int num;
string title;
double price;
int copy;
};
void Set_num(vcdRec_T &vcd, int num);
void Set_title(vcdRec_T &vcd, string title);
void Set_price(vcdRec_T &vcd, double price);
void Set_copy(vcdRec_T &vcd, int copy);
int Get_num(vcdRec_T vcd);
string Get_title(vcdRec_T vcd);
double Get_price(vcdRec_T vcd);
int Get_copy(vcdRec_T vcd);
int Get_vcd(vcdRec_T vcd);
void write_vcdRec(vcdRec_T vcd);
void Load_Record_From_File(ifstream &files, vcdRec_T &vcd);
void Save_Record_To_File(ofstream &files, vcdRec_T vcd);
Just a bit of advice. No one is going to download all these files. You should provide the code with the errors and try to explain. Help us to help you.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.