Skip to content

Instantly share code, notes, and snippets.

@BasilArackal
Created August 25, 2016 01:32
Show Gist options
  • Save BasilArackal/10020e466108f06e5d71da1191ea25aa to your computer and use it in GitHub Desktop.
Save BasilArackal/10020e466108f06e5d71da1191ea25aa to your computer and use it in GitHub Desktop.
+2 C++ Project
///*
#include <iostream>
#include <fstream>
//*/
/*
#include <iostream.h>
#include <fstream.h>
//*/
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
///*
using namespace std;
#define clrscr() system("cls")
//*/
fstream DB;
char masterpwd[] = "ediary";
class USER
{
public:
char password[9];
char name[50];
void signup()
{
clrscr();
cout<<"\n\t\tEDiary - Sign Up\n\t\t________________\n";
cout<<"\n\tEnter your name (case insensitive): ";
gets(name);
cout<<"\n\tEnter your password(max 8 chars): ";
int i = 0;
char c = 'c';
while(1)
{
c=getch();
if(c=='\r' || c== ' ')
break;
else if(i<9)
{
if(c=='\b' && i>0)
{
cout<<"\b \b";
--i;
}
else if(c!='\b' && i<8)
{
putch('*');
password[i]=c;
++i;
}
}
}
password[i]='\0';
}
int has_wrong(char p[])
{
return strcmp(password, p);
}
void changepwd()
{
clrscr();
cout<<"\n\n\n\n\tEnter the new password you wanna use: ";
int i = 0;
char c = 'c';
while(1)
{
c=getch();
if(c=='\r' || c== ' ')
break;
else if(i<9)
{
if(c=='\b' && i>0)
{
cout<<"\b \b";
--i;
}
else if(c!='\b' && i<8)
{
putch('*');
password[i]=c;
++i;
}
}
}
password[i]='\0';
}
}user;
class POST
{
public:
char content[10000];
int D, M, Y;
void create()
{
time_t t;
struct tm now;
time(&t);
now = *localtime(&t);
D = now.tm_mday;
M = now.tm_mon + 1;
Y = now.tm_year + 1900;
clrscr();
cout<<"\n\n DATE: "<<D<<"-"<<M<<"-"<<Y<<" ( Press(CTRL + Z) and ENTER to save )\n ________________\n\n\n";
cin.getline(content, 10000, 26);
}
short exist(int uY,int uM)
{
if(uY==Y && uM ==M && Y!=-1)
return 1;
else
return 0;
}
short exist(int uY,int uM, int uD)
{
if(uY==Y && uM==M && uD==D)
return 1;
else
return 0;
}
void dshow()
{
clrscr();
cout<<"\n\n DATE: "<<D<<"-"<<M<<"-"<<Y<<" (Press 'Del' to delete 'SPACE' to move to the next post)\n ________________\n\n\n";
cout<<content;
cout<<"\n\n";
}
void ashow()
{
clrscr();
cout<<"\n\n DATE: "<<D<<"-"<<M<<"-"<<Y<<" (Press SPACE to append to this post)\n ________________\n\n\n";
cout<<content;
}
void nullify()
{
strcpy(content, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
D = M = Y = -1;
}
}post;
int main()
{
///*
{
cout<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<" .-^-."<<endl;
cout<<" .'=^=^='."<<endl;
cout<<" /=^=^=^=^=\\ "<<endl;
cout<<" .-~-. :^= EDiary=^;"<<endl;
cout<<" .'~~*~~'.|^ ^_^ ! ^|"<<endl;
cout<<" /~~*~~~*~~\\^=^=^=^=^=^:"<<endl;
cout<<" :~*~~~*~~~*~;\\.-*))`*-,/"<<endl;
cout<<" |~~~*~~~*~~|/* ((* *'."<<endl;
cout<<" :~*~~~*~~~*| *)) * *\\ "<<endl;
cout<<" \\~~*~~~*~~| * ((* * / "<<endl;
cout<<" `.~~*~~.' \\ *)) * .'"<<endl;
cout<<" `~~~` '-.((*_.-'"<<endl;
}
cout<<"\n\n\tEDiary is an Open Source project created by Balu & Basil\n";
cout<<"\n\n\tPress any key to Start...";
getch();
char pwd[7];
while(1)
{
clrscr();
cout<<"\n\n\n\n\n\n\n\n\t\tEnter your password: ";
int i = 0;
char c = 'c';
while(1)
{
c=getch();
if(c=='\r' || c== ' ')
break;
else if(i<9)
{
if(c=='\b' && i>0)
{
cout<<"\b \b";
--i;
}
else if(c!='\b' && i<8)
{
putch('*');
pwd[i]=c;
++i;
}
}
}
pwd[i]='\0';
if(!strcmp(masterpwd, pwd))
break;
else
{
cout<<"\n\n\tWrong Password!";
cout<<"\n\tPress any key to try again...";
getch();
}
}
//*/
//Program Starts here ^_^
while(1)
{
clrscr();
cout<<endl<<endl<<endl;
cout<<"\n\t\t\tEDiary - Main Menu\n\t\t\t__________________\n";
cout<<"\n\t\t1.New User? Sign up...\n";
cout<<"\n\t\t2.Existing User? Sign In...\n";
cout<<"\n\t\t3.Exit\n";
cout<<"\n\tEnter your choice: ";
switch(getch())
{
case '1':
{
user.signup();
DB.open(user.name, ios::in);
if(!DB)
{
DB.close();
DB.open(user.name, ios::out|ios::binary);
if(DB)
{
DB.seekp(0);
DB.write((char*)&user, sizeof(user));
DB.close();
clrscr();
{
cout<<"\n -=\\`\\"<<endl;
cout<<" |\\ ____\\_\\"<<endl;
cout<<" -=\\c`\"\"\"\"\"\"\" \"`)"<<endl;
cout<<" `~~~~~/ /~~`"<<endl;
cout<<" -==/ /"<<endl;
cout<<" '-'"<<endl<<endl;
cout<<" ___( ` )_"<<endl;
cout<<" ___( ) `)"<<endl;
cout<<" ___(_ (_ . _) _)"<<endl;
cout<<"\n ( )"<<endl;
cout<<" _ . ( ` ) . )"<<endl;
cout<<" ( _ )_ (_, _( ,_)_)"<<endl;
cout<<" (_ _(_ ,)"<<endl;
}
cout<<"\n\n\n\n\t";
cout<<user.name<<", Your Account is ready!\n";
cout<<"\tPress 'ENTER' to head to your Dashboard...";
getch();
cin.clear();
//FINISHED WHILE GOES HERE!
break;
}
else
{
DB.close();
clrscr();
{
cout<<endl<<endl;
cout<<" .-\"\"\"\"-."<<endl;
cout<<" / - - \\ "<<endl;
cout<<" | .-. .- |"<<endl;
cout<<" | \\o| |o ("<<endl;
cout<<" \\ ^ \\ Oops! Something went wrong!"<<endl;
cout<<" |'. )--' /| "<<endl;
cout<<" / / '-. .-'`\\ \\ "<<endl;
cout<<" / /'---` `---'\\ \\ "<<endl;
cout<<" '.__. .__.'"<<endl;
cout<<" `| |`"<<endl;
cout<<" | \\ "<<endl;
cout<<" \\ '--."<<endl;
cout<<" '. `\\ "<<endl;
cout<<" `'---. |"<<endl;
cout<<" ,__) /"<<endl;
cout<<" `..'"<<endl;
}
cout<<"\n\n\n\tMake sure your username is valid!";
cout<<"\n\n\tPress any key to Try again later... ";
getch();
break;
}
}
else
{
DB.close();
clrscr();
{
cout<<"\n\n _____\n";
cout<<" / \\______ \n";
cout<<" | .-\"\"-. | \n";
cout<<" | / \\ |\n";
cout<<" | \\ / | \n";
cout<<" | '-..-;\\ | \n";
cout<<" |________\\\\___| \n";
cout<<" \\|\n";
}
cout<<"\n\n\n\tLooks like the account you're trying to create already exists!";
cout<<"\n\tPress any key to try again with a different username...";
getch();
break;
}
}
case '2':
{
char name[50];
clrscr();
cout<<"\n\n\n\n\t\tEDiary - Sign In\n\t\t________________\n";
cout<<"\n\tEnter your name(case insensitive): ";
gets(name);
DB.open(name, ios::in);
if(!DB)
{
DB.close();
clrscr();
{
cout<<endl<<endl;
cout<<" .-\"\"\"\"-."<<endl;
cout<<" / - - \\ "<<endl;
cout<<" | .-. .- |"<<endl;
cout<<" | \\o| |o ("<<endl;
cout<<" \\ ^ \\ Oops! Such an account doesn't exist!"<<endl;
cout<<" |'. )--' /| "<<endl;
cout<<" / / '-. .-'`\\ \\ "<<endl;
cout<<" / /'---` `---'\\ \\ "<<endl;
cout<<" '.__. .__.'"<<endl;
cout<<" `| |`"<<endl;
cout<<" | \\ "<<endl;
cout<<" \\ '--."<<endl;
cout<<" '. `\\ "<<endl;
cout<<" `'---. |"<<endl;
cout<<" ,__) /"<<endl;
cout<<" `..'"<<endl;
}
cout<<"\n\t\tAre you trying to create a new account?\n";
cout<<"\n\t\tPress any key to return to Main Menu...";
getch();
break;
}
else
{
char password[9];
cout<<"\n\tEnter your password(max 8 chars): ";
int i = 0;
char c = 'c';
while(1)
{
c=getch();
if(c=='\r' || c== ' ')
break;
else if(i<9)
{
if(c=='\b' && i>0)
{
cout<<"\b \b";
--i;
}
else if(c!='\b' && i<8)
{
putch('*');
password[i]=c;
++i;
}
}
}
password[i]='\0';
DB.read((char*)&user, sizeof(user));
DB.close();
if(user.has_wrong(password))
{
clrscr();
{
cout<<endl<<endl;
cout<<" .-\"\"\"\"-."<<endl;
cout<<" / - - \\ "<<endl;
cout<<" | .-. .- |"<<endl;
cout<<" | \\o| |o ("<<endl;
cout<<" \\ ^ \\ Oops! That's an incorrect password!"<<endl;
cout<<" |'. )--' /| "<<endl;
cout<<" / / '-. .-'`\\ \\ "<<endl;
cout<<" / /'---` `---'\\ \\ "<<endl;
cout<<" '.__. .__.'"<<endl;
cout<<" `| |`"<<endl;
cout<<" | \\ "<<endl;
cout<<" \\ '--."<<endl;
cout<<" '. `\\ "<<endl;
cout<<" `'---. |"<<endl;
cout<<" ,__) /"<<endl;
cout<<" `..'"<<endl;
}
cout<<"\n\n\tPress any key to return to Main Menu...";
getch();
break;
}
//The WHILE PART
while(1)
{
clrscr();
cout<<endl<<endl<<endl;
cout<<"\n\t\tEDiary - Dashboard\n\t\t__________________\n";
cout<<"\n\t1.Read / Delete\n";
cout<<"\n\t2.Write / Append\n";
cout<<"\n\t3.Change password\n";
cout<<"\n\t4.Sign out & Exit\n";
cout<<"\nEnter your choice: ";
switch(getch())
{
case '1':
clrscr();
DB.open(user.name,ios::in|ios::out|ios::app|ios::ate);
if(!DB)
{
DB.close();
clrscr();
{
cout<<endl<<endl;
cout<<" .-\"\"\"\"-."<<endl;
cout<<" / - - \\ "<<endl;
cout<<" | .-. .- |"<<endl;
cout<<" | \\o| |o ("<<endl;
cout<<" \\ ^ \\ Oops! Something went wrong! Try again later!"<<endl;
cout<<" |'. )--' /| "<<endl;
cout<<" / / '-. .-'`\\ \\ "<<endl;
cout<<" / /'---` `---'\\ \\ "<<endl;
cout<<" '.__. .__.'"<<endl;
cout<<" `| |`"<<endl;
cout<<" | \\ "<<endl;
cout<<" \\ '--."<<endl;
cout<<" '. `\\ "<<endl;
cout<<" `'---. |"<<endl;
cout<<" ,__) /"<<endl;
cout<<" `..'"<<endl;
}
cout<<"\n\n\tPress any key to return to Main Menu...";
getch();
break;
}
else
{
int Y;
time_t t;
struct tm now;
time(&t);
now = *localtime(&t);
Y = now.tm_year + 1900;
int cM, cY, Dpressed = 0;
while(1)
{
clrscr();
cout<<"\n\n\n\t\tEnter the year(eg: 2013): ";
cin>>cY;
if(cY>Y)
{
cout<<"\n\n\t\tCome on! let future be a mystery! :P\n";
cout<<"\n\tPress Any key to try again...";
getch();
}
else if(cY<1970)
{
cout<<"\n\n\t\tEDiary was never even out then!\n";
cout<<"\n\tPress Any key to try again...";
getch();
}
else
break;
}
while(1)
{
clrscr();
cout<<"\n\n\n\t\tEnter the month(eg: 12): ";
cin>>cM;
if(cM<1||cM>12)
{
cout<<"\n\n\t\tReally is that a valid month?? :P\n";
cout<<"\n\tPress Any key to try again...";
getch();
}
else
break;
}
clrscr();
//cM = cY = -1;
DB.seekg(sizeof(user));
//cout<<DB.tellg();getch();
short found = 0;
while(!DB.eof())
{
int x=DB.tellg();
DB.read((char*)&post, sizeof(post));
//post.dshow();
//getch();
if(DB.eof())break;
if(post.exist(cY, cM))
{
found = 1;
post.dshow();
char c = getch();
if(c == 'd')
{
//Dpressed = 1;
cout<<sizeof(post)<<"\n\n\tThe post will be deleted!";
post.nullify();
//cout<<DB.tellg()<<"---"<<DB.tellp()<<endl;
DB.seekg(x);
//cout<<DB.tellg()<<"---"<<DB.tellp()<<endl;
//cout<<post.D<<"---"<<DB.tellp()<<endl;
DB.write((char*)&post, sizeof(post));
//clrscr();
c='x';
getch();
cin.clear();
}
}
}
DB.close();
/*
if(Dpressed)
{
post.nullify();
cout<<post.D<<post.M<<post.Y;
DB.open(user.name);
if(!DB){cout<<"err";getch();}
DB.seekp(to);
//DB.seekg(to);
//cout<<" "<<DB.tellp();
DB.write((char*)&post, sizeof(post));
DB.close();
cout<<"\n\n\tDELETED";
getch();
Dpressed = 0;
cin.clear();
}
//*/
if(!found)
{
clrscr();
cout<<"\n\n\n\t\tNo Posts were made in that Month of the Year\n";
cout<<"\n\n\n\t\tPress any key to return to your Dashboard...";
getch();
}
else
{
clrscr();
cout<<"\n\n\n\t\tThat's all folks!";
cout<<"\n\n\n\t\tPress any key to return to your Dashboard...";
getch();
}
break;
}
case '2':
clrscr();
DB.open(user.name, ios::in);
if(!DB)
{
DB.close();
clrscr();
{
cout<<endl<<endl;
cout<<" .-\"\"\"\"-."<<endl;
cout<<" / - - \\ "<<endl;
cout<<" | .-. .- |"<<endl;
cout<<" | \\o| |o ("<<endl;
cout<<" \\ ^ \\ Oops! Something went wrong! Try again later!"<<endl;
cout<<" |'. )--' /| "<<endl;
cout<<" / / '-. .-'`\\ \\ "<<endl;
cout<<" / /'---` `---'\\ \\ "<<endl;
cout<<" '.__. .__.'"<<endl;
cout<<" `| |`"<<endl;
cout<<" | \\ "<<endl;
cout<<" \\ '--."<<endl;
cout<<" '. `\\ "<<endl;
cout<<" `'---. |"<<endl;
cout<<" ,__) /"<<endl;
cout<<" `..'"<<endl;
}
cout<<"\n\n\tPress any key to return to Main Menu...";
getch();
break;
}
else
{
DB.close();
DB.open(user.name, ios::in|ios::out|ios::ate);
if(!DB)
{
{
cout<<endl<<endl;
cout<<" .-\"\"\"\"-."<<endl;
cout<<" / - - \\ "<<endl;
cout<<" | .-. .- |"<<endl;
cout<<" | \\o| |o ("<<endl;
cout<<" \\ ^ \\ Oops! Something went wrong! Try again later!"<<endl;
cout<<" |'. )--' /| "<<endl;
cout<<" / / '-. .-'`\\ \\ "<<endl;
cout<<" / /'---` `---'\\ \\ "<<endl;
cout<<" '.__. .__.'"<<endl;
cout<<" `| |`"<<endl;
cout<<" | \\ "<<endl;
cout<<" \\ '--."<<endl;
cout<<" '. `\\ "<<endl;
cout<<" `'---. |"<<endl;
cout<<" ,__) /"<<endl;
cout<<" `..'"<<endl;
}
"\n\n\nPress any key to return to your Dashboard...\n";
getch();
break;
}
DB.seekg(sizeof(user));
int D, M, Y;
time_t t;
struct tm now;
time(&t);
now = *localtime(&t);
D = now.tm_mday;
M = now.tm_mon + 1;
Y = now.tm_year + 1900;
int notFound=1;
while(!DB.eof()&&notFound)
{
long toAppendPos = DB.tellg();
DB.read((char*)&post, sizeof(post));
if(post.exist(Y,M,D))
{
notFound=0;
char temp[10000];
post.ashow();
cin.getline(temp,10000,26);
strcat(post.content,temp);
DB.seekp(toAppendPos);
DB.write((char*)&post, sizeof(post));
break;
}
}
DB.close();
if(notFound)
{
DB.open(user.name, ios::out|ios::app);
post.create();
DB.write((char*)&post, sizeof(post));
DB.close();
clrscr();
{
cout<<"\n -=\\`\\"<<endl;
cout<<" |\\ ____\\_\\"<<endl;
cout<<" -=\\c`\"\"\"\"\"\"\" \"`)"<<endl;
cout<<" `~~~~~/ /~~`"<<endl;
cout<<" -==/ /"<<endl;
cout<<" '-'"<<endl<<endl;
cout<<" ___( ` )_"<<endl;
cout<<" ___( ) `)"<<endl;
cout<<" ___(_ (_ . _) _)"<<endl;
cout<<"\n ( )"<<endl;
cout<<" _ . ( ` ) . )"<<endl;
cout<<" ( _ )_ (_, _( ,_)_)"<<endl;
cout<<" (_ _(_ ,)"<<endl;
}
cout<<"\n\n\n\t\tEntry Made!!\n";
cout<<"\n\t\tPress any key to return to your Dashboard...";
getch();
cin.clear();
break;
}
} break;
case '3':
DB.open(user.name, ios::out|ios::binary);
if(!DB)
{
DB.close();
clrscr();
{
cout<<endl<<endl;
cout<<" .-\"\"\"\"-."<<endl;
cout<<" / - - \\ "<<endl;
cout<<" | .-. .- |"<<endl;
cout<<" | \\o| |o ("<<endl;
cout<<" \\ ^ \\ Oops! Something went wrong! Try again later!"<<endl;
cout<<" |'. )--' /| "<<endl;
cout<<" / / '-. .-'`\\ \\ "<<endl;
cout<<" / /'---` `---'\\ \\ "<<endl;
cout<<" '.__. .__.'"<<endl;
cout<<" `| |`"<<endl;
cout<<" | \\ "<<endl;
cout<<" \\ '--."<<endl;
cout<<" '. `\\ "<<endl;
cout<<" `'---. |"<<endl;
cout<<" ,__) /"<<endl;
cout<<" `..'"<<endl;
}
cout<<"\n\n\tPress any key to return to Main Menu...";
getch();
break;
}
else
{
user.changepwd();
DB.seekp(0);
DB.write((char*)&user, sizeof(user));
DB.close();
clrscr();
{
cout<<"\n -=\\`\\"<<endl;
cout<<" |\\ ____\\_\\"<<endl;
cout<<" -=\\c`\"\"\"\"\"\"\" \"`)"<<endl;
cout<<" `~~~~~/ /~~`"<<endl;
cout<<" -==/ /"<<endl;
cout<<" '-'"<<endl<<endl;
cout<<" ___( ` )_"<<endl;
cout<<" ___( ) `)"<<endl;
cout<<" ___(_ (_ . _) _)"<<endl;
cout<<"\n ( )"<<endl;
cout<<" _ . ( ` ) . )"<<endl;
cout<<" ( _ )_ (_, _( ,_)_)"<<endl;
cout<<" (_ _(_ ,)"<<endl;
}
cout<<"\n\n\n\t\tPassword Change successful!!\n";
cout<<"\n\t\tPress any key to return to your dashboard... ";
getch();
break;
}
case '4':
return 0;
break;
default:
cout<<"Invalid Choice! Press any key to try again...";
getch();
break;
}
}
break;
}
}
case '3':
{
return 0;
break;
}
default:
{
cout<<"Invalid Choice! Press any key to try again...";
getch();break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment