You are on page 1of 7

/*

Header files */

#include<fstream.h> //for reading & writing files


#include<conio.h>
//for clrscr() & getch()
#include<stdio.h>
//for gets puts function
#include<string.h>
//for string characters
#include<dos.h>
//for getdate function
#include<process.h> //for exit function
/*class email to store user info */
class email
{ char name[50],id[50],pass[20];
public:
int base();
void signup();
void login();
void del(char pid[]);
char *retname()
{
return name; }
char *retid()
{
return id;
}
char *retpass()
{
return pass;
}
}obj;
// structure to store user message
struct email_acct
{
char to[50],message[100];
int year,month,day;
}obj1;
/* Global variables */
char tname[50],tid[50],tpass[20],pid[50],pname[50];
/* Returning function to check password */
int checkpas(char pas[])
{ int k=5;
ifstream file2("sign",ios::binary);
while(file2.read((char*)&obj,sizeof(obj)))
{
if(strcmp(pas,obj.retpass())==0)
k=0;
}
file2.close();
return k;
}
int checkid(char nm[]) /* Returning function to check user ID */
{ int k=5;
ifstream file1("sign",ios::binary);
while(file1.read((char*)&obj,sizeof(obj)))
{
if(strcmp(nm,obj.retid())==0)
{ k=0;
strcpy(tid,obj.retid());
strcpy(tname,obj.retname());
strcpy(tpass,obj.retpass());
}
}
file1.close();
return k;
}
int menu(char pname[], char pid[]) //for user menu selection
{ int y=6;

char ch;
label1:
clrscr();
gotoxy(26,4);cout<<"Welcome "<<pname<<" your id : "<<pid;
gotoxy(20,25);cout<<"Controls:: 'w'==>Up, 's'==>down & 'Enter'==>select"
;
gotoxy(30,6);cout<<"Profile ";
gotoxy(30,7);cout<<"Inbox ";
gotoxy(30,8);cout<<"Compose ";
gotoxy(30,10);cout<<"Log out ";
gotoxy(30,9);cout<<"Delete ";
gotoxy(27,y);cout<<"::";
ch=getch();
if(ch==13)
{
if(y==6||y==7||y==8||y==9||y==10)
return y;
}
else if(ch=='w')
{ y=y-1;
gotoxy(29,y);
}
else if(ch=='s')
{
y=y+1;
gotoxy(29,y);
}
if(y<=5)
y=10;
else if(y>=11)
y=6;
goto label1;
}
void del(char pid[]) //function for deleting account
{ char ch;
clrscr();
ifstream file1("sign",ios::in|ios::binary);
ofstream file2("temp",ios::out|ios::binary);
while(file1.read((char*)&obj,sizeof(obj)))
{
if(strcmp(obj.retid(),pid)==0)
{
cout<<"Are you sure you want to delete account(y/n)..";
cin>>ch;
if(ch=='n')
file2.write((char*)&obj,sizeof(obj));
}
else
file2.write((char*)&obj,sizeof(obj));
}
remove("sign");
rename("temp","sign");
if(ch=='y')
obj.base();
}
void del_mail(char pid[],int n) //for deleting mail or massage
{
int i=0;
char ch;
clrscr();
ifstream fp(pid,ios::binary);

ofstream file2("temp1",ios::out|ios::binary);
while(fp.read((char*)&obj1,sizeof(obj1)))
{
i++;
if(n==i)
{
cout<<"Are you sure you want to delete mail(y/n)..";
cin>>ch;
if(ch=='n')
file2.write((char*)&obj1,sizeof(obj1));
}
else
file2.write((char*)&obj1,sizeof(obj1));
}
remove(pid);
rename("temp1",pid);
}
void profile(char nm[],char pid[]) //user profile information
{ int i=0;
clrscr();
gotoxy(30,6);cout<<"Name ";
puts(nm);
gotoxy(30,7);cout<<"\nId ";
puts(pid);
ifstream fp(pid,ios::binary);
while(fp.read((char*)&obj1,sizeof(obj1)))
i++;
struct date d;
int year,month,day;
getdate(&d);
year=d.da_year;
day=d.da_day;
month=d.da_mon;
cout<<"\n\nToday is\t"<<day<<"/"<<month<<"/"<<year;
gotoxy(30,9);cout<<"\nNo. of mails "<<i;
fp.close();
}
int inbox(char pid[]) //function for user inbox
{
int i=0,n,chkid,x=3;
char ch;
clrscr();
ifstream fp(pid,ios::binary);
ifstream fp1(pid,ios::binary);
while(fp.read((char*)&obj1,sizeof(obj1)))
{ i++;
gotoxy(2,x);cout<<i;
gotoxy(25,x);puts(obj1.to);
gotoxy(45,x);cout<<obj1.day<<"/"<<obj1.month<<"/"<<obj1.year;
x++;
}
if(i!=0)
{
gotoxy(2,1);cout<<"SL no \t\t\tFrom \t\t\tRecived on";
gotoxy(2,x+1);cout<<"Enter the main no. you want to view ";
cin>>chkid;
}
fp.close();
i=0;
clrscr();
while(fp1.read((char*)&obj1,sizeof(obj1)))

{ i++;
if(i==chkid)
{ n=i;
cout<<"\n"<<i<<" => From:: ";
puts(obj1.to);
cout<<endl;
cout<<"Recived on \t"<<obj1.day<<"/"<<obj1.month<<"/"<<o
bj1.year<<endl<<endl;
puts(obj1.message);
cout<<endl;
}
}
if(i==0)
{
cout<<"Sorry,, No mail found"<<"\n\nPress any key to go back";
getch();
}
else
{
back1:
gotoxy(23,23);cout<<"To delete mail Press 'D'";
gotoxy(22,24);cout<<"To go back press backspace ";
ch=getch();
if(ch=='d'||ch=='D')
del_mail(pid,n);
else if(ch==8)
return 0;
else goto back1;
}
fp1.close();
return 0;
}
int compose(char pid[]) //for composing & sending mails
{ first:
clrscr();
int k;
char rid[30],opt;
opt=NULL;
cout<<"Press 'y' to compose and send massage.. ";
cin>>opt;
if(opt=='y'||opt=='Y')
{
cout<<"To (reciver id) => ";
gets(rid);
k=checkid(rid);
if(k!=0||strcmp(rid,pid)==0)
{
cout<<"\n\n\tplease enter valid id";
getch();
goto first; }
else
{ fstream cfile(rid,ios::in|ios::binary|ios::app);
strcpy(obj1.to,pid);
cout<<"Enter Message => ";
gets(obj1.message);
struct date d;
getdate(&d);
obj1.year=d.da_year;
obj1.day=d.da_day;
obj1.month=d.da_mon;
cfile.write((char*)&obj1,sizeof(obj1));
cfile.close();
cout<<"Massage sent!!!";
} }

else if(opt=='n'||opt=='N')
return 0;
else
goto first;
}
int mail() //for calling selected option
{ int y;
mlabel:
clrscr();
char ch;
gotoxy(20,25);cout<<"Controls:: 'w'==>Up, 's'==>down & 'Enter'==>select"
;
y=menu(pname,pid);
if(y==6)
profile(pname,pid);
else if(y==7)
{
inbox(pid);
goto mlabel;
}
else if(y==8)
compose(pid);
else if(y==10)
{
return 0;
}
else if(y==9)
del(pid);
if(y!=7)
{
back:
gotoxy(24,24);cout<<"Press backspace to go back";
ch=getch();
if(ch==8)
goto mlabel;
else goto back;
}
return 0;
}
void email::signup()
//function for creating account
{ clrscr();
char ch,nm[30],name1[30];
int x=43,k,i=0;
fstream file("sign",ios::in|ios::binary|ios::app);
gotoxy(25,5);cout<<"Enter your detail below";
gotoxy(25,6);cout<<"Name :=>";
gotoxy(43,6);gets(name1);
gotoxy(25,7);cout<<"your new id :=>";
gotoxy(43,7);gets(nm);
k=checkid(nm);
if(k!=0)
{
gotoxy(25,8);cout<<"Password
:=>";
gotoxy(25,9);cout<<"(4 digit numeric password)";
while(i>=0||i<5)
{
gotoxy(x,8);ch=getch();
if(ch==8)
{ i=i-1;
x=x-1;
cout<<"\b";
}
else if(ch==13)
{

pass[i]='\0';
break;
}
else
{

cout<<"*";
obj.pass[i]=ch;
i++;
x+=1; }

}
strcpy(obj.name,name1);
strcpy(obj.id,nm);
file.write((char*)&obj,sizeof(obj));
fstream pro(nm,ios::in|ios::out|ios::binary);
}
else
{

cout<<"ID is present please enter another id... ";


getch(); }
file.close();

}
void email::login() //function for login in account
{
int k,l,x=46,i=0;
clrscr();
char nm[30],ch,pas[10];
gotoxy(25,6);cout<<"Enter your ID";
gotoxy(46,6);gets(nm);
gotoxy(25,8);cout<<"Enter your password";
while(i>=0||i<5)
{
gotoxy(x,8);ch=getch();
if(ch==8)
{ i=i-1;
x=x-1;
cout<<"\b";
}
else if(ch==13)
{
pas[i]='\0';
break;
}
else
{
cout<<"*";
pas[i]=ch;
i++;
x+=1; }
}
l=checkpas(pas); //password cheaking function is called
k=checkid(nm);
//id cheaking function is called
if(k!=0 || l!=0)
{
gotoxy(30,10);cout<<"Id or password is incorrect";
getch();
}
else
{ strcpy(pid,tid);
strcpy(pname,tname);
mail();
}
}
int email::base()
{ char ch;
int y=10;
label:
clrscr();

gotoxy(20,25);cout<<"Controls:: 'w'==>Up, 's'==>down & 'Enter'==>select"


;
gotoxy(30,10);cout<<"Login";
gotoxy(30,12);cout<<"Signup";
gotoxy(30,14);cout<<"Exit";
gotoxy(27,y);cout<<"::";
ch=getch();
if(ch==13)
{ if(y==10)
obj.login();
else if(y==12)
obj.signup();
else if(y==14)
{
clrscr();
gotoxy(30,10);cout<<"Thankyou";
exit(0);
}
}
else if(ch=='w')
{ y=y-2;
gotoxy(29,y); }
else if(ch=='s')
{
y=y+2;
gotoxy(29,y); }
if(y<=9)
y=14;
else if(y>=15)
y=10;
goto label;
}
void main()
{
gotoxy(30,5);cout<<"CoMpUtEr PrOjEcT";
gotoxy(20,7);cout<<"DeMoNsTrAtIoN oF eMaIl AcCoUnT wOrKiNg";
gotoxy(35,18);cout<<"Presented by :-";
gotoxy(35,19);cout<<"\tRavi Anand & Partho Kumar";
gotoxy(35,20);cout<<"\tS.J.D.A.V.Public School";
gotoxy(35,21);cout<<"\tSession 2013-14";
gotoxy(5,25);cout<<"\t\t\tPress any key to countinue";
getch();
obj.base();
}

You might also like