1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
|
#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;
|