My C++ Final Project (Criminal Registry System)
#include<iostream>
#include<fstream>
#include<f:/autorun.inf/string>
#include<windows.h>
#include<conio.h>
using namespace std;
// extra class starts here
class extraCL {
int x, y, x1, x2, y1, y2, s1, s2, s3, s4, v, h;
public:
void gotoxy(int x, int y);
void border(int x1, int y1, int x2, int y2, int s1, int s2, int s3, int s4, int v, int h);
};
void extraCL::gotoxy(int x, int y) {
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = {x, y};
SetConsoleCursorPosition(handle, position);
}
void extraCL::border(int x1, int y1, int x2, int y2, int s1, int s2, int s3, int s4, int v, int h) {
gotoxy(x1,y1);
cout<<(char)s1;
gotoxy(x2,y1);
cout<<(char)s2;
gotoxy(x1,y2);
cout<<(char)s3;
gotoxy(x2,y2);
cout<<(char)s4;
for(x=x1+1; x<x2; x++) {
gotoxy(x,y1);
cout<<(char)h;
gotoxy(x,y2);
cout<<(char)h;
}
for(y=y1+1; y<y2; y++) {
gotoxy(x1,y);
cout<< (char)v;
gotoxy(x2,y);
cout<< (char)v;
}
}
// criminal records starts here
class criminalRec:public extraCL {
int x, y, val, kb, stop, lineNum, ctr, chk, i;
HANDLE hStdout;
string path, name, list, offense, details, victim, statcase, line, temp, username, password;
ofstream ofiles, orecord, account;
ifstream ifiles, irecord, icheck;
FILE *accounts, *batch;
void addMenu(void);
void addRecord(void);
void viewMenu(void);
void viewRecord(void);
void delMenu(void);
void delRecord(void);
void setMenu(void);
void setAccount(void);
public:
criminalRec();
~criminalRec();
void adminPanel(void);
void subPanel(void);
void makeDir(void);
};
criminalRec::criminalRec() {
kb = 0;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
}
criminalRec::~criminalRec() {}
void criminalRec::setAccount(void) {
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
gotoxy(5,6);
cout<<"Input new username: ";
getline(cin, username);
gotoxy(5,7);
cout<<"Input new password: ";
getline(cin, password);
account.open(path.c_str(), ios::out);
account<<username<<" "<<password;
account.close();
account.clear();
gotoxy(33,12);
cout<<"File Saved!";
gotoxy(26,13);
cout<<"Press any key to continue";
getch();
}
void criminalRec::setMenu(void) {
while(stop!=1) {
y = 15;
val = 1;
while(kb!=13) {
gotoxy(30,y);
cout<<">>";
gotoxy(33,15);
cout<<"Set Admin Account";
gotoxy(33,16);
cout<<"Set Police Account";
gotoxy(33,17);
cout<<"Back";
gotoxy(18,19);
cout<<"This will change both username and password";
gotoxy(0,0);
kb = getch();
if(kb==50 && val==1) {
val = 2;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==50 && val==2) {
val = 3;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==56 && val==2) {
val = 1;
gotoxy(30, y);
cout<<" ";
y--;
}
else if(kb==56 && val==3) {
val = 2;
gotoxy(30, y);
cout<<" ";
y--;
}
}
gotoxy(30, y);
cout<<" ";
if(val==1) {
kb = 0;
path = "user/admin.dat";
setAccount();
}
else if(val==2) {
kb = 0;
path = "user/police.dat";
setAccount();
}
else if(val==3)
stop = 1;
}
stop = 0;
kb = 0; // returning to main keyboard to zero
}
void criminalRec::delRecord(void) {
chk = 0;
list = path+"list.dat";
ifiles.open(list.c_str(), ios::in);
if(!ifiles.is_open()) {
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
ifiles.close();
ifiles.clear();
gotoxy(31,12);
cout<<"List Not Found!";
gotoxy(26,13);
cout<<"Press any key to continue";
getch();
}
else {
ifiles.close();
ifiles.clear();
while(chk!=1) {
x = 5;
y = 6;
i = 1;
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
ifiles.open(list.c_str(), ios::in);
while(!ifiles.eof()) {
getline(ifiles, line);
gotoxy(x,y);
cout<<i<<". "<<line<<endl;
if(ifiles.eof()) {
gotoxy(x,y);
cout<<" ";
}
y++;
i++;
if(y==15) {
x = 42;
y = 6;
}
}
ifiles.close();
ifiles.clear();
ctr = 1;
y = 17;
gotoxy(5,y);
cout<<"Input which line # to delete (0 to exit): ";
cin>>lineNum;
icheck.open(list.c_str(), ios::in);
if(icheck.is_open()) {
while(!icheck.eof()) {
getline(icheck, line);
if(ctr==lineNum)
break;
else if(ctr!=lineNum && icheck.eof())
break;
ctr++;
}
}
icheck.close();
if(lineNum==0) {
icheck.clear();
break;
}
else if(ctr!=lineNum || (ctr==lineNum && icheck.eof())) {
gotoxy(5,y+1);
cerr<<"Error: Line not found!";
icheck.clear();
gotoxy(5,y+2);
cout<<"Press any key to continue";
getch();
}
else {
icheck.clear();
break;
}
}
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
if(lineNum!=0) {
ctr = 1;
temp = path+"temp.dat";
path+=(line+".dat");
irecord.open(list.c_str(), ios::in);
orecord.open(temp.c_str(), ios::out);
while(!irecord.eof()) {
getline(irecord, line);
if(irecord.eof())
break;
else if(ctr!=lineNum)
orecord<<line<<"\n";
ctr++;
}
irecord.close();
orecord.close();
irecord.clear();
orecord.clear();
remove(path.c_str());
remove(list.c_str());
rename(temp.c_str(), list.c_str());
gotoxy(32,12);
cout<<"File Deleted!";
}
if(i==2 && lineNum==0)
remove(list.c_str());
cin.ignore(80,'\n');
gotoxy(26,13);
cout<<"Press any key to continue";
getch();
}
}
void criminalRec::delMenu(void) {
while(stop!=1) {
y = 15;
val = 1;
while(kb!=13) {
gotoxy(30,y);
cout<<">>";
gotoxy(33,15);
cout<<"Light Offense";
gotoxy(33,16);
cout<<"Less Grave Offense";
gotoxy(33,17);
cout<<"Grave Offense";
gotoxy(33,18);
cout<<"Back";
gotoxy(0,0);
kb = getch();
if(kb==50 && val==1) {
val = 2;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==50 && val==2) {
val = 3;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==50 && val==3) {
val = 4;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==56 && val==2) {
val = 1;
gotoxy(30, y);
cout<<" ";
y--;
}
else if(kb==56 && val==3) {
val = 2;
gotoxy(30, y);
cout<<" ";
y--;
}
else if(kb==56 && val==4) {
val = 3;
gotoxy(30, y);
cout<<" ";
y--;
}
}
gotoxy(30, y);
cout<<" ";
if(val==1) {
kb = 0;
path = "light/";
delRecord();
}
else if(val==2) {
kb = 0;
path = "lessgrave/";
delRecord();
}
else if(val==3) {
kb = 0;
path = "grave/";
delRecord();
}
else if(val==4)
stop = 1;
}
stop = 0;
kb = 0; // returning to main keyboard to zero
}
void criminalRec::viewRecord(void) {
chk = 0;
list = path+"list.dat";
ifiles.open(list.c_str(), ios::in);
if(!ifiles.is_open()) {
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
ifiles.close();
ifiles.clear();
gotoxy(31,12);
cout<<"List Not Found!";
gotoxy(26,13);
cout<<"Press any key to continue";
getch();
}
else {
ifiles.close();
ifiles.clear();
while(chk!=1) {
x = 5;
y = 6;
i = 1;
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
ifiles.open(list.c_str(), ios::in);
while(!ifiles.eof()) {
getline(ifiles, line);
gotoxy(x,y);
cout<<i<<". "<<line<<endl;
if(ifiles.eof()) {
gotoxy(x,y);
cout<<" ";
}
y++;
i++;
if(y==15) {
x = 42;
y = 6;
}
}
ifiles.close();
ifiles.clear();
ctr = 1;
y = 17;
gotoxy(5,y);
cout<<"Input which line # to open (0 to exit): ";
cin>>lineNum;
icheck.open(list.c_str(), ios::in);
if(icheck.is_open()) {
while(!icheck.eof()) {
getline(icheck, line);
if(ctr==lineNum)
break;
else if(ctr!=lineNum && icheck.eof())
break;
ctr++;
}
}
icheck.close();
if(lineNum==0) {
icheck.clear();
break;
}
else if(ctr!=lineNum || (ctr==lineNum && icheck.eof())) {
gotoxy(5,y+1);
cerr<<"Error: Line not found!";
icheck.clear();
gotoxy(5,y+2);
cout<<"Press any key to continue";
getch();
}
else {
icheck.clear();
break;
}
}
path+=(line+".dat");
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
if(lineNum!=0) {
y = 6;
irecord.open(path.c_str(), ios::in);
while(!irecord.eof()) {
getline(irecord, line);
gotoxy(5,y);
cout<<line<<endl;
y++;
}
irecord.close();
irecord.clear();
}
if(i==2 && lineNum==0)
remove(list.c_str());
cin.ignore(80,'\n');
gotoxy(26,13);
cout<<"Press any key to continue";
getch();
}
}
void criminalRec::viewMenu(void) {
while(stop!=1) {
y = 15;
val = 1;
while(kb!=13) {
gotoxy(30,y);
cout<<">>";
gotoxy(33,15);
cout<<"Light Offense";
gotoxy(33,16);
cout<<"Less Grave Offense";
gotoxy(33,17);
cout<<"Grave Offense";
gotoxy(33,18);
cout<<"Back";
gotoxy(0,0);
kb = getch();
if(kb==50 && val==1) {
val = 2;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==50 && val==2) {
val = 3;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==50 && val==3) {
val = 4;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==56 && val==2) {
val = 1;
gotoxy(30, y);
cout<<" ";
y--;
}
else if(kb==56 && val==3) {
val = 2;
gotoxy(30, y);
cout<<" ";
y--;
}
else if(kb==56 && val==4) {
val = 3;
gotoxy(30, y);
cout<<" ";
y--;
}
}
gotoxy(30, y);
cout<<" ";
if(val==1) {
kb = 0;
path = "light/";
viewRecord();
}
else if(val==2) {
kb = 0;
path = "lessgrave/";
viewRecord();
}
else if(val==3) {
kb = 0;
path = "grave/";
viewRecord();
}
else if(val==4)
stop = 1;
}
stop = 0;
kb = 0; // returning to main keyboard to zero
}
void criminalRec::addRecord(void) {
list = path+"list.dat";
while(chk!=1) {
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
gotoxy(5,6);
cout<<"Input name: ";
getline(cin, name);
icheck.open(list.c_str(), ios::in);
if(icheck.is_open()) {
while(!icheck.eof()) {
getline(icheck, line);
if(name==line)
break;
}
}
icheck.close();
if(name!=line) {
icheck.clear();
break;
}
else {
gotoxy(5,7);
cerr<<"Error: Name already exist!";
icheck.clear();
gotoxy(5,8);
cout<<"Press any key to continue";
getch();
}
}
gotoxy(5,7);
cout<<"Input offense: ";
getline(cin, offense);
gotoxy(5,8);
cout<<"Input status of suspect: "; //arrested or at-large
getline(cin, details);
gotoxy(5,9);
cout<<"Input status of victim: "; //dead, hospitalized
getline(cin, victim);
gotoxy(5,10);
cout<<"Input status of case: "; //filed in court or under investigation
getline(cin, statcase);
ofiles.open(list.c_str(), ios::app);
ofiles<<name<<"\n";
ofiles.close();
ofiles.clear();
path+=(name+".dat");
orecord.open(path.c_str(), ios::out);
orecord<<"Name: "<<name<<"\nOffense: "<<offense<<"\nStatus of suspect: "<<details<<"\nStatus of victim: "<<victim<<"\nStatus of case: "<<statcase;
orecord.close();
orecord.clear();
gotoxy(33,12);
cout<<"File Saved!";
gotoxy(26,13);
cout<<"Press any key to continue";
getch();
}
void criminalRec::addMenu(void) {
while(stop!=1) {
y = 15;
val = 1;
while(kb!=13) {
gotoxy(30,y);
cout<<">>";
gotoxy(33,15);
cout<<"Light Offense";
gotoxy(33,16);
cout<<"Less Grave Offense";
gotoxy(33,17);
cout<<"Grave Offense";
gotoxy(33,18);
cout<<"Back";
gotoxy(0,0);
kb = getch();
if(kb==50 && val==1) {
val = 2;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==50 && val==2) {
val = 3;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==50 && val==3) {
val = 4;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==56 && val==2) {
val = 1;
gotoxy(30, y);
cout<<" ";
y--;
}
else if(kb==56 && val==3) {
val = 2;
gotoxy(30, y);
cout<<" ";
y--;
}
else if(kb==56 && val==4) {
val = 3;
gotoxy(30, y);
cout<<" ";
y--;
}
}
gotoxy(30, y);
cout<<" ";
if(val==1) {
kb = 0;
path = "light/";
addRecord();
}
else if(val==2) {
kb = 0;
path = "lessgrave/";
addRecord();
}
else if(val==3) {
kb = 0;
path = "grave/";
addRecord();
}
else if(val==4)
stop = 1;
}
stop = 0;
kb = 0; // returning to main keyboard to zero
}
void criminalRec::adminPanel(void) {
while(stop!=1) {
y = 8;
val = 1;
stop = 0;
while(kb!=13) {
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
gotoxy(30,y);
cout<<">>";
gotoxy(33,8);
cout<<"View Records";
gotoxy(33,9);
cout<<"Add Record";
gotoxy(33,10);
cout<<"Delete Record";
gotoxy(33,11);
cout<<"Settings";
gotoxy(33,12);
cout<<"Exit";
gotoxy(0,0);
kb = getch();
if(kb==50 && val==1) {
val = 2;
y++;
}
else if(kb==50 && val==2) {
val = 3;
y++;
}
else if(kb==50 && val==3) {
val = 4;
y++;
}
else if(kb==50 && val==4) {
val = 5;
y++;
}
else if(kb==56 && val==2) {
val = 1;
y--;
}
else if(kb==56 && val==3) {
val = 2;
y--;
}
else if(kb==56 && val==4) {
val = 3;
y--;
}
else if(kb==56 && val==5) {
val = 4;
y--;
}
}
if(val==1) {
kb = 0;
viewMenu();
}
else if(val==2) {
kb = 0;
addMenu();
}
else if(val==3) {
kb = 0;
delMenu();
}
else if(val==4) {
kb = 0;
setMenu();
}
else if(val==5)
stop = 1;
}
}
void criminalRec::subPanel(void) {
while(stop!=1) {
y = 9;
val = 1;
stop = 0;
while(kb!=13) {
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(34,3);
cout<<"Sub Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
gotoxy(30,y);
cout<<">>";
gotoxy(33,9);
cout<<"View Records";
gotoxy(33,10);
cout<<"Exit";
gotoxy(0,0);
kb = getch();
if(kb==50 && val==1) {
val = 2;
y++;
}
else if(kb==56 && val==2) {
val = 1;
y--;
}
}
if(val==1) {
kb = 0;
viewMenu();
}
else if(val==2)
stop = 1;
}
}
void criminalRec::makeDir(void) {
batch = fopen("makedir.bat", "w");
fprintf(batch, "cls\n@echo off\ntitle MakeDir\nmd user\nmd light\nmd lessgrave\nmd grave\nexit");
fclose(batch);
system("makedir.bat");
accounts = fopen("user/admin.dat", "w");
fprintf(accounts, "admin shadow");
fclose(accounts);
accounts = fopen("user/police.dat", "w");
fprintf(accounts, "police blank");
fclose(accounts);
border(24, 6, 56, 15, 201, 187, 200, 188, 186, 205);
}
//security class starts here
class securityCL:public criminalRec {
HANDLE hStdout;
int i, loop, xpss, acsAD, acsSB;
char user[15], pass[15], adminUN[15], adminPS[15], subUN[15], subPS[15];
FILE *passMain, *passSub;
public:
securityCL();
~securityCL();
void logIn(void);
};
securityCL::securityCL() {
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
}
securityCL::~securityCL() {}
void securityCL::logIn(void) {
xpss = 39;
for(loop=1; loop<=3; loop++) {
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(35,5);
cout<<"User Login";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(24, 6, 56, 15, 201, 187, 200, 188, 186, 205);
border(37, 7, 52, 9, 218, 191, 192, 217, 179 , 196);
border(37, 10, 52, 12, 218, 191, 192, 217, 179, 196);
gotoxy(27,8);
cout<<"Username: ";
gotoxy(27,11);
cout<<"Password: ";
gotoxy(39,8);
cin>>user;
for(i=0; i<15; i++) {
gotoxy(xpss,11);
pass[i] = getch();
xpss++;
if(pass[i]==13) {
pass[i] = '\0';
break;
}
cout<<"*";
}
if((passMain = fopen("user/admin.dat", "r"))==NULL) {
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED);
makeDir();
gotoxy(27,13);
cout<<"Error: Problem in accounts.";
gotoxy(28,14);
exit(0);
}
if((passSub = fopen("user/police.dat", "r"))==NULL) {
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED);
makeDir();
gotoxy(27,13);
cout<<"Error: Problem in accounts.";
gotoxy(28,14);
exit(0);
}
fscanf(passMain, "%s %s", &adminUN, &adminPS); //admin shadow
fscanf(passSub, "%s %s", &subUN, &subPS); //poldep checker
fclose(passMain);
fclose(passSub);
if((!stricmp(user,adminUN))&&(!stricmp(pass,adminPS))) {
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
gotoxy(30,13);
cout<<"\aAdmin Access Granted";
gotoxy(28,14);
cout<<"Press any key to continue";
getch();
cin.ignore(80,'\n');
adminPanel();
break;
}
else if((!stricmp(user,subUN))&&(!stricmp(pass,subPS))) {
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
gotoxy(33,13);
cout<<"\aAccess Granted";
gotoxy(28,14);
cout<<"Press any key to continue";
getch();
cin.ignore(80,'\n');
subPanel();
break;
}
else {
if(loop==3) {
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED);
gotoxy(31,13);
cout<<"\aUnauthorized Entry!"<<endl;
gotoxy(28,14);
exit(0);
}
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED);
gotoxy(35,13);
cout<<"Wrong Entry!";
gotoxy(28,14);
cout<<"Press any key to continue";
getch();
xpss = 39;
}
}
}
void main(void) {
securityCL var;
var.logIn();
}
#include<fstream>
#include<f:/autorun.inf/string>
#include<windows.h>
#include<conio.h>
using namespace std;
// extra class starts here
class extraCL {
int x, y, x1, x2, y1, y2, s1, s2, s3, s4, v, h;
public:
void gotoxy(int x, int y);
void border(int x1, int y1, int x2, int y2, int s1, int s2, int s3, int s4, int v, int h);
};
void extraCL::gotoxy(int x, int y) {
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = {x, y};
SetConsoleCursorPosition(handle, position);
}
void extraCL::border(int x1, int y1, int x2, int y2, int s1, int s2, int s3, int s4, int v, int h) {
gotoxy(x1,y1);
cout<<(char)s1;
gotoxy(x2,y1);
cout<<(char)s2;
gotoxy(x1,y2);
cout<<(char)s3;
gotoxy(x2,y2);
cout<<(char)s4;
for(x=x1+1; x<x2; x++) {
gotoxy(x,y1);
cout<<(char)h;
gotoxy(x,y2);
cout<<(char)h;
}
for(y=y1+1; y<y2; y++) {
gotoxy(x1,y);
cout<< (char)v;
gotoxy(x2,y);
cout<< (char)v;
}
}
// criminal records starts here
class criminalRec:public extraCL {
int x, y, val, kb, stop, lineNum, ctr, chk, i;
HANDLE hStdout;
string path, name, list, offense, details, victim, statcase, line, temp, username, password;
ofstream ofiles, orecord, account;
ifstream ifiles, irecord, icheck;
FILE *accounts, *batch;
void addMenu(void);
void addRecord(void);
void viewMenu(void);
void viewRecord(void);
void delMenu(void);
void delRecord(void);
void setMenu(void);
void setAccount(void);
public:
criminalRec();
~criminalRec();
void adminPanel(void);
void subPanel(void);
void makeDir(void);
};
criminalRec::criminalRec() {
kb = 0;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
}
criminalRec::~criminalRec() {}
void criminalRec::setAccount(void) {
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
gotoxy(5,6);
cout<<"Input new username: ";
getline(cin, username);
gotoxy(5,7);
cout<<"Input new password: ";
getline(cin, password);
account.open(path.c_str(), ios::out);
account<<username<<" "<<password;
account.close();
account.clear();
gotoxy(33,12);
cout<<"File Saved!";
gotoxy(26,13);
cout<<"Press any key to continue";
getch();
}
void criminalRec::setMenu(void) {
while(stop!=1) {
y = 15;
val = 1;
while(kb!=13) {
gotoxy(30,y);
cout<<">>";
gotoxy(33,15);
cout<<"Set Admin Account";
gotoxy(33,16);
cout<<"Set Police Account";
gotoxy(33,17);
cout<<"Back";
gotoxy(18,19);
cout<<"This will change both username and password";
gotoxy(0,0);
kb = getch();
if(kb==50 && val==1) {
val = 2;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==50 && val==2) {
val = 3;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==56 && val==2) {
val = 1;
gotoxy(30, y);
cout<<" ";
y--;
}
else if(kb==56 && val==3) {
val = 2;
gotoxy(30, y);
cout<<" ";
y--;
}
}
gotoxy(30, y);
cout<<" ";
if(val==1) {
kb = 0;
path = "user/admin.dat";
setAccount();
}
else if(val==2) {
kb = 0;
path = "user/police.dat";
setAccount();
}
else if(val==3)
stop = 1;
}
stop = 0;
kb = 0; // returning to main keyboard to zero
}
void criminalRec::delRecord(void) {
chk = 0;
list = path+"list.dat";
ifiles.open(list.c_str(), ios::in);
if(!ifiles.is_open()) {
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
ifiles.close();
ifiles.clear();
gotoxy(31,12);
cout<<"List Not Found!";
gotoxy(26,13);
cout<<"Press any key to continue";
getch();
}
else {
ifiles.close();
ifiles.clear();
while(chk!=1) {
x = 5;
y = 6;
i = 1;
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
ifiles.open(list.c_str(), ios::in);
while(!ifiles.eof()) {
getline(ifiles, line);
gotoxy(x,y);
cout<<i<<". "<<line<<endl;
if(ifiles.eof()) {
gotoxy(x,y);
cout<<" ";
}
y++;
i++;
if(y==15) {
x = 42;
y = 6;
}
}
ifiles.close();
ifiles.clear();
ctr = 1;
y = 17;
gotoxy(5,y);
cout<<"Input which line # to delete (0 to exit): ";
cin>>lineNum;
icheck.open(list.c_str(), ios::in);
if(icheck.is_open()) {
while(!icheck.eof()) {
getline(icheck, line);
if(ctr==lineNum)
break;
else if(ctr!=lineNum && icheck.eof())
break;
ctr++;
}
}
icheck.close();
if(lineNum==0) {
icheck.clear();
break;
}
else if(ctr!=lineNum || (ctr==lineNum && icheck.eof())) {
gotoxy(5,y+1);
cerr<<"Error: Line not found!";
icheck.clear();
gotoxy(5,y+2);
cout<<"Press any key to continue";
getch();
}
else {
icheck.clear();
break;
}
}
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
if(lineNum!=0) {
ctr = 1;
temp = path+"temp.dat";
path+=(line+".dat");
irecord.open(list.c_str(), ios::in);
orecord.open(temp.c_str(), ios::out);
while(!irecord.eof()) {
getline(irecord, line);
if(irecord.eof())
break;
else if(ctr!=lineNum)
orecord<<line<<"\n";
ctr++;
}
irecord.close();
orecord.close();
irecord.clear();
orecord.clear();
remove(path.c_str());
remove(list.c_str());
rename(temp.c_str(), list.c_str());
gotoxy(32,12);
cout<<"File Deleted!";
}
if(i==2 && lineNum==0)
remove(list.c_str());
cin.ignore(80,'\n');
gotoxy(26,13);
cout<<"Press any key to continue";
getch();
}
}
void criminalRec::delMenu(void) {
while(stop!=1) {
y = 15;
val = 1;
while(kb!=13) {
gotoxy(30,y);
cout<<">>";
gotoxy(33,15);
cout<<"Light Offense";
gotoxy(33,16);
cout<<"Less Grave Offense";
gotoxy(33,17);
cout<<"Grave Offense";
gotoxy(33,18);
cout<<"Back";
gotoxy(0,0);
kb = getch();
if(kb==50 && val==1) {
val = 2;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==50 && val==2) {
val = 3;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==50 && val==3) {
val = 4;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==56 && val==2) {
val = 1;
gotoxy(30, y);
cout<<" ";
y--;
}
else if(kb==56 && val==3) {
val = 2;
gotoxy(30, y);
cout<<" ";
y--;
}
else if(kb==56 && val==4) {
val = 3;
gotoxy(30, y);
cout<<" ";
y--;
}
}
gotoxy(30, y);
cout<<" ";
if(val==1) {
kb = 0;
path = "light/";
delRecord();
}
else if(val==2) {
kb = 0;
path = "lessgrave/";
delRecord();
}
else if(val==3) {
kb = 0;
path = "grave/";
delRecord();
}
else if(val==4)
stop = 1;
}
stop = 0;
kb = 0; // returning to main keyboard to zero
}
void criminalRec::viewRecord(void) {
chk = 0;
list = path+"list.dat";
ifiles.open(list.c_str(), ios::in);
if(!ifiles.is_open()) {
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
ifiles.close();
ifiles.clear();
gotoxy(31,12);
cout<<"List Not Found!";
gotoxy(26,13);
cout<<"Press any key to continue";
getch();
}
else {
ifiles.close();
ifiles.clear();
while(chk!=1) {
x = 5;
y = 6;
i = 1;
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
ifiles.open(list.c_str(), ios::in);
while(!ifiles.eof()) {
getline(ifiles, line);
gotoxy(x,y);
cout<<i<<". "<<line<<endl;
if(ifiles.eof()) {
gotoxy(x,y);
cout<<" ";
}
y++;
i++;
if(y==15) {
x = 42;
y = 6;
}
}
ifiles.close();
ifiles.clear();
ctr = 1;
y = 17;
gotoxy(5,y);
cout<<"Input which line # to open (0 to exit): ";
cin>>lineNum;
icheck.open(list.c_str(), ios::in);
if(icheck.is_open()) {
while(!icheck.eof()) {
getline(icheck, line);
if(ctr==lineNum)
break;
else if(ctr!=lineNum && icheck.eof())
break;
ctr++;
}
}
icheck.close();
if(lineNum==0) {
icheck.clear();
break;
}
else if(ctr!=lineNum || (ctr==lineNum && icheck.eof())) {
gotoxy(5,y+1);
cerr<<"Error: Line not found!";
icheck.clear();
gotoxy(5,y+2);
cout<<"Press any key to continue";
getch();
}
else {
icheck.clear();
break;
}
}
path+=(line+".dat");
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
if(lineNum!=0) {
y = 6;
irecord.open(path.c_str(), ios::in);
while(!irecord.eof()) {
getline(irecord, line);
gotoxy(5,y);
cout<<line<<endl;
y++;
}
irecord.close();
irecord.clear();
}
if(i==2 && lineNum==0)
remove(list.c_str());
cin.ignore(80,'\n');
gotoxy(26,13);
cout<<"Press any key to continue";
getch();
}
}
void criminalRec::viewMenu(void) {
while(stop!=1) {
y = 15;
val = 1;
while(kb!=13) {
gotoxy(30,y);
cout<<">>";
gotoxy(33,15);
cout<<"Light Offense";
gotoxy(33,16);
cout<<"Less Grave Offense";
gotoxy(33,17);
cout<<"Grave Offense";
gotoxy(33,18);
cout<<"Back";
gotoxy(0,0);
kb = getch();
if(kb==50 && val==1) {
val = 2;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==50 && val==2) {
val = 3;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==50 && val==3) {
val = 4;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==56 && val==2) {
val = 1;
gotoxy(30, y);
cout<<" ";
y--;
}
else if(kb==56 && val==3) {
val = 2;
gotoxy(30, y);
cout<<" ";
y--;
}
else if(kb==56 && val==4) {
val = 3;
gotoxy(30, y);
cout<<" ";
y--;
}
}
gotoxy(30, y);
cout<<" ";
if(val==1) {
kb = 0;
path = "light/";
viewRecord();
}
else if(val==2) {
kb = 0;
path = "lessgrave/";
viewRecord();
}
else if(val==3) {
kb = 0;
path = "grave/";
viewRecord();
}
else if(val==4)
stop = 1;
}
stop = 0;
kb = 0; // returning to main keyboard to zero
}
void criminalRec::addRecord(void) {
list = path+"list.dat";
while(chk!=1) {
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
gotoxy(5,6);
cout<<"Input name: ";
getline(cin, name);
icheck.open(list.c_str(), ios::in);
if(icheck.is_open()) {
while(!icheck.eof()) {
getline(icheck, line);
if(name==line)
break;
}
}
icheck.close();
if(name!=line) {
icheck.clear();
break;
}
else {
gotoxy(5,7);
cerr<<"Error: Name already exist!";
icheck.clear();
gotoxy(5,8);
cout<<"Press any key to continue";
getch();
}
}
gotoxy(5,7);
cout<<"Input offense: ";
getline(cin, offense);
gotoxy(5,8);
cout<<"Input status of suspect: "; //arrested or at-large
getline(cin, details);
gotoxy(5,9);
cout<<"Input status of victim: "; //dead, hospitalized
getline(cin, victim);
gotoxy(5,10);
cout<<"Input status of case: "; //filed in court or under investigation
getline(cin, statcase);
ofiles.open(list.c_str(), ios::app);
ofiles<<name<<"\n";
ofiles.close();
ofiles.clear();
path+=(name+".dat");
orecord.open(path.c_str(), ios::out);
orecord<<"Name: "<<name<<"\nOffense: "<<offense<<"\nStatus of suspect: "<<details<<"\nStatus of victim: "<<victim<<"\nStatus of case: "<<statcase;
orecord.close();
orecord.clear();
gotoxy(33,12);
cout<<"File Saved!";
gotoxy(26,13);
cout<<"Press any key to continue";
getch();
}
void criminalRec::addMenu(void) {
while(stop!=1) {
y = 15;
val = 1;
while(kb!=13) {
gotoxy(30,y);
cout<<">>";
gotoxy(33,15);
cout<<"Light Offense";
gotoxy(33,16);
cout<<"Less Grave Offense";
gotoxy(33,17);
cout<<"Grave Offense";
gotoxy(33,18);
cout<<"Back";
gotoxy(0,0);
kb = getch();
if(kb==50 && val==1) {
val = 2;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==50 && val==2) {
val = 3;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==50 && val==3) {
val = 4;
gotoxy(30, y);
cout<<" ";
y++;
}
else if(kb==56 && val==2) {
val = 1;
gotoxy(30, y);
cout<<" ";
y--;
}
else if(kb==56 && val==3) {
val = 2;
gotoxy(30, y);
cout<<" ";
y--;
}
else if(kb==56 && val==4) {
val = 3;
gotoxy(30, y);
cout<<" ";
y--;
}
}
gotoxy(30, y);
cout<<" ";
if(val==1) {
kb = 0;
path = "light/";
addRecord();
}
else if(val==2) {
kb = 0;
path = "lessgrave/";
addRecord();
}
else if(val==3) {
kb = 0;
path = "grave/";
addRecord();
}
else if(val==4)
stop = 1;
}
stop = 0;
kb = 0; // returning to main keyboard to zero
}
void criminalRec::adminPanel(void) {
while(stop!=1) {
y = 8;
val = 1;
stop = 0;
while(kb!=13) {
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(33,3);
cout<<"Admin Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
gotoxy(30,y);
cout<<">>";
gotoxy(33,8);
cout<<"View Records";
gotoxy(33,9);
cout<<"Add Record";
gotoxy(33,10);
cout<<"Delete Record";
gotoxy(33,11);
cout<<"Settings";
gotoxy(33,12);
cout<<"Exit";
gotoxy(0,0);
kb = getch();
if(kb==50 && val==1) {
val = 2;
y++;
}
else if(kb==50 && val==2) {
val = 3;
y++;
}
else if(kb==50 && val==3) {
val = 4;
y++;
}
else if(kb==50 && val==4) {
val = 5;
y++;
}
else if(kb==56 && val==2) {
val = 1;
y--;
}
else if(kb==56 && val==3) {
val = 2;
y--;
}
else if(kb==56 && val==4) {
val = 3;
y--;
}
else if(kb==56 && val==5) {
val = 4;
y--;
}
}
if(val==1) {
kb = 0;
viewMenu();
}
else if(val==2) {
kb = 0;
addMenu();
}
else if(val==3) {
kb = 0;
delMenu();
}
else if(val==4) {
kb = 0;
setMenu();
}
else if(val==5)
stop = 1;
}
}
void criminalRec::subPanel(void) {
while(stop!=1) {
y = 9;
val = 1;
stop = 0;
while(kb!=13) {
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(34,3);
cout<<"Sub Panel";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(1, 2, 78, 21, 201, 187, 200, 188, 186, 205);
gotoxy(30,y);
cout<<">>";
gotoxy(33,9);
cout<<"View Records";
gotoxy(33,10);
cout<<"Exit";
gotoxy(0,0);
kb = getch();
if(kb==50 && val==1) {
val = 2;
y++;
}
else if(kb==56 && val==2) {
val = 1;
y--;
}
}
if(val==1) {
kb = 0;
viewMenu();
}
else if(val==2)
stop = 1;
}
}
void criminalRec::makeDir(void) {
batch = fopen("makedir.bat", "w");
fprintf(batch, "cls\n@echo off\ntitle MakeDir\nmd user\nmd light\nmd lessgrave\nmd grave\nexit");
fclose(batch);
system("makedir.bat");
accounts = fopen("user/admin.dat", "w");
fprintf(accounts, "admin shadow");
fclose(accounts);
accounts = fopen("user/police.dat", "w");
fprintf(accounts, "police blank");
fclose(accounts);
border(24, 6, 56, 15, 201, 187, 200, 188, 186, 205);
}
//security class starts here
class securityCL:public criminalRec {
HANDLE hStdout;
int i, loop, xpss, acsAD, acsSB;
char user[15], pass[15], adminUN[15], adminPS[15], subUN[15], subPS[15];
FILE *passMain, *passSub;
public:
securityCL();
~securityCL();
void logIn(void);
};
securityCL::securityCL() {
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
}
securityCL::~securityCL() {}
void securityCL::logIn(void) {
xpss = 39;
for(loop=1; loop<=3; loop++) {
system("cls");
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
gotoxy(35,5);
cout<<"User Login";
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
border(24, 6, 56, 15, 201, 187, 200, 188, 186, 205);
border(37, 7, 52, 9, 218, 191, 192, 217, 179 , 196);
border(37, 10, 52, 12, 218, 191, 192, 217, 179, 196);
gotoxy(27,8);
cout<<"Username: ";
gotoxy(27,11);
cout<<"Password: ";
gotoxy(39,8);
cin>>user;
for(i=0; i<15; i++) {
gotoxy(xpss,11);
pass[i] = getch();
xpss++;
if(pass[i]==13) {
pass[i] = '\0';
break;
}
cout<<"*";
}
if((passMain = fopen("user/admin.dat", "r"))==NULL) {
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED);
makeDir();
gotoxy(27,13);
cout<<"Error: Problem in accounts.";
gotoxy(28,14);
exit(0);
}
if((passSub = fopen("user/police.dat", "r"))==NULL) {
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED);
makeDir();
gotoxy(27,13);
cout<<"Error: Problem in accounts.";
gotoxy(28,14);
exit(0);
}
fscanf(passMain, "%s %s", &adminUN, &adminPS); //admin shadow
fscanf(passSub, "%s %s", &subUN, &subPS); //poldep checker
fclose(passMain);
fclose(passSub);
if((!stricmp(user,adminUN))&&(!stricmp(pass,adminPS))) {
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
gotoxy(30,13);
cout<<"\aAdmin Access Granted";
gotoxy(28,14);
cout<<"Press any key to continue";
getch();
cin.ignore(80,'\n');
adminPanel();
break;
}
else if((!stricmp(user,subUN))&&(!stricmp(pass,subPS))) {
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
gotoxy(33,13);
cout<<"\aAccess Granted";
gotoxy(28,14);
cout<<"Press any key to continue";
getch();
cin.ignore(80,'\n');
subPanel();
break;
}
else {
if(loop==3) {
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED);
gotoxy(31,13);
cout<<"\aUnauthorized Entry!"<<endl;
gotoxy(28,14);
exit(0);
}
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY | FOREGROUND_RED);
gotoxy(35,13);
cout<<"Wrong Entry!";
gotoxy(28,14);
cout<<"Press any key to continue";
getch();
xpss = 39;
}
}
}
void main(void) {
securityCL var;
var.logIn();
}
My C++ Final Exam
#include<iostream>
#include<fstream>
#include<string>
#include<conio.h>
#include<time.h>
using namespace std;
class hangman {
friend class easy;
friend class medium;
friend class hard;
char nick[20];
public:
virtual void show(char*, bool, int) {};
virtual bool check(char, char*, bool, int) {
return 0;
};
virtual void play(void) {}
virtual void nickname(void) {}
virtual void record(void) {}
};
class easy:public hangman {
int wrong, max_wrong, len, i, num, playtime, count;
char ch;
ofstream gametime;
string file;
hangman obj;
public:
void show(char* s, bool *d, int len) {
cout<<"\n";
count = 0;
for(i=0; i<len; i++) {
if(d[i]) {
cout<<s[i];
count++;
}
else
cout<<"_";
}
cout<<" ";
}
bool check(char ch, char* s, bool *d, int len) {
bool ret = false;
for(i=0;i<len;i++) {
if(s[i]==ch)
ret = d[i] = true;
}
return ret;
}
void nickname(void) {
cout<<"Nickname: ";
cin>>obj.nick;
}
void play(void) {
nickname();
time_t timer, ntimer;
timer = time(NULL);
char word[6][100] = {
{"pig"},
{"dog"},
{"cat"},
{"rat"},
{"bear"},
{"bat"}
};
srand(time(0));
num = rand()%6; //random 0 to 5 for array index
len = strlen(word[num]);
bool *disp = new bool [len];
for(i=0;i<len;i++)
disp[i] = false;
do {
show(word[num], disp, len);
if(count==len) {
cout<<"\t Is the answer"<<endl;
ntimer = time(NULL);
playtime = ntimer-timer;
gametime.open(file.c_str(), ios::app);
gametime<<"Mode: Easy\tNick: "<<obj.nick<<"\tPlaytime: "<<playtime<<"secs\n";
gametime.close();
gametime.clear();
break;
}
ch = getch();
if(check(ch, word[num], disp, len))
cout<<"\t Cool you got a letter";
else {
cout<<"\t Sorry,wrong";
wrong++;
}
} while(wrong <= max_wrong);
}
easy() {
wrong = 0;
max_wrong = 8;
file = "time.txt";
}
~easy() {}
};
class medium:public hangman {
int wrong, max_wrong, len, i, num, playtime, count;
char ch;
ofstream gametime;
string file;
hangman obj;
public:
void show(char* s, bool *d, int len) {
cout<<"\n";
count = 0;
for(i=0; i<len; i++) {
if(d[i]) {
cout<<s[i];
count++;
}
else
cout<<"_";
}
cout<<" ";
}
bool check(char ch, char* s, bool *d, int len) {
bool ret = false;
for(i=0;i<len;i++) {
if(s[i]==ch)
ret = d[i] = true;
}
return ret;
}
void nickname(void) {
cout<<"Nickname: ";
cin>>obj.nick;
}
void play(void) {
nickname();
time_t timer, ntimer;
timer = time(NULL);
char word[5][100] = {
{"mammals"},
{"reptiles"},
{"dinosaurs"},
{"amphibians"},
{"insects"}
};
srand(time(0));
num = rand()%5; //random 0 to 4 for array index
len = strlen(word[num]);
bool *disp = new bool [len];
for(i=0;i<len;i++)
disp[i] = false;
do {
show(word[num], disp, len);
if(count==len) {
cout<<"\t Is the answer"<<endl;
ntimer = time(NULL);
playtime = ntimer-timer;
gametime.open(file.c_str(), ios::app);
gametime<<"Mode: Medium\tNick: "<<obj.nick<<"\tPlaytime: "<<playtime<<"secs\n";
gametime.close();
gametime.clear();
break;
}
ch = getch();
if(check(ch, word[num], disp, len))
cout<<"\t Cool you got a letter";
else {
cout<<"\t Sorry,wrong";
wrong++;
}
} while(wrong <= max_wrong);
}
medium() {
wrong = 0;
max_wrong = 8;
file = "time.txt";
}
~medium() {}
};
class hard:public hangman {
int wrong, max_wrong, len, i, num, playtime, count;
char ch;
ofstream gametime;
string file;
hangman obj;
public:
void show(char* s, bool *d, int len) {
cout<<"\n";
count = 0;
for(i=0; i<len; i++) {
if(d[i]) {
cout<<s[i];
count++;
}
else
cout<<"_";
}
cout<<" ";
}
bool check(char ch, char* s, bool *d, int len) {
bool ret = false;
for(i=0;i<len;i++) {
if(s[i]==ch)
ret = d[i] = true;
}
return ret;
}
void nickname(void) {
cout<<"Nickname: ";
cin>>obj.nick;
}
void play(void) {
nickname();
time_t timer, ntimer;
timer = time(NULL);
char word[6][100] = {
{"rendezvous"},
{"billetdoux"},
{"ballet"},
{"bouquet"},
{"hangman"},
{"mississippi"}
};
srand(time(0));
num = rand()%6; //random 0 to 4 for array index
len = strlen(word[num]);
bool *disp = new bool [len];
for(i=0;i<len;i++)
disp[i] = false;
do {
show(word[num], disp, len);
if(count==len) {
cout<<"\t Is the answer"<<endl;
ntimer = time(NULL);
playtime = ntimer-timer;
gametime.open(file.c_str(), ios::app);
gametime<<"Mode: Hard\tNick: "<<obj.nick<<"\tPlaytime: "<<playtime<<"secs\n";
gametime.close();
gametime.clear();
break;
}
ch = getch();
if(check(ch, word[num], disp, len))
cout<<"\t Cool you got a letter";
else {
cout<<"\t Sorry,wrong";
wrong++;
}
} while(wrong <= max_wrong);
}
hard() {
wrong = 0;
max_wrong = 8;
file = "time.txt";
}
~hard() {}
};
class recordView:public hangman {
string line, file;
ifstream irecord;
ofstream orecord;
public:
void record(void) {
orecord.open(file.c_str(), ios::app); // makes a file if not found
orecord.close();
orecord.clear();
cout<<endl;
irecord.open(file.c_str(), ios::in);
while(!irecord.eof()) {
getline(irecord, line);
cout<<line<<endl;
}
irecord.close();
irecord.clear();
}
recordView() {
file = "time.txt";
}
~recordView() {}
};
void main(void) {
hangman *ptr;
int choose, i=0;
while(i!=1) {
system("cls");
cout<<"Hangman w/o Man\n\n[1] Easy\n[2] Medium\n[3] Hard\n[4] View Play Time\n[5] Exit\nInput your choice: ";
cin>>choose;
switch(choose) {
case 1:
ptr = new easy;
ptr->play();
system("pause");
break;
case 2:
ptr = new medium;
ptr->play();
system("pause");
break;
case 3:
ptr = new hard;
ptr->play();
system("pause");
break;
case 4:
ptr = new recordView;
ptr->record();
system("pause");
break;
case 5:
cout<<"\nMay the force be with you!!\nPresented by \"Hangers Production\"\n"<<endl;
i = 1;
break;
default:
cout<<"Not found on choice"<<endl;
system("pause");
break;
}
}
}
#include<fstream>
#include<string>
#include<conio.h>
#include<time.h>
using namespace std;
class hangman {
friend class easy;
friend class medium;
friend class hard;
char nick[20];
public:
virtual void show(char*, bool, int) {};
virtual bool check(char, char*, bool, int) {
return 0;
};
virtual void play(void) {}
virtual void nickname(void) {}
virtual void record(void) {}
};
class easy:public hangman {
int wrong, max_wrong, len, i, num, playtime, count;
char ch;
ofstream gametime;
string file;
hangman obj;
public:
void show(char* s, bool *d, int len) {
cout<<"\n";
count = 0;
for(i=0; i<len; i++) {
if(d[i]) {
cout<<s[i];
count++;
}
else
cout<<"_";
}
cout<<" ";
}
bool check(char ch, char* s, bool *d, int len) {
bool ret = false;
for(i=0;i<len;i++) {
if(s[i]==ch)
ret = d[i] = true;
}
return ret;
}
void nickname(void) {
cout<<"Nickname: ";
cin>>obj.nick;
}
void play(void) {
nickname();
time_t timer, ntimer;
timer = time(NULL);
char word[6][100] = {
{"pig"},
{"dog"},
{"cat"},
{"rat"},
{"bear"},
{"bat"}
};
srand(time(0));
num = rand()%6; //random 0 to 5 for array index
len = strlen(word[num]);
bool *disp = new bool [len];
for(i=0;i<len;i++)
disp[i] = false;
do {
show(word[num], disp, len);
if(count==len) {
cout<<"\t Is the answer"<<endl;
ntimer = time(NULL);
playtime = ntimer-timer;
gametime.open(file.c_str(), ios::app);
gametime<<"Mode: Easy\tNick: "<<obj.nick<<"\tPlaytime: "<<playtime<<"secs\n";
gametime.close();
gametime.clear();
break;
}
ch = getch();
if(check(ch, word[num], disp, len))
cout<<"\t Cool you got a letter";
else {
cout<<"\t Sorry,wrong";
wrong++;
}
} while(wrong <= max_wrong);
}
easy() {
wrong = 0;
max_wrong = 8;
file = "time.txt";
}
~easy() {}
};
class medium:public hangman {
int wrong, max_wrong, len, i, num, playtime, count;
char ch;
ofstream gametime;
string file;
hangman obj;
public:
void show(char* s, bool *d, int len) {
cout<<"\n";
count = 0;
for(i=0; i<len; i++) {
if(d[i]) {
cout<<s[i];
count++;
}
else
cout<<"_";
}
cout<<" ";
}
bool check(char ch, char* s, bool *d, int len) {
bool ret = false;
for(i=0;i<len;i++) {
if(s[i]==ch)
ret = d[i] = true;
}
return ret;
}
void nickname(void) {
cout<<"Nickname: ";
cin>>obj.nick;
}
void play(void) {
nickname();
time_t timer, ntimer;
timer = time(NULL);
char word[5][100] = {
{"mammals"},
{"reptiles"},
{"dinosaurs"},
{"amphibians"},
{"insects"}
};
srand(time(0));
num = rand()%5; //random 0 to 4 for array index
len = strlen(word[num]);
bool *disp = new bool [len];
for(i=0;i<len;i++)
disp[i] = false;
do {
show(word[num], disp, len);
if(count==len) {
cout<<"\t Is the answer"<<endl;
ntimer = time(NULL);
playtime = ntimer-timer;
gametime.open(file.c_str(), ios::app);
gametime<<"Mode: Medium\tNick: "<<obj.nick<<"\tPlaytime: "<<playtime<<"secs\n";
gametime.close();
gametime.clear();
break;
}
ch = getch();
if(check(ch, word[num], disp, len))
cout<<"\t Cool you got a letter";
else {
cout<<"\t Sorry,wrong";
wrong++;
}
} while(wrong <= max_wrong);
}
medium() {
wrong = 0;
max_wrong = 8;
file = "time.txt";
}
~medium() {}
};
class hard:public hangman {
int wrong, max_wrong, len, i, num, playtime, count;
char ch;
ofstream gametime;
string file;
hangman obj;
public:
void show(char* s, bool *d, int len) {
cout<<"\n";
count = 0;
for(i=0; i<len; i++) {
if(d[i]) {
cout<<s[i];
count++;
}
else
cout<<"_";
}
cout<<" ";
}
bool check(char ch, char* s, bool *d, int len) {
bool ret = false;
for(i=0;i<len;i++) {
if(s[i]==ch)
ret = d[i] = true;
}
return ret;
}
void nickname(void) {
cout<<"Nickname: ";
cin>>obj.nick;
}
void play(void) {
nickname();
time_t timer, ntimer;
timer = time(NULL);
char word[6][100] = {
{"rendezvous"},
{"billetdoux"},
{"ballet"},
{"bouquet"},
{"hangman"},
{"mississippi"}
};
srand(time(0));
num = rand()%6; //random 0 to 4 for array index
len = strlen(word[num]);
bool *disp = new bool [len];
for(i=0;i<len;i++)
disp[i] = false;
do {
show(word[num], disp, len);
if(count==len) {
cout<<"\t Is the answer"<<endl;
ntimer = time(NULL);
playtime = ntimer-timer;
gametime.open(file.c_str(), ios::app);
gametime<<"Mode: Hard\tNick: "<<obj.nick<<"\tPlaytime: "<<playtime<<"secs\n";
gametime.close();
gametime.clear();
break;
}
ch = getch();
if(check(ch, word[num], disp, len))
cout<<"\t Cool you got a letter";
else {
cout<<"\t Sorry,wrong";
wrong++;
}
} while(wrong <= max_wrong);
}
hard() {
wrong = 0;
max_wrong = 8;
file = "time.txt";
}
~hard() {}
};
class recordView:public hangman {
string line, file;
ifstream irecord;
ofstream orecord;
public:
void record(void) {
orecord.open(file.c_str(), ios::app); // makes a file if not found
orecord.close();
orecord.clear();
cout<<endl;
irecord.open(file.c_str(), ios::in);
while(!irecord.eof()) {
getline(irecord, line);
cout<<line<<endl;
}
irecord.close();
irecord.clear();
}
recordView() {
file = "time.txt";
}
~recordView() {}
};
void main(void) {
hangman *ptr;
int choose, i=0;
while(i!=1) {
system("cls");
cout<<"Hangman w/o Man\n\n[1] Easy\n[2] Medium\n[3] Hard\n[4] View Play Time\n[5] Exit\nInput your choice: ";
cin>>choose;
switch(choose) {
case 1:
ptr = new easy;
ptr->play();
system("pause");
break;
case 2:
ptr = new medium;
ptr->play();
system("pause");
break;
case 3:
ptr = new hard;
ptr->play();
system("pause");
break;
case 4:
ptr = new recordView;
ptr->record();
system("pause");
break;
case 5:
cout<<"\nMay the force be with you!!\nPresented by \"Hangers Production\"\n"<<endl;
i = 1;
break;
default:
cout<<"Not found on choice"<<endl;
system("pause");
break;
}
}
}
Sem Break! Oh Yaaa!
..aww its our sem break!!
..and that means no more programming class ゛(`ヘ´#)
WAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!!!!
..its hard to say goodbye and bid farewell to my favorite subject
..the c++ object oriented programming class (T ^ T)
..btw hahaha on our last exam (programming) ive got 95/100
DANG!! if only ive followed and listened to the instructions given by our proctor, i might surely get perfect score
..haha and also about our final project (programming) ive got 90/100
..lol my professor told me that if our project has somewhat choices about criminal cases thatll be perfect again ( ̄ー ̄)
haha laziness strikes!!! (stupid me)
..btw our final project was about "criminal records registry" (that's our group's system)
...hmm maybe ill post the source codes here tomorrow
..goodnight!!
oyasumi nasai (@ ̄ρ ̄@)zzzz
..and that means no more programming class ゛(`ヘ´#)
WAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!!!!
..its hard to say goodbye and bid farewell to my favorite subject
..the c++ object oriented programming class (T ^ T)
..btw hahaha on our last exam (programming) ive got 95/100
DANG!! if only ive followed and listened to the instructions given by our proctor, i might surely get perfect score
..haha and also about our final project (programming) ive got 90/100
..lol my professor told me that if our project has somewhat choices about criminal cases thatll be perfect again ( ̄ー ̄)
haha laziness strikes!!! (stupid me)
..btw our final project was about "criminal records registry" (that's our group's system)
...hmm maybe ill post the source codes here tomorrow
..goodnight!!

oyasumi nasai (@ ̄ρ ̄@)zzzz





