DATABASE MAKER

Hello guys!! I need some expert help!

I had tried to program a database maker. What it does is that it allows the user to at first make a template file which contains the required database's field names and other parameters, then with the help of that file to make the database, and enter data (char) into it. In short, if for example you wanna make a SCHOOL GRADE database with 3 fields, say, Roll num, Name and Grade, first, the template-maker block of my program takes these as inputs along with other stuff, and then provides the options to actually enter the data based on the template. The aim is so that my program can be used by anyone to make any simple database, with as many fields as required, and other criteria.

And by 'template', I mean a file which holds information regarding how data is to be saved in the database.

But, I am not an expert, and hence I am meeting with several syntax errors.

Can anyone help me? It's a school project, and this is my first 'big' program. Thanks in advance!

Here is the code: (It is incomplete, but...well....you should get an idea)

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

#define WAIT fflush(stdin);\
cout<<"\n\nPRESS ANY KEY TO CONTINUE...";\
cin.get();

#define FLUSH fflush(stdin);

#define CLEAR system("cls");

struct tmplate
{
unsigned short int numFields,batch;
char *nameFields;
bool options[5];
char nameDB[21],nameDBfile[25],nameDBtmp[29],instructions[501];
};


void main()
{

unsigned short int mainChoice;
char dbChoice,*data;
register short unsigned int i,j;
tmplate tmp;
fstream tmplatef,db;


while(1)
{
system("cls");
cout<<"\t\t\t\t SOHAIL'S Database Maker"; //title
cout<<"\n\n\n1) Make new database template\n2) Open database\n3) EXIT"; //MAAAAAAIN MENu
cout<<"\n\n\n\nEnter your choice number: ";
cin>>mainChoice;

switch(mainChoice)
{
case 3:
CLEAR
cout<<"HOPE YOU LIKED MY PROGRAM.....\n\n\nPress any key to continue...";
fflush(stdin);
cin.get();
exit(0);

case 1: //template maker
CLEAR
cout<<"How many fields do you want: ";
cin>>tmp.numFields;

tmp.nameFields=new char[tmp.numFields][31];

cout<<"\n\n\nEnter the field names one by one:\n\n";

for(i=0;i<=tmp.numFields-1;i++)
{
cout<<"Enter Field Name "<<i+1<<": ";
FLUSH
cin.getline(tmp.nameFields[i],30,'\n');
} //field names obtained

WAIT
CLEAR

cout<<"Database user-interface options: ";
cout<<"\n\n\nAdd new entry: ";
cin>>tmp.options[0];
cout<<"\nModify entry: ";
cin>>tmp.options[1];
cout<<"\nDelete entry: ";
cin>>tmp.options[2];
cout<<"\nShow all entry: ";
cin>>tmp.options[3];
cout<<"\nInstructions: ";
cin>>tmp.options[4];
CLEAR

if(tmp.options[4]==1)
{
cout<<"Please type your instructions in not more than 500 characters and in one para:\n\n\n";
FLUSH
cin.getline(tmp.instructions,500,'\n');
}
CLEAR

cout<<"Enter database name: ";
FLUSH
cin.getline(tmp.nameDB,20,'\n');
cout<<"\n\nEnter database filename: ";
FLUSH
cin.getline(tmp.nameDBfile,20,'\n');
CLEAR

strcpy(tmp.nameDBtmp,tmp.nameDBfile);
strcat(tmp.nameDBtmp,".tmplate");
strcat(tmp.nameDBfile,".txt");

tmplatef.open(tmp.nameDBtmp,ios::out); //template file created
/*if(tmplate==NULL)
{
CLEAR
cout<<"TEMPLATE CREATE ERROR.\nPLEASE RESOLVE ISSUES BEFORE RETRYING.";
WAIT
exit(1);
}*/
tmplatef.write((char*)&tmp,sizeof(tmplate);
tmplatef.close();
CLEAR
cout<<"\n\n\nTemplate successfully created and stored as "<<tmp.nameDBtmp<<" and database will be stored as "<<tmp.nameDBfile;
WAIT
break;

case 2:
CLEAR
cout<<"Enter database template name: ";
cin>>tmp.nameDBtmp;
db.open(tmp.nameDBfile,ios::out|ios::_Noreplace);
tmplatef.open(tmp.nameDBtmp,ios::in|ios::_Nocreate);
tmplatef.read((char*)&tmp,sizeof(tmplate));

while(1)
{
CLEAR //DB menu

if(tmp.options[0]==1)
cout<<"e) New data entry\n";
if(tmp.options[1]==1)
cout<<"m) Modify existing entry\n";
if(tmp.options[2]==1)
cout<<"d) Delete existing entry\n";
if(tmp.options[3]==1)
cout<<"l) List all data\n";
if(tmp.options[4]==1)
cout<<"i) Instructions\n";
cout<<"E) EXIT";

cout<<"\n\n\nEnter your choice: ";
cin>>dbChoice;
CLEAR

switch(dbChoice)
{
case 'e':
CLEAR
cout<<"Enter A for single entry, B for batch entry: ";
cin>>dbChoice;
CLEAR

if(dbChoice=='A')
{
for(i=0;i<=tmp.numFields-1;i++)
{
data=new char[tmp.numFields][52];
cout<<"\nEnter ";
for(j=0;j<=29;j++)
{
cout<<tmp.nameFields[i][j];
if((tmp.nameFields[i][j+1])=='\0')
break;
}
cout<<": ";
cin.getline(data[i][0],50,'\n');
strcat(data[i]," ");

}
db.seekp(0L,ios::end);
db.write((char*)data,(tmp.numFields*51));
delete data;
db<<"\n";

}

else if(dbChoice=='B')
{
cout<<"How many entry: ";
cin>>batch;
for(unsigned register short int k=0;k<=batch-1;k++)
{
cout<<"Entry no. "<<k+1<<"\n\n\n";
for(i=0;i<=tmp.numFields-1;i++)
{
data=new char[tmp.numFields][52];
CLEAR
cout<<"\nEnter ";
for(j=0;j<=29;j++)
{
cout<<tmp.nameFields[i][j];
if((tmp.nameFields[i][j+1])=='\0')
break;
}
cout<<": ";
cin.getline(data[i][0],50,'\n');
strcat(data[i]," ");

}
db.seekp(0L,ios::end);
db.write((char*)data,(tmp.numFields*51));
delete data;
db<<"\n";
}

}
else
cout<<"\n\nWRONG CHOICE!";
WAIT
continue;
}


}



}



}
}>
Last edited on
Can you please edit it and add in a code? It would be very helpful
Topic archived. No new replies allowed.