console notepad just doing some functions any one better than this ???

#ifndef ABC_C
#define ABC_C

#include<iostream>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
using namespace std;

struct CurPos
{
CurPos():xcordinate(-1),ycordinate(-1) {}
int xcordinate, ycordinate;
operator bool() const
{
return xcordinate >= 0 && ycordinate >= 0;
}
};

class cursor
{
private:
POINT p;
public:
cursor();
void gotoxy(int _x,int _y);
void curPos(int x, int y); //sets cursor position;
CurPos getCursorPos();
};


cursor :: cursor()
{

}

void cursor :: gotoxy(int _x, int _y)
{
HANDLE console_handle;
COORD cursor_coord;
cursor_coord.X=_x;
cursor_coord.Y=_y;
console_handle=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(console_handle,cursor_coord);
}


void curPos(int x, int y) //set console cursor
{
HANDLE hStdout;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
hStdout=GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hStdout, &csbiInfo);
csbiInfo.dwCursorPosition.X=x;
csbiInfo.dwCursorPosition.Y=y;
SetConsoleCursorPosition(hStdout, csbiInfo.dwCursorPosition);
}

CurPos cursor :: getCursorPos()
{
CurPos pos;
CONSOLE_SCREEN_BUFFER_INFO con;
HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
if (hcon != INVALID_HANDLE_VALUE &&
GetConsoleScreenBufferInfo(hcon,&con))
{
pos.xcordinate = con.dwCursorPosition.X;
pos.ycordinate = con.dwCursorPosition.Y;
}
return pos;
}


#endif
#ifndef ABC_Z
#define ABC_Z
#include <string>
#include <iostream>
#include "point.h"
using namespace std;
template <class Type>
struct Node
{
Type data;
Node<Type> *next;
Node<Type> *previous;
bool check;
};

template <class Type>
class action : public cursor
{
Node<Type> *start;
Node<Type> *last; // points to node at last position
int xcordinate ,ycordinate;
Node<Type> *temp1;
Node<Type> *temp;
cursor c;
public:
action();
~action();
void move_forword();
void move_back();
void UNDO_MOVE();
void REDO();
void paste();
void copy();
void insert (const Type & element);
void makeEmpty();
void DISPLAY();
void go_back();
void go_fwd();
Node<Type>* return_last();
bool remove (Node<Type>* to_delete);
bool isEmpty() const;
};


template <class Type>
void action<Type> :: go_back()
{
xcordinate=c.getCursorPos().xcordinate;
ycordinate=c.getCursorPos().ycordinate;
if(xcordinate!=0)
{
c.gotoxy(--xcordinate,ycordinate);
}
if(isEmpty()==false && return_last()->previous!=NULL)
move_back();
}

template <class Type>
void action<Type> :: go_fwd()
{
xcordinate=c.getCursorPos().xcordinate;
ycordinate=c.getCursorPos().ycordinate;
c.gotoxy(++xcordinate,ycordinate);
if(isEmpty()==false && return_last()->next!=NULL)
move_forword();
}

template <class Type>
action<Type>::action() : start(0), last(0)
{
}

template <class Type>
action<Type>::~action()
{
makeEmpty( );
}

template <class Type>
void action<Type>::insert(const Type& parameter) // O(1)
{
Node<Type>* node = new Node<Type>;
node->data = parameter;
node->next=NULL;
node->previous=NULL;
node->check=true;
if(start==NULL)
{
start=node;
last=node;
}
else if(last->next==NULL)
{
last->next=node;
node->previous=last;
last=node;
}
else if(last->next!=NULL && last->previous!=NULL)
{
Node<Type> *temp;
temp=last->next;
node->next=temp;
temp->previous=node;
node->previous=last;
last->next=node;
}
else if(last->previous==NULL && last->next!=NULL)
{
node->next=last;
node->previous=NULL;
last=node;
start=last;
}
}

template <class Type>
bool action<Type>::remove(Node<Type>* to_delete) // O(n)
{
Node<Type> *pre,*fwd;
if(to_delete->next==NULL && to_delete->previous!=NULL)
{
Node<Type> *temp;
temp=to_delete;
last=last->previous;
last->next=NULL;
temp->previous=NULL;
delete temp;
temp=NULL;
return true;
}
else if(to_delete->previous==NULL && to_delete->next==NULL)
{
delete last;
last=NULL;
start=NULL;
return true;
}
else
{
if(to_delete->previous==NULL && to_delete->next!=NULL)
{
Node<Type> *temp;
temp=to_delete;
start=start->next;
start->previous=NULL;
last=start;
delete temp;
temp=NULL;
to_delete=NULL;
return true;
}
Node<Type> *temp;
temp=to_delete;
pre=to_delete->previous;
fwd=to_delete->next;
last=last->previous;
temp->next=NULL;
temp->previous=NULL;
delete temp;
temp=NULL;
pre->next=fwd;
fwd->previous=pre;
return true;
}
}

template <class Type>
bool action<Type>::isEmpty() const // O(1)
{
return start == NULL;
}

template <class Type>
void action<Type>::makeEmpty() // O(n)
{
while (start)
{
last = start->next;
delete start;
start = last;
} }

template <class Type>
void action<Type> :: DISPLAY()
{
Node<Type> *temp;
temp=start;
while(temp!=NULL)
{
if(temp->check==true)
cout<< temp->data;
temp=temp->next;
}
}

template <class Type>
Node<Type>* action<Type> :: return_last()
{
return last;
}

template <class Type>
void action<Type> :: move_forword()
{
last=last->next;
}

template <class Type>
void action<Type> :: move_back()
{
last=last->previous;
}

template <class Type>
void action<Type> :: UNDO_MOVE()
{
Node<Type> *temp;
temp=return_last();
if(temp!=NULL)
{
temp=return_last();
temp->check=false;
move_back();
}
}

template <class Type>
void action<Type> :: REDO()
{
Node<Type> *temp;
temp=return_last();
if(temp==NULL)
{
last=start;
}
if(temp!=NULL)
{
if(temp->next!=NULL)
{
move_forword();
temp=return_last();
temp->check=true;
}
}
}

template <class Type>
void action<Type> :: copy() //copy selected text
{
int ch;
temp=return_last();
temp1=return_last();
move_back();
while(true)
{
ch=getch();
if(ch=='<')
{
go_back();
temp1=return_last();
}
else if(ch=='>')
{
go_fwd();
temp=return_last();
}
else
if(ch=='C')
{
break;
}
}
}

template <class Type>
void action<Type> :: paste() //SELECT TEXT THEN PASTE
{
while(temp1!=temp)
{
insert(temp1->data);
temp1=temp1->next;
}
insert(temp1->data);
}

#endif
#include <string>
#include<conio.h>
#include <iostream>
#include"point.h"
#include"aaction.h"
#include<Winuser.h>
using namespace std;

int main()
{
cout<<"SHIFT+C for copy\nSHIFT+P for paste\n SHIFT+< (copy text from left)\nSHIFT+> (copy text from right)\nSHIFT+Z for undo\nSHIFT+R for redo"<<endl;
int x=0,y=0;
bool check=false;;
char ch;
cursor CUR;
action <char> OBJ;
while(true)
{
ch=getch();
if(GetAsyncKeyState(VK_LEFT)) //MOVE CURSOR LEFT
{
x=CUR.getCursorPos().xcordinate;
y=CUR.getCursorPos().ycordinate;
if(x!=0)
{
CUR.gotoxy(--x,y);
}
if(!OBJ.isEmpty() && OBJ.return_last()->previous!=NULL)
OBJ.move_back();
check=false;
getch();
}
else if(GetAsyncKeyState(VK_RIGHT)) //MOVE CURSOR LEFT
{
x=CUR.getCursorPos().xcordinate;
y=CUR.getCursorPos().ycordinate;
CUR.gotoxy(++x,y);
if(!OBJ.isEmpty() && OBJ.return_last()->next!=NULL)
OBJ.move_forword();
check=false;
getch();
}
else if(ch==8) //BACK SPACE ASCII KEY
{
if(OBJ.return_last()!=NULL)
{
x=CUR.getCursorPos().xcordinate;
y=CUR.getCursorPos().ycordinate;
OBJ.remove(OBJ.return_last());
cout<<" ";
system("cls");
OBJ.DISPLAY();
CUR.gotoxy(--x,y);
x=CUR.getCursorPos().xcordinate;
y=CUR.getCursorPos().ycordinate;
check=true;
}
}
else if(ch=='Z')
{
OBJ.UNDO_MOVE();
system("cls");
OBJ.DISPLAY();
}
else if(ch=='R')
{
OBJ.REDO();
system("cls");
OBJ.DISPLAY();
}
else if(ch== '<' )
{
x=CUR.getCursorPos().xcordinate;
y=CUR.getCursorPos().ycordinate;
CUR.gotoxy(--x,y);
OBJ.copy();
}
else if(ch=='>')
{
x=CUR.getCursorPos().xcordinate;
y=CUR.getCursorPos().ycordinate;
CUR.gotoxy(++x,y);
OBJ.copy();
}
else if(ch=='P')
{
OBJ.paste();
system("cls");
OBJ.DISPLAY();
}
else
{
OBJ.insert(ch);
cout<<ch;
x=CUR.getCursorPos().xcordinate;
y=CUR.getCursorPos().ycordinate;
system("cls");
OBJ.DISPLAY();
if(OBJ.return_last()->next==NULL)
{
check=false;
}
else if(check==true)
{
CUR.gotoxy(--x,y);
}
else
{
CUR.gotoxy(x,y);
OBJ.move_forword();
}
}
}
system("pause");
return 0;
}
ohh i got emerged one :)




#ifndef ABC_Z
#define ABC_Z
#include <string>
#include <iostream>
//#include "point.h"
using namespace std;
template <class Type>
class Term
{
public:
Type data;
Term<Type> *next;
Term<Type> *previous;
bool verify;
};
template <class Type>
class operations : public Blinker
{
Term<Type> *head;
Term<Type> *end; // points to node at end position
int X , Y;
Term<Type> *pointer1;
Term<Type> *pointer2;
Blinker blinker_obj;
public:
operations();
~operations();
void new_node(const Type & element);
void going_next();
void going_previous();
void FUNC_undo();
void FUNC_redo();
void FUNC_paste();
void FUNC_copy();
void FUNC_print();
void FUNC_bckwrd();
void FUNC_frwrd();
Term<Type>* return_last();
bool deletion (Term<Type>* backspace);
bool _NULL_() const;
};
template <class Type>
void operations<Type> :: FUNC_bckwrd()
{
X = blinker_obj.final_position().X;
Y = blinker_obj.final_position().Y;
if( X != 0 )
blinker_obj.point_to(--X , Y);
if(_NULL_() == false )
if( return_last() -> previous != NULL )
going_previous();
}
template <class Type>
void operations<Type> :: FUNC_frwrd()
{
X = blinker_obj.final_position() .X;
Y = blinker_obj.final_position() .Y;
blinker_obj.point_to( ++X , Y );
if( _NULL_() == false )
if( return_last() -> next != NULL)
going_next();
}

template <class Type>
operations<Type>::operations()
{
head = 0;
end = 0;
}

template <class Type>
operations<Type> :: ~operations()
{
end = head->next;
while(head)
delete end;
head = end = NULL;
}

template <class Type>
void operations<Type> :: new_node( const Type& type_obj )
{
Term<Type>* node = new Term<Type>;
node -> data = type_obj;
node -> next = NULL;
node -> previous = NULL;
node -> verify = true;
if(head == NULL)
{
head = node;
end = node;
}
else if( end -> next == NULL )
{
end -> next = node;
node -> previous = end;
end = node;
}
else if( end -> next != NULL )
{
if( end -> previous != NULL )
{
Term<Type> *pointer2;
pointer2 = end->next;
node -> next = pointer2;
pointer2 -> previous = node;
node -> previous = end;
end -> next = node;
}
}
else if( end -> previous == NULL )
{

if( end -> next != NULL )
{
node -> next = end;
node -> previous = NULL;
end = node;
head = end;
}
}
}

template <class Type>
bool operations<Type> :: deletion( Term<Type>* backspace ) // O(n)
{
Term<Type> *pointer3,*pointer4;
if( backspace->next == NULL )
{
if( backspace -> previous != NULL )
{
Term<Type> *pointer2;
pointer2 = backspace;
end = end -> previous;
end -> next = NULL;
pointer2 -> previous = NULL;
delete pointer2;
pointer2 = NULL;
return true;
}
}
else if( backspace -> previous == NULL )
{
if( backspace -> next == NULL )
{
delete end;
end=NULL;
head=NULL;
return true;
}
}
else
{
if( backspace -> previous == NULL )
{
if( backspace -> next != NULL )
{
Term<Type> *pointer2;
pointer2=backspace;
head=head->next;
head->previous=NULL;
end=head;
delete pointer2;
pointer2=NULL;
backspace=NULL;
return true;
}
}
Term<Type> *pointer2;
pointer2 = backspace;
pointer3 = backspace -> previous;
pointer4 = backspace -> next;
end = end -> previous;
pointer2 -> next = NULL;
pointer2 -> previous = NULL;
delete pointer2;
pointer2 = NULL;
pointer3 -> next = pointer4;
pointer4 -> previous = pointer3;
return true;
}
}

template <class Type>
bool operations<Type>::_NULL_() const // O(1)
{
return head == NULL;
}

template <class Type>
void operations<Type> :: FUNC_print()
{
Term<Type> *pointer2;
pointer2 = head;
while( pointer2 != NULL )
{
if( pointer2 -> verify == true )
cout<< pointer2 -> data;
pointer2 = pointer2 -> next;
}
}

template <class Type>
Term<Type>* operations<Type> :: return_last()
{
return end;
}

template <class Type>
void operations<Type> :: going_next()
{
end=end->next;
}

template <class Type>
void operations<Type> :: going_previous()
{
end=end->previous;
}

template <class Type>
void operations<Type> :: FUNC_undo()
{
Term<Type> *pointer2;
pointer2 = return_last();
if(pointer2 != NULL)
{
pointer2 = return_last();
pointer2 -> verify = false;
going_previous();
}
}

template <class Type>
void operations<Type> :: FUNC_redo()
{
Term<Type> *pointer2;
pointer2 = return_last();
if(pointer2 == NULL)
{
end=head;
}
if(pointer2 != NULL)
{
if( pointer2 -> next != NULL )
{
going_next();
pointer2 = return_last();
pointer2 -> verify = true;
}
}
}

template <class Type>
void operations<Type> :: FUNC_copy()
//FUNC_copy selected text
{
int input;
pointer2 = return_last();
pointer1 = return_last();
going_previous();
while( !false )
{
input = getch();
if( input == '<' )
{
FUNC_bckwrd() ;
pointer1 = return_last();
}
else if( input == 'C' )
break;
}
}
template <class Type>
void operations<Type> :: FUNC_paste(){
while( pointer1 != pointer2 )
{
new_node( pointer1 -> data );
pointer1 = pointer1 -> next;
}
new_node( pointer1 -> data );
}

#endif
n what about compressed one :D


#ifndef ABC_C
#define ABC_C
#ifndef ABC_Z
#define ABC_Z
#include <iostream>
#include <string>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
using namespace std;
class Where_To_Blink{
public:
int X, Y; //Declaring variables for handling X Y coordinates of the Curser
Where_To_Blink(); //Constructor
operator bool() const;
};
Where_To_Blink::Where_To_Blink(){
X = -1;
Y = -1; //
}
Where_To_Blink::operator bool() const
{ return X >= 0 && Y >= 0; }
class Blinker
{
public:
void point_to(int x,int y);
void setting_blinker(int x, int y); //sets Blinker position;
Where_To_Blink final_position();
};
void Blinker :: point_to(int x, int y)
{
HANDLE handling;
COORD coordinations;
coordinations .X = x;
coordinations .Y = y;
handling = GetStdHandle( STD_OUTPUT_HANDLE );
SetConsoleCursorPosition ( handling , coordinations );
}
void setting_blinker(int x, int y) //set console Blinker
{
HANDLE handling2;
CONSOLE_SCREEN_BUFFER_INFO contrl_position;
handling2=GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(handling2, &contrl_position);
contrl_position .dwCursorPosition .X = x;
contrl_position .dwCursorPosition .Y = y;
SetConsoleCursorPosition(handling2, contrl_position.dwCursorPosition);
}
Where_To_Blink Blinker :: final_position()
{
Where_To_Blink positioning;
CONSOLE_SCREEN_BUFFER_INFO controling;
HANDLE hndle_csbi = GetStdHandle(STD_OUTPUT_HANDLE);
if (hndle_csbi != INVALID_HANDLE_VALUE &&GetConsoleScreenBufferInfo(hndle_csbi,&controling))
{
positioning.X = controling.dwCursorPosition.X;
positioning.Y = controling.dwCursorPosition.Y;
}
return positioning;
}
template <class Type>
class Term
{
public:
Type data;
Term<Type> *next;
Term<Type> *previous;
bool verify;
};
template <class Type>
class operations : public Blinker
{
public:
Term<Type> *end,*head;
operations();
~operations();
void new_node(Type & element);
void FUNC_copy();
void FUNC_paste();
void FUNC_print();
void FUNC_bckwrd();
void FUNC_frwrd();
bool deletion(Term<Type>* backspace);
bool _NULL_()const;
private:
Term<Type> *pointer1;
Term<Type> *pointer2;
Blinker blinker_obj;
int A , B;
};
template <class Type>
void operations<Type> :: FUNC_bckwrd()
{
A = blinker_obj.final_position().X;
B = blinker_obj.final_position().Y;
if( A != 0 )
blinker_obj.point_to(--A , B);
if(_NULL_() == false )
if( end -> previous != NULL )
end = end -> previous;
}
template <class Type>
operations<Type>::operations()
{
head = 0;
end = 0;
}
template <class Type>
operations<Type> :: ~operations()
{
end = head->next;
while(head)
delete end;
head = end = NULL;
}
template <class Type>
void operations<Type> :: new_node( Type& type_obj )
{
Term<Type>* node = new Term<Type>;
node -> data = type_obj;
node -> next = NULL;
node -> previous = NULL;
node -> verify = true;
if(head == NULL)
{
head = node;
end = node;
}
else if( end -> next == NULL )
{
end -> next = node;
node -> previous = end;
end = node;
}
else if( end -> next != NULL )
{
if( end -> previous != NULL )
{
Term<Type> *pointer2;
pointer2 = end->next;
node -> next = pointer2;
pointer2 -> previous = node;
node -> previous = end;
end -> next = node;
}
}
else if( end -> previous == NULL )
{

if( end -> next != NULL )
{
node -> next = end;
node -> previous = NULL;
end = node;
head = end;
}
}
}
template <class Type>
bool operations<Type> :: deletion( Term<Type>* backspace ) // O(n)
{
Term<Type> *pointer3,*pointer4;
if( backspace->next == NULL )
{
if( backspace -> previous != NULL )
{
Term<Type> *pointer2;
pointer2 = backspace;
end = end -> previous;
end -> next = NULL;
pointer2 -> previous = NULL;
delete pointer2;
pointer2 = NULL;
return true;
}
}
else if( backspace -> previous == NULL )
{
if( backspace -> next == NULL )
{
delete end;
end=NULL;
head=NULL;
return true;
}
}
else
{
if( backspace -> previous == NULL )
{
if( backspace -> next != NULL )
{
Term<Type> *pointer2;
pointer2=backspace;
head=head->next;
head->previous=NULL;
end=head;
delete pointer2;
pointer2=NULL;
backspace=NULL;
return true;
}
}
Term<Type> *pointer2;
pointer2 = backspace;
pointer3 = backspace -> previous;
pointer4 = backspace -> next;
end = end -> previous;
pointer2 -> next = NULL;
pointer2 -> previous = NULL;
delete pointer2;
pointer2 = NULL;
pointer3 -> next = pointer4;
pointer4 -> previous = pointer3;
return true;
}
}
template <class Type>
bool operations<Type>::_NULL_() const
{ return (*this).head == NULL; }
template <class Type>
void operations<Type> :: FUNC_print()
{
Term<Type> *pointer2;
pointer2 = head;
while( pointer2 != NULL )
{
if( pointer2 -> verify == true )
cout<< pointer2 -> data;
pointer2 = pointer2 -> next;
}
}
template <class Type>
void operations<Type> :: FUNC_copy()
//FUNC_copy selected text
{
int input;
pointer2 = end;
pointer1 = end;
end = end -> previous;
while( !false )
{
input = getch();
if( input == 'B' )
{
FUNC_bckwrd() ;
pointer1 = end;
}
else if( input == 'C' )
break;
}
}
template<class Type>
void operations<Type> :: FUNC_paste(){
while( pointer1 != pointer2 )
{
new_node( pointer1 -> data );
pointer1 = pointer1 -> next;
}
new_node( pointer1 -> data );
}
void systemCLS()
{
cout<<" ";
system("cls");
}
int main()
{
int x = 0,y = 0;
bool verify = false;
char input;
Blinker blinkr_objct;
operations <char> pro_object;
input = getch();
while( !false )
{
if( GetAsyncKeyState ( VK_LEFT ) )
{
x = blinkr_objct .final_position() .X;
y = blinkr_objct .final_position() .Y;
if( x != 0 )
blinkr_objct .point_to ( --x , y );
if( !pro_object ._NULL_() )
if( pro_object .end -> previous != NULL )
pro_object.end = pro_object.end -> previous;
verify = false;
getch();
}
else if( GetAsyncKeyState(VK_RIGHT) )
{
x = blinkr_objct .final_position() .X;
y = blinkr_objct .final_position() .Y;
blinkr_objct .point_to( ++x , y );
if(!pro_object ._NULL_() )
if( pro_object .end -> next != NULL)
pro_object.end = pro_object.end->next;
verify = false;
getch();
}
else if( input == '◘' )
{
if( pro_object.end != NULL )
{
x = blinkr_objct .final_position() .X;
y = blinkr_objct .final_position() .Y;
pro_object .deletion ( pro_object.end);
systemCLS();
pro_object .FUNC_print();
blinkr_objct.point_to(--x,y);
x=blinkr_objct.final_position().X;
y=blinkr_objct.final_position().Y;
verify=true;
}
}
else if(input == 'B' )
{
x=blinkr_objct.final_position().X;
y=blinkr_objct.final_position().Y;
blinkr_objct.point_to(--x,y);
pro_object.FUNC_copy();
}
else if(input == 'P')
{
pro_object.FUNC_paste();
systemCLS();
pro_object.FUNC_print();
}
else
{
pro_object.new_node(input);
cout<<input;
x=blinkr_objct.final_position().X;
y=blinkr_objct.final_position().Y;
systemCLS();
pro_object.FUNC_print();
if(pro_object.end->next==NULL)
verify=false;
else if(verify==true)
blinkr_objct.point_to(--x,y);
else
{
blinkr_objct .point_to( x , y );
pro_object.end = pro_object.end->next ;
}
}
input = getch();
}
system("pause");
return 0;
}
#endif
#endif
Topic archived. No new replies allowed.