Twitter: Iimt Engineering Colege

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 77

IIMT ENGINEERING COLEGE

TWITTER

SUBMITTED TO:
Mr. Achilesh Tyagi.
Department: BCA
HOD: Mr. Neeraj Sharma
INDEX
Sr.N Topic Page No.
o.
1 Acknowledgement 3
2 Certificate 4
3 Introduction to 5
TWITTER
4 Scope and 6
Objective of the
Project
5 System 8
Development life
Cycle
6 Software and 10
hardware
requirements
7 Language Used(C+ 11
+)
8 Dataflow Diagram 13
9 Source Code 14
2
10 Snapshots 73
11 Bibliography 78
ACKNOWLEDGEMENT

I
Gratefully acknowledge the valuable
contributions and suggestions of my dear
friends, class mates and a helping hand
from our most respectable subject
teacher Mr. Achilesh Tyagi who was
always with me to help me in any
manner he can. I hope that I would get
the same coordination from my teachers
and friends in future.

While working with this project I got to


learn more of its deepness and got a
better hold on its concepts and
2
programming logics. I am thankful to all
those who are concerned with this
project.

Checked by:
(Initials)

Name: _______________ Roll Number: _____________

BCA 6th SEM


IIMT ENGINEERING COLLEGE (GANGANAGAR)

2
This is certified to be the
bonafide work of the student in
the Project during the academic
year 2009-2010.

………………………
(Teachers Signature)

TWITTER

Twitter is an offline emulation of the


original website www.twitter.com. In this
software two things has been primarily
focused, one is that how a language Like
C++ can be utilized to make Graphically
attractive and user friendly software.
Secondly it shows the use of C++’s file
handling capabilities as a base for
database on small systems. This software
works almost the same way as the former,
but of course without a online support.
2
However with slight modification it can
work on Local Area Networks.
Here you create accounts, and post your
tweets. The people following you will
receive your tweets and will be visible
within their own tweet viewing window. The
tweets are sorted chronologically, so you
even get to see the date and time of the
tweet. If you follow someone their tweets
will be visible within your own tweets.
OBJECTIVE AND SCOPE OF THE
PROJECT
The objective of the project “Twitter” is to automate the current complex
manual system of Store Management on real time basis.

Features which supplement the main objective are:

• System Oriented Approach rather than user Oriented

Now the organizations have system oriented approach rather than user
oriented. User having basic knowledge of computer can maintain the
approach. Now it is very easy to maintain all the posts and followers.

• Real Time Solution

2
This project provides real time solution to all the queries. Posts
of tweets and posts of the tweets of your follower, all of them can be viewed
, can be generated at any time or when suitable.

• Accurate & Time Saving

The project provides accuracy to the tracking of new posts and to all
the inputs. Some parts of information like date and time of tweet are
automatically added by the program. It saves the time of user
and now large volume of tweets for communication handled smoothly
and easily.

• Fast and Reliable

This project has made possible to quicken communication process. Earlier


it was required to visit the individual in person every time it was required
to ask or say somthing . Now after making a tweet the posts are
automatically updated in the posts of the followers.

• User Friendly

Any person having basic knowledge of chatting and computers can


handle the Package with ease. Attractive Graphics with commands
limited to entering numbers to select options provide simple interface to the
user.

2
SYSTEM DEVELOPMENT CYCLE
(SDLC)

The system development life cycle is a structured


sequence of phases for implementing an information system.

INITIAL INVESTIGATION: - A system is made to solve a


problem. This step is called PROBLEM IDENTIFICATION.

FEASIBILITY STUDY: - A feasibility study is conducted to see


whether the required system is “Workable”. The phase may result
in a decision to not to go in for subsequent phases as the system is
found to be infeasible.

DESIGN : - It is the phase when “What” the system is to do, is


converted into “how” the system shall do it.

DEVELOPMENT :- Development is the phase where he detailed


design is actually used to construct the system. The phase is also
called the CONSTRUCTION.

IMPLEMENTATION: - In the phase, user actually starts using the


system. This phase involves training the users for using the system.

2
MAINTENANCE :- Maintenance of the system involves activities like
fixing problems that may arise while running the system and
evaluating and incorporating change requests.

HARDWARE AND SOFTWARE


REQUIREMENTS

HARDWARE REQUIREMENTS:

Processor Intel Pentium 16 MHz

Memory: 16 MB RAM

Hard disk: 2GB Hard disk

2
Monitor: 15 Inch color monitor

SOFTWARE REQUIREMENTS:

Operating System: Windows 98,

Novel LAN Network,

Windows 2000

Compiler: Turbo ‘C++’ 3.0

LANGUAGE USED
C++:- C++ programming language was developed
at AT&T Bell laboratories in the early 1980s by Bjarne
Stroustrup. This language was called as “C with classes”
originally. The name ‘C++’ was coined by Rick Mascitti
where “++” is the C increment operator.
The major reason behind the success and popularity
of the C++ is that it supports the Object Oriented
Programming (OOP), the latest in the software
development and the most near to the real world. One
can easily judge the importance of C++ as given in the
following lines:

2
“Object Oriented Technology is regarded as
the ultimate paradigm for the modeling information, be hat
data or logic. The C++ has by now shown to fulfill this goal.”
Features of C++:- The OOP approach is based on
certain concepts that help it attain its goal of
overcoming the drawbacks or shortcomings of
conventional programming approaches. These general
concepts of OOP are given below:
1. Data Abstraction
2. Data Encapsulation
3. Inheritance
4. Polymorphism

Data Abstraction: Abstraction refers to the act of


representing essential features without including the
background details.
Data Encapsulation: The Wrapping up of data and functions
(that operate on the data) into a single unit (called class) is
known as encapsulation. It is just a way to implement data
abstraction.
Inheritance: Inheritance is the capability of one
class of things to inherit capabilities or properties from
another class.
Polymorphism: Polymorphism is the ability for a
message or data to be processed in more than one form.
It is the property by which the same message can be sent
to objects of several different classes, and each object can
respond in a different way depending on its class.
2
CONCEPTUAL DATA FLOW DIAGRAM
(0 LEVEL)

2
Program Source Code:
#include<RAJ.H>

/*Function to populate the list of followers*/

int populatelist() //Returning just to escape this function

{ //Return value may not be used

tfollow thefollows;

ifstream followf;

int counter=0;

followf.open("tfollow.sam",ios::in|ios::binary);

while(!followf.eof())

followf.read((char*)&thefollows,sizeof(thefollows));

if(strcmp(thefollows.user1,logedinuser)==0)

strcpy(followlist[counter],thefollows.user2);

counter++;

if(counter>(loggedinfollows-1))

followf.close();

return 1;

2
}

followf.close();

return 0;

/*******************************/

/*Function to check what user did in tweetbox & do accordingly*/

int whathedid()

tweets thetweet;

tuser theuser;

ofstream tweetf; //to save tweet

fstream userf; //to update user tweet status

long pos; //to save file pointer position

switch(mytweet[0])

case '1':

if(tweetfavail==0||hastweets==0)

2
gotoxy(1,MAXY);

cout<<" **There are no Tweets for the user**


";

window(2,8,79,10); //clear only tweet area

textbackground(2);

clrscr();

window(1,1,80,MAXY); //reset the screen

gotoxy(2,8);

return 1;

viewtweets();

return 1;

case '2':

follow();

return 2;

case '3':

pifollow();

return 3;

2
}

case '4':

_setcursortype(_NOCURSOR); //Hide Cursor

textbackground(4);

puttext(1,1,80,MAXY,fscreenbuf); // Refresh screen

window(2,12,79,MAXY-2); //clears the output area cause buffer


had option text

clrscr();

gotoxy(1,(MAXY/2)-6); //goto a relative position in the screen

cprintf(" !!YOU ARE LOGGED OUT!!\r\n");

cprintf(" PLEASE LOGIN AGAIN TO ACCESS YOUR


ACCOUNT");

window(1,1,80,MAXY); //reset window

gotoxy(1,MAXY);

textbackground(2);

while(!kbhit())

cprintf("|| [ \\ ] Logged Out Successfully | Press any key to go


back to Home

\r");

delay(200);

2
cprintf("|| [ | ] Logged Out Successfully | Press any key to go
back to Home

\r");

delay(200);

cprintf("|| [ / ] Logged Out Successfully | Press any key to go


back to Home

\r");

delay(200);

cprintf("|| [---] Logged Out Successfully | Press any key to go


back to Home

\r");

delay(200);

getch();

_setcursortype(_NORMALCURSOR); //Reset Cursor

return 4;

case '5':

deleteacc();

return 5;

2
case '6':

about();

return 6;

default:

if(!strlen(mytweet)==0)

getdate(&thetweet.tdate);

gettime(&thetweet.ttime);

strcpy(thetweet.tuser,logedinuser);

strcpy(thetweet.tweet,mytweet);

tweetf.open("tweets.sam",ios::out|ios::app|ios::ate|ios::binary);

tweetf.write((char*)&thetweet,sizeof(thetweet));

tweetf.close();

window(2,8,79,10); //clear only tweet area

textbackground(2);

clrscr();

window(1,1,80,MAXY); //reset the screen

userf.open("userf.sam",ios::in|ios::out|ios::binary);

2
userf.seekg(0);

while(!userf.eof())

pos=userf.tellg();

userf.read((char*)&theuser,sizeof(theuser));

if((strcmp(theuser.tusername,logedinuser)==0)&&(strcmp(the
user.tpassword,password)==0))

theuser.hastweet=1;

userf.seekg(pos);

userf.write((char*)&theuser,sizeof(theuser));

userf.close();

break;

userf.close();

tweetfavail=1; hastweets=1; //Set 1 cause now we have at


least one tweet

gotoxy(1,MAXY);

2
cout<<" || *** Tweet Saved Successfully ***
||";

gotoxy(2,8);

while(!kbhit()){}

puttext(1,1,80,MAXY,fscreenbuf); //Put full screen

gotoxy(2,8);

return 7;

else

_setcursortype(_NOCURSOR);

gotoxy(1,MAXY);

cout<<"** You didn\'t selected any option or Entered a Tweet


** \r";

while(!kbhit()){}

puttext(1,1,80,MAXY,fscreenbuf); //Put full screen

gotoxy(2,8);

_setcursortype(_NORMALCURSOR);

return 7;

2
}

/*******************************/

/*Function to view tweets*/

int viewtweets() //Return value may not be used, its just to escape

tweets thetweet;

ifstream tweetf;

ofstream temptweetf;

int counter,keypress;

int spaceneeded;

int haveroom;

long pos=0;

textbackground(2);

_setcursortype(_NOCURSOR); //Hide cursor for now

puttext(1,1,80,MAXY,fscreenbuf);

gotoxy(1,MAXY);

cout<<" || Press "<<uparrow<<" To scroll up | Press


"<<downarrow<<" To scroll down | Press ESC to go back ||";

window(2,12,79,MAXY-2);

textbackground(2);

2
clrscr();

tweetf.open("tweets.sam",ios::in|ios::binary);

temptweetf.open("~temptf.sam",ios::out|ios::binary);

while(!tweetf.eof())

tweetf.read((char*)&thetweet,sizeof(thetweet));

for(counter=0;counter<=loggedinfollows;counter++)

if((strcmp(thetweet.tuser,followlist[counter])==0)||
(strcmp(thetweet.tuser,logedinuser)==0))

//Above statement is to check whether he

//Or people he follow has any tweets if

//he has save it in temp file, so it could

//be used for scrolling easily

temptweetf.write((char*)&thetweet,sizeof(thetweet));

break;

tweetf.close();

temptweetf.close();

2
counter=0;

tweetf.open("~temptf.sam",ios::in|ios::binary|ios::nocreate);

//Using tweetf bcoz it is a input stream

//obviously it makes sense to use what we already have

while(!tweetf.eof())

tweetf.seekg(pos);

tweetf.read((char*)&thetweet,sizeof(thetweet));

if (strlen(thetweet.tweet)<78) {spaceneeded=2;}

if (strlen(thetweet.tweet)<154) {spaceneeded=3;}

if (strlen(thetweet.tweet)<234) {spaceneeded=4;}

if (wherey()<((MAXY-11)-spaceneeded)) {haveroom=1;}

else {haveroom=0;}

if (haveroom==0)

while(1)

while(!kbhit()){} //wait for him to press a key

keypress=getch();

if(keypress==ESC)

2
window(1,1,80,MAXY);

puttext(1,1,80,MAXY,fscreenbuf); //Put full screen

_setcursortype(_NORMALCURSOR); //Reset Cursor

tweetf.close();

remove("~temptf.sam"); //Get rid of file

gotoxy(2,8);

return (0);

if(keypress==UP)

if(pos>0) //if we are not already in begining of file

clrscr();

gotoxy(1,1); //here 1,1 is relative to current window

pos-=(sizeof(thetweet)*counter);

counter=0;

break;

if(keypress==DN)

2
if(!tweetf.eof())

cprintf("Date:%d/%d/%d Time:%2d:%02d:%02d By:%s\r\n


%s\n\r\n",thetweet.tdate.da_day,thetweet.tdate.da_mon,thetweet.
tdate.da_year,thetweet.ttime.ti_hour,thetweet.ttime.ti_min,thetwe
et.ttime.ti_sec,thetweet.tuser,thetweet.tweet);

pos+=sizeof(thetweet);

counter++;

tweetf.read((char*)&thetweet,sizeof(thetweet));

if(!tweetf.eof()){break;}

else

cprintf("Date:%d/%d/%d Time:%2d:%02d:%02d By:%s\r\n


%s\n\r\n",thetweet.tdate.da_day,thetweet.tdate.da_mon,thetweet.
tdate.da_year,thetweet.ttime.ti_hour,thetweet.ttime.ti_min,thetwe
et.ttime.ti_sec,thetweet.tuser,thetweet.tweet);

pos+=sizeof(thetweet);

counter++;

2
}

window(1,1,80,MAXY); //Reset text window

while(1)

while(!kbhit()){}

keypress=getch();

if(keypress==ESC)

puttext(1,1,80,MAXY,fscreenbuf); //Put full screen

_setcursortype(_NORMALCURSOR); //Reset Cursor

tweetf.close();

remove("~temptf.sam");

gotoxy(2,8);

return (0);

/*******************************/

2
/*Function to view users and follow them*/

void follow()

int keypress;

tuser theuser;

tfollow thefollow;

fstream userf;

ofstream followf;

long pos=0;

int found=0,success=0;

gotoxy(1,MAXY);

cout<<" || Enter the Name of the User you want to follow |


Press ESC to exit ||";

textbackground(2);

window(2,8,79,10);

clrscr(); //Clear tweet area;

window(2,12,79,MAXY-2);

clrscr(); //Output area

userf.open("userf.sam",ios::in|ios::out|ios::binary);

int x=5,y=2,ct=0;

userf.seekg(pos);

2
userf.read((char*)&theuser,sizeof(theuser));

while(!userf.eof()) //first show all the users

if(ct<5)

gotoxy(x,y);

x+=15; ct++;

else

x=5;

gotoxy(x,++y);

ct=0;

cprintf("%s",theuser.tusername);

userf.read((char*)&theuser,sizeof(theuser));

userf.close();

window(1,1,80,MAXY); //reset text window to full screen

gotoxy(2,8);

ct=0; //initilize counter to zero so we can reuse it

2
while(1)

while(!kbhit()){}

keypress=getche();

if(keypress==ESC)

break;

else

ungetch(keypress); //So that it it taken next time

window(2,8,79,10); //clear only tweet area

textbackground(2);

clrscr();

window(1,1,80,MAXY); //reset the screen

gotoxy(2,8);

cout<<"Enter Username:";

getmysizetext(12); //Get user name

userf.open("userf.sam",ios::in|ios::out|ios::binary);

userf.read((char*)&theuser,sizeof(theuser));

while(!userf.eof())

2
{

if(strcmp(mysizetext,theuser.tusername)==0) //first we find


that such a user

exist or not

found=1;

break;

else

found=0;

userf.read((char*)&theuser,sizeof(theuser));

if(found==1)

userf.seekg(0);

userf.read((char*)&theuser,sizeof(theuser));

pos=userf.tellg();

while(!userf.eof())

2
if(strcmp(logedinuser,theuser.tusername)==0) //then we find
logedin user

account and update it

theuser.nfollows++;

loggedinfollows=theuser.nfollows; //update number of


followers

userf.seekg(pos-sizeof(theuser));

userf.write((char*)&theuser,sizeof(theuser));

userf.close();

followf.open("tfollow.sam",ios::out|ios::app|ios::binary|
ios::ate);

//Open to update the follow details

strcpy(thefollow.user1,logedinuser);

strcpy(thefollow.user2,mysizetext);

followf.write((char*)&thefollow,sizeof(thefollow));

followf.close();

success=1;

break;

else

2
success=0;

userf.read((char*)&theuser,sizeof(theuser));

pos=userf.tellg();

else

userf.close();

gotoxy(1,MAXY);

cout<<" || Entered User Name does not Exist | Use


One of the above ||";

gotoxy(2,8); //We dont want the user to see cursor in status bar
while he sees the status

while(!kbhit()) {}

gotoxy(1,MAXY);

cout<<" || Enter the Name of the User you want to follow |


Press ESC to exit ||";

gotoxy(2,8);

if(success==1)

2
userf.close();

gotoxy(1,MAXY);

cout<<" \r";

cout<<" || Update saved Successfully | You


Follow:"<<mysizetext;

gotoxy(78,MAXY);

cout<<"||";

gotoxy(2,8); //We dont want the user to see cursor in status bar
while he sees the status

while(!kbhit()) {}

gotoxy(1,MAXY);

cout<<" || Enter the Name of the User you want to follow |


Press ESC to exit ||";

gotoxy(2,8);

puttext(1,1,80,MAXY,fscreenbuf);

gotoxy(2,8);

/*******************************/

2
/*Function to show list of users he follow*/

void pifollow()

const int i=loggedinfollows;

int j,ch,x=5,y=2,ct=0;

populatelist();

gotoxy(1,MAXY);

if(i==0)

puttext(1,1,80,MAXY,fscreenbuf);

cout<<" || ** You Dont Follow any one yet ** | Follow


Someone ||";

gotoxy(2,8);

while(!kbhit()){}

else

_setcursortype(_NOCURSOR);

2
cout<<" || Above is the List of People you are following | Press
ESC to exit ||";

window(2,12,79,MAXY-2);

textbackground(2);

clrscr();

for(j=0;j<i;j++)

if(ct<5)

gotoxy(x,y);

x+=15; ct++;

else

x=5;

gotoxy(x,++y);

ct=0;

cprintf("%s",followlist[j]);

while(1)

2
while(!kbhit()){}

ch=getch();

if(ch==ESC)

break;

window(1,1,80,MAXY);

puttext(1,1,80,MAXY,fscreenbuf);

_setcursortype(_NORMALCURSOR);

gotoxy(2,8);

/*******************************/

void main()

textmode(C80);//Set mode to 80 column

startsoft(); //Start the software

getch();

2
RAJ.H
#include<io.h>

#include<conio.h>

#include<dos.h>

#include<fstream.h>

#include<stdio.h>

#include<string.h>

#include<fcntl.h>

#include<process.h>

/*Created on 1/21/2010

Last Modified on 3:05 AM 1/29/2010

Colors for mycolorscreen(color1 color2)

0 Black yes yes

1 Blue yes yes

2 Green yes yes

3 Cyan yes yes

4 Red yes yes

5 Magenta yes yes

2
6 Brown yes yes

7 Light Gray yes yes

8 Dark Gray no yes

9 Light Blue no yes

10 Light Green no yes

11 Light Cyan no yes

12 Light Red no yes

13 Light Magenta no yes

14 Yellow no yes

15 White no yes

Files Used:

userf.sam

tfollow.sam

tweets.sam

Functions: */

int homedisplay();

void mycolorscreen(int color1, int color2);

void createbox(int x1,int y1,int x2,int y2,int color1);

void getpassword();

void loginbox();

void getmysizetext(int size);

2
void initialize();

void newaccbox();

int populatelist();

void startsoft();

void loggedinscreen();

int whathedid();

int viewtweets();

void follow();

void pifollow();

void deleteacc();

void about();

/********************************/

/* Global Variables and enums */

int userfavail=0;

int tweetfavail=0;

int followfavail=0;

int ux;

int uy;

int MAXY;

int loggedinfollows;

2
int hastweets;

char tbuf[960];

char fscreenbuf[8000];

char password[12];

char mysizetext[12];

char mytweet[234];

char logedinuser[12];

char followlist[100][12];

enum { UP = 72, DN = 80 , ESC = 27} direction;

unsigned char uparrow=24,downarrow=25;

/*******************************/

/*Project classes*/

class tuser

public:

char tusername[12];

char tpassword[12];

int nfollows;

int hastweet;

};

2
class tweets

public:

char tuser[12];

struct time ttime;

struct date tdate;

char tweet[234];

};

class tfollow

public:

char user1[12];

char user2[12];

};

/*******************************/

2
/*Function to color background*/

void mycolorscreen(int color1, int color2)

//I know i could have done this with graphic functions of

//graphics.h, but since my computer has Windows7

//so it don't work. So functions of conio.h do the way around

//Here i just tricked clrscr() to paint the screen with custom color

clrscr();

textbackground(color1);

textcolor(color2);

clrscr();

/*******************************/

/*Function to display homescreen */

int homedisplay()

int a,i,y1,y2,y3;

_setcursortype(_NOCURSOR);

struct text_info ti; //this code is just to make

2
gettextinfo(&ti); //sure this animation works

const MAX_Y=ti.screenheight; //works on every monitor

y1=MAX_Y/2;

i=(MAX_Y/2)-2;

y2=y1+1;

y3=y1+2;

while(i>0)

textcolor(4);

textbackground(0);

clrscr();

textbackground(3);

gotoxy(30,y1--);

cprintf(" ");

gotoxy(30,y2);

cprintf(" ");

textbackground(0);

gotoxy(38,y2--);

a=((i%2)*4);

textcolor(a);

cprintf("TWITTER");

2
textbackground(3);

cprintf(" ");

gotoxy(30,y3--);

cprintf(" ");

i--;

// if(MAX_Y<43) //move slow if screen small

// delay(500);

// else

// delay(300);

gotoxy(29,2);

cprintf(" ");

gotoxy(29,6);

cprintf(" ");

gettext(1,1,80,6,tbuf); //Save Twitter home logo in buffer

textbackground(5);

y1=(MAX_Y/2)+5;

gotoxy(29,y1++);

cprintf(" ");

gotoxy(29,y1);

cprintf(" ");

2
cout<<" Enter yor Choice";

gotoxy(53,y1++);

cprintf(" ");

initialize(); //to initialize variables

if(userfavail==1)

gotoxy(29,y1);

cprintf(" ");

cout<<" 1: Login";

gotoxy(53,y1++);

cprintf(" ");

else

gotoxy(29,y1);

cprintf(" ");

cout<<"Can't Login No user yet";

gotoxy(53,y1++);

cprintf(" ");

gotoxy(29,y1);

2
cprintf(" ");

cout<<" 2: Create Account";

gotoxy(53,y1++);

cprintf(" ");

gotoxy(29,y1);

cprintf(" ");

cout<<" 3: Exit";

gotoxy(53,y1++);

cprintf(" ");

_setcursortype(_NORMALCURSOR);

while(1)

textbackground(5);

gotoxy(29,y1);

cprintf(" ");

gotoxy(42,y1);

cprintf(" ");

textbackground(0);

gotoxy(41,y1);

i=(int)getchar();

if(userfavail==1 && i==49)

2
break;

if(i>=50 && i<=51)

break;

mycolorscreen(0,15); //This just clears the screen

return (i-48);

/*******************************/

/*Function to create a box*/

void createbox(int x1,int y1,int x2,int y2,int color1=5)

int ix=x1;

int iy=y1;

if(!(x2<x1||y2<y1))

textbackground(color1);

for(;y1<=y2;y1++)

for(;x1<=x2;x1++)

2
if(y1==iy||x1==ix||y1==y2||x1==x2)

gotoxy(x1,y1);

cprintf(" ");

x1=ix;

gotoxy(ix+1,iy+1);

ux=ix+1; uy=iy+1;

/*******************************/

/*Function to write password character '*' */

void getpassword()

int a=0;

while(1)

password[a]=getch();

2
if(password[a]==8) //Check if Backspace was pressed

if(!(a==0))

a--;

cout<<"\b \b";

continue;

else

if(password[a]==13) //Check For Enter key

password[a]='\0';

break;

cout<<"*";

a++;

if(a>11)

2
a--;

cout<<"\b \b";

/*******************************/

/*Function to create a Login Box*/

void loginbox()

struct text_info ti; //this code is just to make

gettextinfo(&ti); //sure this works

const MAX_Y=ti.screenheight; //works on every monitor

puttext(1,1,80,6,tbuf); //Put Twitter home logo

createbox(29,(MAX_Y/2)+5,53,(MAX_Y/2)+9);

cout<<"Username: ";

createbox(29,(MAX_Y/2)+7,53,(MAX_Y/2)+7);

gotoxy(30,(MAX_Y/2)+8);

cout<<"Password: ";

gotoxy(40,(MAX_Y/2)+6);

ux=40; uy=(MAX_Y/2)+6;

2
}

/*******************************/

/*Function to create a new account Box*/

void newaccbox()

mycolorscreen(0,15);

puttext(1,1,80,6,tbuf); //Put Twitter home logo

createbox(25,(MAXY/2)+4,56,(MAXY/2)+12);

cout<<"Enter Details for New Account";

createbox(25,(MAXY/2)+6,56,(MAXY/2)+8);

cout<<"Username :";

gotoxy(26,(MAXY/2)+9);

cout<<"Password :";

createbox(25,(MAXY/2)+10,56,(MAXY/2)+12);

cout<<"Confirm Password:";

gotoxy(43,(MAXY/2)+7);

ux=43; uy=(MAXY/2)+7;

/*******************************/

2
/*Function to get custom sized text*/

void getmysizetext(int size)

int a=0,thex;

if(size<13)

while(1)

mysizetext[a]=getch();

if(mysizetext[a]==8) //Check if Backspace was pressed

if(!(a==0))

a--;

cout<<"\b \b";

continue;

else

2
{

if(mysizetext[a]==13) //Check For Enter key

mysizetext[a]='\0';

break;

cout<<mysizetext[a];

a++;

if(a>size)

a--;

cout<<"\b \b";

else

uy=wherey(); //Save current cursor y coordinate

while(1)

2
mytweet[a]=getch();

thex=wherex(); //save current cursor x coordinate

if(mytweet[a]==8) //Check if Backspace was pressed

if(!(a==0))

a--;

if(!(thex<3))

cout<<"\b \b";

else

gotoxy(79,--uy);

cout<<" \b";

continue;

else

if(mytweet[a]==13) //Check For Enter key

2
mytweet[a]='\0';

break;

if(thex<=79)

cout<<mytweet[a];

else

gotoxy(2,++uy);

cout<<mytweet[a];

a++;

if(a>size-1)

a--;

cout<<"\b \b";

/*******************************/

2
/*Function to initialize variables and check files*/

void initialize()

int handle;

handle=creatnew("userf.sam",0);

if(handle==-1)

handle=open("userf.sam",O_CREAT);

if((filelength(handle))<(sizeof(tuser))) //if file seems blank then


create a fresh one

close(handle); remove("userf.sam");

creatnew("userf.sam",0); close(handle);

userfavail=0;

else

userfavail=1;

else

close(handle);

2
userfavail=0;

handle=creatnew("tfollow.sam",0);

if(handle==-1)

handle=open("tfollow.sam",O_CREAT);

if((filelength(handle))<(sizeof(tfollow)))

//if file seems blank then create a fresh one

close(handle); remove("tfollow.sam");

creatnew("tfollow.sam",0); close(handle);

followfavail=0;

else

followfavail=1;

else

close(handle);

followfavail=0;

2
handle=creatnew("tweets.sam",0);

if(handle==-1)

handle=open("tweets.sam",O_CREAT);

if((filelength(handle))<(sizeof(tweets)))

//if file seems blank then create a fresh one

close(handle); remove("tweets.sam");

creatnew("tweets.sam",0); close(handle);

tweetfavail=0;

else

tweetfavail=1;

else

close(handle);

tweetfavail=0;

/*******************************/

2
/*Function to start this software*/

void startsoft()

int a;

struct text_info ti; //this code is just to make

gettextinfo(&ti); //sure this works

const MAX_Y=ti.screenheight; //works on every monitor

MAXY=MAX_Y;

home: //Label to come back to begining

a=homedisplay();

switch (a)

case 1:

ifstream userf;

tuser theuser;

int found=0;

while(1)

loginbox();

2
getmysizetext(12);

gotoxy(ux,uy+2);

getpassword();

userf.open("userf.sam",ios::in|ios::binary);

while(!userf.eof())

userf.read((char*)&theuser,sizeof(theuser));

if((strcmp(theuser.tusername,mysizetext)==0)&&(strcmp(theu
ser.tpassword,password)==0))

strcpy(logedinuser,theuser.tusername); // Set current loggedin


user

loggedinfollows=theuser.nfollows; //Set the number of people


he follow

hastweets=theuser.hastweet; //Set whether he has tweets

found=1;

userf.close();

break;

userf.close();

if(found==1)

2
break;

else

textcolor(15);

textbackground(0);

clrscr();

gotoxy(27,(MAX_Y/2)+4);

cout<<"Invalid Username or Password";

continue;

populatelist(); //Initialize follows list

loggedinscreen(); //draw the loggedin screen

tweetagain: //Used Label insted of recursion for


efficiency

getmysizetext(234); //get the tweet or option

int choice=whathedid(); //check what user did

if(choice==7||choice==1||choice==2||choice==3||choice==6)

goto tweetagain; //Go back to get tweet

if(choice==4||choice==5)

goto home; //Go back to start of the software

break;

2
}

case 2:

char pass1[12],pass2[12];

newaccbox();

while (1)

gotoxy(ux,uy);

getmysizetext(12);

gotoxy(ux,uy+=2);

getpassword();

strcpy(pass1,password);

gotoxy(ux,uy+=2);

getpassword();

strcpy(pass2,password);

if((strcmp(pass1,pass2))!=0)

textcolor(15); textbackground(0);

clrscr();

newaccbox();

gotoxy(26,(MAX_Y/2+5));

2
cout<<"Sorry Passwords do not match ";

else

ofstream ouserf;

tuser newuser;

strcpy(newuser.tusername,mysizetext);

strcpy(newuser.tpassword,password);

newuser.nfollows=0;

newuser.hastweet=0;

ouserf.open("userf.sam",ios::out|ios::app|ios::binary);

ouserf.write((char*)&newuser,sizeof(newuser));

ouserf.close();

_setcursortype(_NOCURSOR);

gotoxy(26,(MAX_Y/2)+5);

cout<<"Account Created Successfully ";

delay(2000);

_setcursortype(_NORMALCURSOR);

startsoft();

break;

2
}

break;

case 3:

exit (0);

/*******************************/

/*Function to create logged in screen*/

void loggedinscreen()

mycolorscreen(2,15);

puttext(1,1,80,6,tbuf); //Put buffered twitter logo

createbox(1,7,80,(MAXY-1),4);

createbox(2,11,79,11,4);

gotoxy(2,MAXY);

cout<<"** Enter Your tweet or simply enter the Number to select


an option **";

gotoxy(5,(MAXY/2)+3);

ux=wherex(); uy=wherey();//save current cursor positions

if(MAXY<43)

2
{

cout<<"1: View Tweets";

gotoxy(ux,uy+=1);

cout<<"2: Follow Someone";

gotoxy(ux,uy+=1);

cout<<"3: People You Follow";

gotoxy(ux,uy+=1);

cout<<"4: Logout";

gotoxy(ux,uy+=1);

cout<<"5: Delete your Account";

gotoxy(ux,uy+=1);

cout<<"6: About this Software";

else

gotoxy(ux,uy-=6);

cout<<"1: View Tweets";

gotoxy(ux,uy+=3);

cout<<"2: Follow Someone";

gotoxy(ux,uy+=3);

cout<<"3: People You Follow";

2
gotoxy(ux,uy+=3);

cout<<"4: Logout";

gotoxy(ux,uy+=3);

cout<<"5: Delete your Account";

gotoxy(ux,uy+=3);

cout<<"6: About this Software";

gotoxy(2,8);

gettext(1,1,80,MAXY,fscreenbuf); //Save full screen

/*******************************/

/*Function to delete your account*/

void deleteacc()

/*This function removes all entries of the */

/*user from every file */

ifstream userf,ffollow,ftweets;

ofstream utemp,ftemp,ttemp;

tuser theuser;

tweets thetweet;

2
tfollow thefollow;

_setcursortype(_NOCURSOR); //Hide Cursor

textbackground(2);

userf.open("userf.sam",ios::in|ios::binary);

utemp.open("utemp.sam",ios::out|ios::binary);

gotoxy(1,MAXY);

cprintf("|| [---] Account being deleted


\r");

delay(400);

cprintf("|| [ \\ ] Account being deleted


\r");

while(!userf.eof())

userf.read((char*)&theuser,sizeof(theuser));

if(!(strcmp(theuser.tusername,logedinuser)==0)&&(!
strcmp(theuser.tpassword,password)==0))

utemp.write((char*)&theuser,sizeof(theuser)); //Copy every


entry except logedin one

userf.close();

utemp.close();

2
cprintf("|| [ | ] Account being deleted
\r");

delay(400);

cprintf("|| [ / ] Deleting Follow


list \r");

ffollow.open("tfollow.sam",ios::in|ios::binary);

ftemp.open("ftemp.sam",ios::out|ios::binary);

while(!ffollow.eof())

ffollow.read((char*)&thefollow,sizeof(thefollow));

if(!(strcmp(thefollow.user1,logedinuser)==0))

ftemp.write((char*)&thefollow,sizeof(thefollow)); //Copy every


entry except logedin one

ffollow.close();

ftemp.close();

cprintf("|| [---] Deleting Follow


list \r");

delay(400);

cprintf("|| [ \\ ] Deleting Follow


list \r");

2
delay(400);

cprintf("|| [ | ] Deleting your Tweets


\r");

delay(400);

ftweets.open("tweets.sam",ios::in|ios::binary);

ttemp.open("ttemp.sam",ios::out|ios::binary);

while(!ftweets.eof())

ftweets.read((char*)&thetweet,sizeof(thetweet));

if(!strcmp(thetweet.tuser,logedinuser)==0)

ttemp.write((char*)&thetweet,sizeof(thetweet));

ftweets.close();

ttemp.close();

cprintf("|| [ / ] Deleting your Tweets


\r");

delay(400);

cprintf("|| [---] Deleting your Tweets


\r");

remove("userf.sam");

2
remove("tfollow.sam");

remove("tweets.sam");

rename("utemp.sam","userf.sam");

rename("ftemp.sam","tfollow.sam");

rename("ttemp.sam","tweets.sam");

puttext(1,1,80,MAXY,fscreenbuf); // Refresh screen

textbackground(4);

window(2,12,79,MAXY-2); //clears the output area cause buffer


had option text

clrscr();

gotoxy(1,(MAXY/2)-6); //goto a relative position in the screen

cprintf(" !!YOU DON\'T HAVE AN ACCOUNT!!\r\n");

cprintf(" CREATE A NEW ACCOUNT OR LOGIN WITH


ANOTHER ACCOUNT");

window(1,1,80,MAXY); //reset window

gotoxy(1,MAXY);

textbackground(2);

while(!kbhit())

cprintf("|| [ \\ ] Account Deleted Successfully | Press any key to


go back to Home \r");

delay(200);

2
cprintf("|| [ | ] Account Deleted Successfully | Press any key to
go back to Home \r");

delay(200);

cprintf("|| [ / ] Account Deleted Successfully | Press any key to


go back to Home \r");

delay(200);

cprintf("|| [---] Account Deleted Successfully | Press any key to


go back to Home \r");

delay(200);

getch();

_setcursortype(_NORMALCURSOR); //Reset Cursor

/*******************************/

/*************END OF CODE************/

2
RUNTIME SCREEN SHOTS

2
2
2
2
2
BIBLIOGRAPHY

 Algorithms in C by Robert Sedgewick, Princeton University. 1946 ISBN-0-201-


51245-7
 C++ The Complete Reference, Herb Schildt, ISBN 0-07-213293-0
 CodePlex - Open Source Project Hosting http://www.codeplex.com/
 Developers www.dev.com

You might also like