-2
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<process.h>
#include<stdio.h>
#include<string.h>
int access=0;                     // for accessing data modifier functions
int report_s=0;
int report_u=0;
class element
{
int at_no;
float mass_no;
char name[15];
char symbol[4];
int group,period;                     //for displaying the table
public:

void input()
{
cout<<"enter elements name \n";
gets(name);
cout<<"enter its symbol \n";
gets(symbol);
cout<<"enter its atomic number \n";
cin>>at_no;
cout<<"enter its mass number\n";
cin>>mass_no;
cout<<"enter its group number\n";
cin>>group;
cout<<"enter its period number\n";
cin>>period;
}
void output()
{
cout<<"elements name:"<<name<<"\n";
cout<<"symbol:"<<symbol<<"\n";
cout<<"atomic number:"<<at_no<<"\n";
cout<<"mass number:"<<mass_no<<"\n";
}
char*sym()
{return symbol;}
char *nam()
{return name;}
int atno()
{return mass_no;}
int ret_period()
{return group;}
}e;

struct user
{ 
char name[20];
private:
char password[10];
public:
void input()
{
cout<<"\nenter name";
gets(name);
cout<<"\nenter password:\n";
gets(password);
}
char*getpassw()
{return password;}
void inpass()
{
cout<<"enter password\n";
gets(password);
}
}
u;
void report(element,char);
void report();
void login()
{
access=0;
int i;
char ch;
do
{
clrscr();
cout<<"\t\t\t\tlogin menu\n\n";
cout<<"enter type of user:\n\n";
cout<<"\t\t1.new user\n";
cout<<"\t\t2.existing user\n";
cout<<"\t\t3.quit\n\n\n";
cout<<"your choice";
cin>>ch;
switch(ch)
{
case '1':
{
int presence=0;        //for  checking presence of record (user)
u.input();
user b;
ifstream fin("users.dat",ios::binary|ios::in);
if(!fin)
cout<<"error";
while(!(fin.eof()))
{
if(fin.eof())
break;
fin.read((char*)&b,sizeof(user));
if(strcmp(b.name,u.name)==0)
{
cout<<"name exists, try again";
getch();
fin.close();
presence=1;          //presence is true
break;
}                             // end of if
break;                // break for case 1
}                        // close of case 1
case '2':
{
int i=0;
u.input();
user b;
ifstream fin("users.dat",ios::binary|ios::in);
if(!fin)
cout<<"error";
while(!(fin.eof()))
{
if(fin.eof())
break;
fin.read((char*)&b,sizeof(user));
if((strcmp(b.name,u.name)==0)&&(strcmp(b.getpassw(),u.getpassw())==0))
{
if(strcmp(u.name,"administrator")==0)
{
fin.close();
access=1;
return;
}                                 //close of inner if
fin.close();
return;
} //close of if
if(strcmp(u.name,b.name)==0)
{
for(i=0;i<3;)
{
cout<<"enter the correct password \n";
u.inpass();
if(strcmp(u.getpassw(),b.getpassw())==0)
{
if(strcmp(u.name,"administrator")==0)
access=1;
return;
}
else
i++;
}    // close of loop
}  // close of if
if(i>=3)
{
cout<<"invalid password. program will now terminate";
fin.close();
getch();
exit(0);
}
}  // close of while
cout<<"user not found";
getch();
break;
}    //close of case 2
case '3':
{
clrscr();
char opt;
 cout<<"are you sure? (y/n) \n";
cin>>opt;
if(opt=='y')
{
clrscr();
gotoxy(33,13);
cout<<"thank you";
getch();
exit(0);
}
break;
}
default:
{
cout<<"enter a valid option";
getch();
}   // close of switch
} while(1);  //close of do while
}   // close of function
void disp_period()
{
clrscr();
ifstream fin("period.dat",ios::binary|ios::in);
if(!fin)
cout<<"error";
cout<<"\t\t\t the modern periodic table";
while(!fin.eof())
{
if(fin.eof())
break;
fin.read((char*)&e,sizeof(element));
gotoxy(4*e.ret_group()),(e.ret_period+5));
cout<<e.sym();
}
fin.close();
getch();
}
void search()
{
char ch;
int result=0;                //for checking success of  search
do
{
result=0;
clrscr();
cout<<"\t\t\tthe periodic table\n\n";
cout<<"\t\tsearch modes available \n\n";
cout<<"1.element symbol\n";
cout<<"2.element name\n";
cout<<"3.atomic number\n";
cout<<"4.return to main memory\n";
cout<<"your choice:";
cin>>ch;
ifstream a("period.dat",ios::binary);
if(!a)
cout<<"error";
switch(ch)
{
case '1':
{
char symbol[3];
cout<<"enter the elements symbol\n";
gets(symbol);
while(!(a.eof()))
{
if((a.eof()))
break;
a.read((char*)&e,sizeof(element));
if(strcmpi(e.sym(),symbol)==0)
{
e.output();
report(e,'s');     //for sending result of search to report()
getch();
result=1;
break;
}
}
a.close();
break;
}
case '2':
{
char name[20];
cout<<"enter the elements name\n";
gets(name);
while(!a.eof())
{
if(a.eof())
break;
a.read((char*)&e,sizeof(element));
if(strcmpi(e.nam(),name)==0)
{
e.output();
report(e,'s');
getch();
result=1;
break;
}
}
a.close();
break;
}
case'3':
{
int atno;
cout<<"enter the elements atomic no.\n";
cin>>atno;
while(!(a.eof()))
{
if((a.eof()))
break;
a.read((char*)&e,sizeof(element));
if(e.atno()==atno)
{
e.output();
report(e,'s');
getch();
result=1;
break;
}
}
a.close();
break;
}
case '4' : return;                                                     //no need break as the control is passed on,
                                                                                 //fall through does not occur
default:
{
cout<<"enter a valid option";
getch();
}
}
if(!result)
{
cout<<"sorry, no entry found";
getch();
}
}while(1);
}
void period_det()
{
int presence;                                      // for checking presence of element in database
char ch;
do
{
presence=0;
clrscr();
cout<<"\t\tperiodic table details \n\n";
cout<<"1. add element \n";
cout<<"2. modify element\n";
cout<<"3. display periodic table\n";
cout<<"4. return to main menu\n";
cout<<"enter your choice : ";
cin>>ch;
switch(ch)
{
case '1' :
{
if(access)
{
element e3;
e.input();
ifstream a("period.dat",ios::binary);
if(!a)
cout<<"error";
a.seekg(0);
while(!a.eof())
{
if(a.eof())
break;
a.read((char*)&e3,sizeof(element));
if(strcmpi(e3.sym(),e.sym())==0) || (strcmpi(e3.nam(),e.nam())==0) || (e3.atno()==e.atno()) || ((e3.ret_period))==e.ret_period())&&(e3.ret_group()==e.ret_group())) || (e3.massno()==e.massno())
{e3.output();presence=1;break;}
}
a.close();
if(!presence)
{
ofstream b("period.dat",ios::binary|ios::app);
if(!b)
cout<<"error";
b.write((char*)&e,sizeof(element));
cout<<"element added\n";
getch();
b.close();
report(e,'u');
}
else
{
cout<<"element already present";
getch();
}
break;
}
else
{
clrscr();
cout<<"access denied";
getch();
break;
}
}
case '2' :
{
if(access)
{
int result=0;
char ele_name[20];
cout<<"enter name of element to be modified\n";
gets(ele_name);
fstream f("period.dat",ios::binary|ios::in|ios::out);
if(!f)
cout<<"error";
f.seekg(0);
while(!f.eof())
{
if(f.eof())
break;
f.read((char*)&e,sizeof(element));
if(strcmpi(ele_name,e.nam())==0)
{
result=1;
char choice;
e.output();
cout<<"do you want to modify this record(y/n)";
cin>>ch;
if(ch=='y'||ch=='y')
{
f.seekp(f.tellg()-(sizeof(element)));
e.input();
ifstream g("period.dat",ios::binary);
if(!g)
cout<<"error";
element h;
int unique =1;
while(!g.eof())
{
if(g.eof())
break;
g.read((char*)&h,sizeof(element));
if((strcmpi(h.sym(),e.sym())==0) || (strcmpi(h.nam(),e.nam())==0) || (h.atno()==e.atno())
|| (h.ret_period()==e.ret_period()0&&(h.ret_group()==e.ret_group())) || (h.massno()==e.massno()))
{unique=0;
cout<<"element with modified data exists\n";
h.output();
getch();
break;
}
}
if(unique)
{f.write((char*)&e,sizeof(element));
report(e,'u');
cout<<"record edited";
getch();
}
break;
}
}
}
if(!result())
cout<<"no such record found";
getch();
f.close();
break;
}
else {
clrscr();
cout<<"access denied";
getch();
break;
}
}
case '3':
{
disp_period();
break;
}
case '4':
{
return;
}
default:
cout<<"enter a valid option";
getch();
}
}while(1);
}
void report(element e,char type)
{
if(type=='s')
{
report_s=1;
ofstream fout("reportsearch.dat",ios::binary|ios::app);
if(!fout)
cout<<"error";
else
fout.write((char*)&e,sizeof(element));
fout.close();
}
}
void report()
{
ifstream fin("reportsearch.dat",ios::binary);
if(!fin)
cout<<"error";
else
{
if(report_s)
{
clrscr();
cout<<"\tsearch report\n";
while(!fin.eof())
{
fin.read((char*)&e,sizeof(element));
if(fin.eof())
break;
e.output();
getch();
}
fin.close();
cout<<"end  of search report";
getch();
}
else
{
clrscr();
cout<<"no search report found\n";
getch();
{
if(access)
{
if(report_u)
{
ifstream fin("reportupdate.dat",ios::binary);
if(!fin)
cout<<"error";
else
{
clrscr();
cout<<"\tupdate report\n";
while(!fin.eof())
{
fin.read((char*)&e,sizeof(element));
if(fin.eof())
break;
e.output();
getch();
}
fin.close();
cout<<"end of update report";
getch();
}
}
else {
clrscr();
cout<<"no update report found";
getch();
}
}
}
}
void main()
{
ofstream z("reportsearch.dat",ios::binary|ios::trunc);
if(!z)
cout<<"error";
z.close();
ofstream y("reportupdate.dat",ios::binary|ios::trunc);
if(!y)
cout<<"error";
y.close();
clrscr();
highvideo();
char ch;
gotoxy(25,12);
highvideo();
cout<<"welcome to the periodic table\n";
getch();
login();
do
{
clrscr();
cout<<"\t"<<"\t"<<"the periodic table\n\n";
cout<<"1. periodic table details\n";
cout<<"2. search for element \n";
cout<<"3. report\n";
cout<<"4.switch user\n";
cout<<"5. quit\n";
cout<<" enter you choice";
cin>>ch;
switch(ch)
{
case '1': period_det(); break;
case '2': search(); break;
case '3': report(); break;
case '4': login(); break;
case '5': clrscr();
char opt;
cout<<"are you sure?? (y/n) \n";
cin>>opt;
if(opt=='y')
{
clrscr();
gotoxy(33,13);
cout<<"thank you";
getch();
exit(0);
}
break;
default:cout<<"enter a valid option";
getch();
}
}while(1);
}
Votes + Comments
That Sir, is your duty!
5
Contributors
4
Replies
5
Views
4 Years
Discussion Span
Last Post by Ketsuekiame
0

are you kidding me ?
Use some legit spaces and search for yourself or find a IDE who can show you open and closing braces.
Or you could find the problem by looking into the error you get compiling that ?

Edit :

Ok looking further at the code there are many errors. I think you can give up,
nobody's going to look over the whole code for you.

Edited by Dman01

0

please correct the problem with the Braces...

What do you mean by "problem with the braces"? Are you referring to code indentation?
If so, run your code through a code formatter / code beautifier.
If you're using an IDE look if there's an option available, most IDEs come with a code formatter.

Edited by mvmalderen

0

Visual Studio: CTRL+A, CTRL+K, CTRL+F

On the off-chance it might be a simple solution I put it into Visual Studio myself.

I added brackets to the end to make them match, but the problem goes WAY beyond that. Intellisense actually gave up trying to make sense of the code =/

From what I can see, you've got a bad case of "copy pasting without knowing what you're doing". The cure for this is a combination of google, common sense and education. Good luck. Failing that, quit now before it becomes terminal!

In another note, I haven't seen the word "GOTOXY" since I programmed on my C64...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.