Commit b33614cc authored by varshiths's avatar varshiths

First and probably everything

parents
File added
void Dialog::rectAlloc(Rectangle rec){
r[m] = new Rectangle;
*r[m] = rec;
m++;
}
void Dialog::textAlloc(Text txt){
t[k] = new Text;
*t[k] = txt;
k++;
}
void Dialog::circAlloc(Circle cir){
c[i] = new Circle;
*c[i] = cir;
i++;
}
void Dialog::lineAlloc(Line lin){
l[j] = new Line;
*l[j] = lin;
j++;
}
void Dialog::click(){
Point e; e.read();
if(e.inRect(Paint)){
cout << "Opening Paint" << endl;// ob correspoinding to app
paint xyz;
}
else if(e.inRect(PolyPr)){
cout << "Opening PolyProcessor" << endl;// ob correspoinding to app
polyui pui;
}
else if(e.inRect(TextPr)){
cout << "Opening TextProcessor" << endl;// ob correspoinding to app
tcui tpx;
}
else if( e.inCircle(exitb) ){
readytostay=false;
}
}
Dialog::Dialog(double l,double m){
w = l; h = m;
float wd=3*w/4; float hd=2*h/3; // window dimensions
for(int i=0; i<rln; i++){ // animation
Rectangle d( w/8 + wd/2 , h + ( hd/2-5*h/6 )*(i/rln), (i/rln)*wd, (i/rln)*hd );
d.setColor(COLOR(230,228,227)); d.setFill();
Rectangle doutline( w/8 + wd/2 , h + ( hd/2-5*h/6 )*(i/rln), (i/rln)*wd, (i/rln)*hd );
rptr[rpr] = new Rectangle; rptr[rpr+irln] = new Rectangle;
*rptr[rpr] = d; *rptr[rpr+irln] = doutline; rpr++; // rpr-1 points to the last rectangle
if(i!=rln-1){
delete rptr[i];
delete rptr[i+irln];
}
//wait(1.0/rln);
}
double r=h/20; // radius of exit button
exitb.init(w-r-10,r+10,r); exitb.setColor(COLOR(243,81,79)); exitb.setFill(); // Exit from dialog
circAlloc(exitb);
// links to apps
Paint.init( w/2, h/2-hd/3+10 , wd-20, hd/3-10);
Text painttxt( w/2, h/2-hd/3+10 , "Paint");
PolyPr.init( w/2, h/2 , wd-20, hd/3-10);
Text polytxt( w/2, h/2 , "Polynomial Processor");
TextPr.init( w/2, h/2+hd/3-10, wd-20, hd/3-10);
Text textprtxt(w/2, h/2+hd/3-10 , "Text Processor");
Line paintpoly(w/2-wd/2+20,h/2-hd/6, w/2+wd/2-20, h/2-hd/6);
Line polytext(w/2-wd/2+20,h/2+hd/6, w/2+wd/2-20, h/2+hd/6);
cout << "Opening Dialog Box." << endl;
while(readytostay){
click();
}
}
Dialog::~Dialog(){
cout << "Closing Dialog Box." << endl;
for(int x = 0;x<m;x++)
delete r[x];
for(int x = 0;x<i;x++)
delete c[x];
for(int x = 0;x<j;x++)
delete l[x];
for(int x = 0;x<k;x++)
delete t[x];
delete rptr[rpr-1];
delete rptr[rpr+irln-1];
}
class Dialog{
double w = 800, h = 600, rln=50; int irln=rln; // size and resolution
Rectangle * rptr[200];
int rpr=0;
float wd=3*w/4; float hd=2*h/3;
int i=0,j=0,k=0,m=0; //pointers to the graphic objects created
Circle* c[10];
Line* l[10];
Text* t[10];
Rectangle* r[100];
Rectangle Paint, TextPr, PolyPr;
Circle exitb;
bool readytostay=true;
public:
Dialog(double l, double m);
void click();
void rectAlloc(Rectangle rec);
void circAlloc(Circle cir);
void lineAlloc(Line lin);
void textAlloc(Text txt);
~Dialog();
};
#include <simplecpp>
#include <fstream>
#include <string>
#include <cmath>
#include "tcui.h"
#include "polynomial.h"
#include "dialog.h"
#include "point.h"
#include "paint.h"
#include "lay.h"
#include "polyui.h"
#include "tstring.h"
#include "tcui.cpp"
#include "polynomial.cpp"
#include "dialog.cpp"
#include "point.cpp"
#include "paint.cpp"
#include "lay.cpp"
#include "polyui.cpp"
#include "tstring.cpp"
void initGUI(){
double w=800, h=600; // resolution and screen size
initCanvas("XGen",w,h);
int ires=100; // shaded background
Rectangle back[2*ires];
double res=ires;
for(int i=0; i<res; i++){
back[i+ires].init(w/2,h/2+(h/(2*res))/2+(h/(2*res))*i,w,h/(2*res));
back[i+ires].setColor(COLOR(162+(93.0/res)*i,220+(35.0/res)*i,255));
back[i+ires].setFill(true);
back[i].init(w/2,h/2-(h/(2*res))/2-(h/(2*res))*i,w,h/(2*res));
back[i].setColor(COLOR(162+(93.0/res)*i,220+(35.0/res)*i,255));
back[i].setFill(true);
}
// x on the background
const float pi=3.1415; float tilt=pi/6; float lb=300; float hshift = h/20; // position of x from the centre
Rectangle xb(w/2,h/2 - hshift,lb,10); xb.setColor(COLOR(255,255,255));xb.setFill();
xb.rotate(tilt);
Rectangle xc(w/2,h/2 - hshift,lb,10); xc.setColor(COLOR(255,255,255)); xc.setFill();
xc.rotate(-tilt);
float bl = w/2 - (lb/2)* cos(pi/6);
Rectangle xrt( w/2 + w/4 + cos(pi/6)*lb/4 , h/2 - sin(pi/6)*lb/2 - hshift, bl + 5*cos(pi/3) ,10);
xrt.setColor(COLOR(255,255,255)); xrt.setFill();
Rectangle xrb( w/2 + w/4 + cos(pi/6)*lb/4 , h/2 + sin(pi/6)*lb/2 - hshift, bl + 5*cos(pi/3) ,10);
xrb.setColor(COLOR(255,255,255)); xrb.setFill();
Rectangle xlt( w/4 - cos(pi/6)*lb/4 , h/2 - sin(pi/6)*lb/2 - hshift, bl + 10*cos(pi/3) ,10);
xlt.setColor(COLOR(255,255,255)); xlt.setFill();
Rectangle xlb( w/4 - cos(pi/6)*lb/4 , h/2 + sin(pi/6)*lb/2 - hshift, bl + 10*cos(pi/3) ,10);
xlb.setColor(COLOR(255,255,255)); xlb.setFill();
int it=25; // task bar
Rectangle tk[2*it];
double t=it, ht=h/12.5;
for(int i=0; i<t; i++){
tk[i+it].init(w/2,h-ht/2+(ht/(2*t))/2+(ht/(2*t))*i,w,ht/(2*t));
tk[i+it].setColor(COLOR(0,0,0));
tk[i+it].setFill(true);
tk[i].init(w/2,h-ht/2-(ht/(2*t))/2-(ht/(2*t))*i,w,ht/(2*t));
tk[i].setColor(COLOR(65+(60.0/t)*i,65+(60.0/t)*i,65+(60.0/t)*i));
tk[i].setFill(true);
}
// home button on the task bar
int ic=100;
Circle home[ic];
double c=ic, r=h/15;
int start=35;
for(int i=0; i<start; i++){
home[i].init(w/2,h-h/30,r-(r/c)*i);
home[i].setColor(COLOR(40+(80.0/start)*i,40+(80.0/start)*i,40+(80.0/start)*i));
}
for(int i=start; i<c; i++){
home[i].init(w/2,h-h/30,r-(r/c)*i);
home[i].setColor(COLOR(170+(240-170)*(i/c),(80/c)*i,(80/c)*i)); home[i].setFill(true);
}
// exiting the main ui
r=h/20; // setting r to the size of exitui button
Circle exitui(w-r-10,r+10,r); exitui.setColor(COLOR(243,81,79)); exitui.setFill();
Circle olexitui(w-r-10,r+10,r);
cout << "Welcome to Halcyon." << endl;
while(true){
Point t;
t.read();
if(t.inCircle(home[0])) { //Dialog Box
Dialog dg(w,h);
}
if(t.inCircle(exitui)) { cout << "Thank You." << endl; break; }
}
}
void initGUI();
#include "headers.h"
int main(){
initGUI();
}
void paint::rectAlloc(Rectangle rec){
r[m] = new Rectangle;
*r[m] = rec;
m++;
}
void paint::textAlloc(Text txt){
t[k] = new Text;
*t[k] = txt;
k++;
}
void paint::circAlloc(Circle cir){
c[i] = new Circle;
*c[i] = cir;
i++;
}
void paint::lineAlloc(Line lin){
l[j] = new Line;
*l[j] = lin;
j++;
}
paint::paint(){ //paint layout
w = 800,h = 600,n = 3; b=true;
//app bounds
double wp = (7*w)/8,hp = (5*h)/6;
rm.init(w/2,h/2,(7*w)/8,(5*h)/6); Rectangle rmoutl(w/2,h/2,(7*w)/8,(5*h)/6);
rm.setColor(COLOR(230,228,227));rm.setFill();
rectAlloc(rm); rectAlloc(rmoutl);
//app task bar
int it=25;
Rectangle tk[2*it];
double t=it, ht=h/16;
for(int i=0; i<t; i++){
tk[i+it].init(w/2,((5*h)/96)+(ht/(2*t))/2+(ht/(2*t))*i,(7*w)/8,ht/(2*t));
tk[i+it].setColor(COLOR(0,0,0));
tk[i+it].setFill(true);
tk[i].init(w/2,((5*h)/96)-(ht/(2*t))/2-(ht/(2*t))*i,(7*w)/8,ht/(2*t));
tk[i].setColor(COLOR(65+(60.0/t)*i,65+(60.0/t)*i,65+(60.0/t)*i));
tk[i].setFill(true);
rectAlloc(tk[i]); rectAlloc(tk[i+it]);
}
//canvasBounds
double wc = wp - 20,hc = hp - 50;
rc.init(w/2,h/2 + 8,wc,hc); rc.setColor(COLOR("white")); rc.setFill();
rectAlloc(rc);
//exitButton
float rad = h/20; // setting r to the size of exitui button
exitui.init(w-rad-10,rad+10,rad); exitui.setColor(COLOR(243,81,79)); exitui.setFill();
Circle olexitui(w-rad-10,rad+10,rad); circAlloc(exitui); circAlloc(olexitui);
//LineButton
r1.init(w/16 + 10 + (wc)/(n+1)+24/2,h/12 + 10 +textHeight()/2,24+4,textHeight()+3); r1.setColor(COLOR(255,255,255)); r1.setFill();
Text t1(w/16 + 10 + (wc)/(n+1)+24/2,h/12 + 10 +textHeight()/2,"Line");
rectAlloc(r1); textAlloc(t1);
//CircleButton
r2.init(w/16 + 10 + 2*(wc)/(n+1)+36/2,h/12 + 10 +textHeight()/2,36+4,textHeight()+3); r2.setColor(COLOR(255,255,255)); r2.setFill();
Text t2(w/16 + 10 + 2*(wc)/(n+1)+36/2,h/12 + 10 +textHeight()/2,"Circle");
rectAlloc(r2); textAlloc(t2);
//RectangleButton
r3.init(w/16 + 10 + 3*(wc)/(n+1)+56/2,h/12 + 10 +textHeight()/2,56+4,textHeight()+3); r3.setColor(COLOR(255,255,255)); r3.setFill();
Text t3(w/16 + 10 + 3*(wc)/(n+1)+56/2,h/12 + 10 +textHeight()/2,"Rectangle");
rectAlloc(r3); textAlloc(t3);
cout << "Welcome to Paint." << endl;
while(b){
Point p; int a;
a = drawHelp(p);
if(a == 4){
b = false;
}
paintHelp(a);
}
}
int paint::drawLine(){
while(true) {
cout << "Line Command Active." << endl;
Point p,q; int a;
a = drawHelp(p);
if(a != 0){
return a;
break;
}
a = drawHelp(q);
if(a != 0){
return a;
break;
}
Line l1(p.getX(),p.getY(),q.getX(),q.getY());
lineAlloc(l1);
}
}
int paint::drawRectangle(){
cout << "Rectangle Command Active." << endl;
Point p,q; int a;
a = drawHelp(p);
if(a != 0){
return a;
}
a = drawHelp(q);
if(a != 0){
return a;
}
Rectangle r4((p.getX()+q.getX())/2,(p.getY()+q.getY())/2,abs(p.getX()-q.getX()),abs(p.getY()-q.getY()));
rectAlloc(r4);
return 5;
}
int paint::drawCircle(){
cout << "Circle Command Active." << endl;
Point p,q; int a;
a = drawHelp(p);
if(a != 0){
return a;
}
a = drawHelp(q);
if(a != 0){
return a;
}
Circle c1(p.getX(),p.getY(),p.dist(q));
circAlloc(c1);
return 5;
}
paint::~paint(){
cout << "Closing Paint." << endl;
for(int x = 0;x<m;x++)
delete r[x];
for(int x = 0;x<i;x++)
delete c[x];
for(int x = 0;x<j;x++)
delete l[x];
for(int x = 0;x<k;x++)
delete t[x];
}
int paint::drawHelp(Point &p){
p.read();
if(p.inRect(r1)){
return 1;
}
else if(p.inRect(r2)){
return 2;
}
else if(p.inRect(r3)){
return 3;
}
else if(p.inCircle(exitui)){
return 4;
}
else if(p.inRect(rc)){
return 0;
}
else return drawHelp(p);
}
int paint::paintHelp(int a){
if(a == 4){
b = false;
return 5;
}
else if(a == 1){
return(paintHelp(drawLine()));
}
else if(a == 2){
return(paintHelp(drawCircle()));
}
else if(a == 3){
return(paintHelp(drawRectangle()));
}
else return 5;
}
class paint{
float h,w,n;
int i=0,j=0,k=0,m=0; // pointers to the graphical objects created
Circle* c[20];
Line* l[40];
Text* t[10];
Rectangle* r[120];
Rectangle rm,rc,r1,r2,r3;
Circle exitui;
bool b;
public :
paint();
~paint();
int drawLine();
int drawCircle();
int drawRectangle();
void rectAlloc(Rectangle rec);
void circAlloc(Circle cir);
void lineAlloc(Line lin);
void textAlloc(Text txt);
int drawHelp(Point &p);
int paintHelp(int a);
};
void Point::read(){
int p=getClick();
int xi=p/65536; int yi=p%65536;
x=xi; y=yi;
}
Point::Point(){}
Point::Point(double a,double b){
x = a; y = b;
}
Point::Point(const Point &a){
x=a.x; y=a.y;
}
double Point::dist(Point a){
return sqrt( (x-a.x)*(x-a.x)+(y-a.y)*(y-a.y) );
}
bool Point::inRect(Rectangle a){
double cx=a.getX(), cy=a.getY(), w=a.getWidth(), h=a.getHeight();
if( cx-w/2 < x and x < cx+w/2 and cy-h/2 < y and y < cy+h/2 ) return true;
else return false;
}
bool Point::inCircle(Circle a){
Point cc;
cc.x=a.getX(); cc.y=a.getY();
if ( dist(cc) < a.getRadius() ) return true;
else return false;
}
double Point::getX(){
return x;
}
double Point::getY(){
return y;
}
class Point{
double x, y;
public:
Point();
Point(double a,double b);
void read();
Point(const Point &a);
double dist(Point a);
bool inRect(Rectangle a);
bool inCircle(Circle a);
double getX();
double getY();
};
void polynomial::read(){
int m;
cin >> m;
double coeff[m];
int expo[m];
for(int i = 0;i < m;i++){
cin >> expo[i];
cin >> coeff[i];
}
int mexpo = expo[0];
for(int i = 1;i < m;i++){
mexpo = max(mexpo,expo[i]);
}
n = mexpo;
a = new double[mexpo + 1];
for(int i = 0;i <= mexpo;i++){
a[i] = 0;
}
for(int i = 0;i < m;i++){
a[expo[i]] += coeff[i];
}
}
void polynomial::print(){
int nzro=0;
while(a[nzro]==0){
nzro++;
}
for(int i=0; i<n+1; i++){
if(n==0){
cout << a[0] << endl;
}
else{
if(a[i]==0){
continue;
}
else{
if(nzro==0){
if(a[i]>0){
if(i==0) cout << a[i];
if(i==1) cout << " + " << abs(a[i]) << "x";
if(i>1 and i!=n) cout << " + " << abs(a[i]) << "x^" << i;
if(i==n) cout << " + " << abs(a[n]) << "x^" << n << endl;
}
else{
if(i==0) cout << a[i];
if(i==1) cout << " - " << abs(a[i]) << "x";
if(i>1 and i!=n) cout << " - " << abs(a[i]) << "x^" << i;
if(i==n) cout << " - " << abs(a[n]) << "x^" << n << endl;
}
}
else{
if(a[i]>0){
if(i==nzro) cout << (a[i]) << "x";
if(i>nzro and i!=n) cout << " + " << abs(a[i]) << "x^" << i;
if(i==n) cout << " + " << abs(a[n]) << "x^" << n << endl;
}
else{
if(i==nzro) cout << (a[i]) << "x" << endl;
if(i>nzro and i!=n) cout << " - " << abs(a[i]) << "x^" << i;
if(i==n) cout << " - " << abs(a[n]) << "x^" << n << endl;
}
}
}
}
}
}
polynomial polynomial::operator+(const polynomial &b){
int x = max(n,b.n);
int y = min(n,b.n);
polynomial c;
c.n = x;
c.a = new double[x+1];
for(int i = 0; i < x+1; i++)
if(i<y+1)
c.a[i] = a[i] + b.a[i];
else if(n > b.n)
c.a[i] = a[i];
else
c.a[i] = b.a[i];
return c;
}
polynomial polynomial::operator-(const polynomial &b){
int x = max(n,b.n);
int y = min(n,b.n);
polynomial c;
c.n = x;
c.a = new double[x+1];
for(int i = 0; i < x+1; i++)
if(i<y+1)
c.a[i] = a[i] - b.a[i];
else if(n > b.n)
c.a[i] = a[i];
else
c.a[i] = - b.a[i];
return c;
}
polynomial & polynomial::operator=(const polynomial &rhs){
for(int i = rhs.n;i >=0;i--){
if(rhs.a[i] != 0){
n = i;
break;
}
}
a = new double[n+1];
for(int i =0 ;i<n+1;i++)
a[i] = rhs.a[i];
return *this;
}
polynomial polynomial::operator*(const polynomial &b){
polynomial c;
c.n = n + b.n;
c.a = new double[c.n+1];
for(int i = 0;i < c.n + 1;i++){
c.a[i] = 0;
}
for(int i = 0;i<n+1;i++){
for(int j = 0;j<b.n+1;j++){
c.a[i+j] += a[i] * b.a[j];
}
}
return c;
}
polynomial polynomial::operator/(const polynomial &b){
polynomial c;
if(b.n <= n){
polynomial x,y;
x.n = n - 1;
y.n = n - b.n;
y.a = new double[y.n+1];
for(int i = 0;i<y.n;i++){
y.a[i] = 0;
}
y.a[y.n] = a[n]/b.a[b.n];
c = y * b;
polynomial * g = this;
x = *g - c;
polynomial z = x / b;
return y + z;
}
else {
polynomial z;
z.n = 0;
z.a = new double[1];
z.a[0] = 0;
return z;
}
}
polynomial polynomial::operator%(const polynomial &b){
polynomial * x = this;
polynomial z = *x / b;
polynomial c = z * b;
return (*x - c);
}
polynomial polynomial::diff(){
polynomial x;
x.n = n -1;
x.a = new double[n];
for(int i = 1;i<n+1;i++){
x.a[i-1] = i * a[i];
}
return x;
}
polynomial polynomial::integrate(){
polynomial x;
x.n = n + 1;
x.a = new double[n+2];
x.a[0] = 0;
for(int i = 1;i<n+2;i++){
x.a[i] = a[i-1]/i;
}
return x;
}
long double polynomial::valueAt(const double &x){
long double value = a[0];
for(int i =1;i<n+1;i++){
value += a[i]*(pow(x,i));
}
return value;
}
void polynomial::plot(const double &xl,const double &xr,Rectangle r){
polynomial * ptr = this;
Line *lptr;
repaint();
double w = r.getWidth() - 10,h = r.getHeight() - 10,cx = r.getX(),cy = r.getY();
Line l1(cx - w/2 - 5,cy,cx + w/2 + 5,cy);
if(true){
long double fy,fx = w/(xr-xl);
long double dx = 0.009,mx = ptr->valueAt(xl),mn = ptr->valueAt(xl);
for(long double x = xl ; x <= xr ; x += dx){
mx = max(mx,ptr->valueAt(x));
mn = min(mn,ptr->valueAt(x));
}
long double xm = max(abs(mx),abs(mn));
fy = h/(xm*2);
int nlines = (xr - xl)/dx;
lptr = new Line[nlines + 3];
long double yl = ptr->valueAt(xl),yr;
int i =0;
for(long double x = xl ; x <= xr;x += dx){
yr = ptr->valueAt(x + dx);
Line l2((cx - (w/2))+((x - xl)*fx),cy + ((-yl)*fy),(cx - (w/2)) + (x + dx - xl)*fx,cy + ((-yr)*fy));
lptr[i] = l2; i++;
yl = yr;
}
}
cout << "Click to clear." << endl;
getClick();
delete[] lptr;
}
class polynomial{
int n;
double *a;
public:
polynomial(){
}
void read();
void print();
polynomial operator+(const polynomial &b);
polynomial operator/(const polynomial &b);
polynomial operator%(const polynomial &b);
polynomial operator*(const polynomial &b);
polynomial operator-(const polynomial &b);
polynomial & operator=(const polynomial &rhs);
polynomial diff();
polynomial integrate();
long double valueAt(const double &x);
void plot(const double &xl,const double &xr, Rectangle r);
};
This diff is collapsed.
class polyui{
float h,w;
polynomial p,q;
int i=0,j=0,k=0,m=0; //pointers
Circle* c[20];
Line* l[20];
Text* t[10];
Rectangle* r[100];
Rectangle rm,rc,r1,r2,r3;
bool readytostay=true;
Circle exitui;
bool pread=false, qread=false;
Rectangle ppolyread;
Rectangle qpolyread;
Rectangle pqswap;
Rectangle add;
Rectangle minus;
Rectangle remain;
Rectangle multiply;
Rectangle divide;
Rectangle diffp;
Rectangle diffq;
Rectangle integp;
Rectangle integq;
Rectangle plotp;
Rectangle plotq;
public:
polyui();
~polyui();
void click();
void ppolyreadfn();
void qpolyreadfn();
void pqswapfn();
void addfn();
void minusfn();
void remainfn();
void multiplyfn();
void dividefn();
void plotpfn();
void plotqfn();
void diffpfn();
void diffqfn();
void integpfn();
void integqfn();
void textAlloc(Text tex);
void rectAlloc(Rectangle rec);
void circAlloc(Circle cir);
void lineAlloc(Line lin);
};
void tcui::rectAlloc(Rectangle rec){
r[m] = new Rectangle;
*r[m] = rec;
m++;
}
void tcui::textAlloc(Text txt){
t[k] = new Text;
*t[k] = txt;
k++;
}
void tcui::circAlloc(Circle cir){
c[i] = new Circle;
*c[i] = cir;
i++;
}
void tcui::lineAlloc(Line lin){
l[j] = new Line;
*l[j] = lin;
j++;
}
void tcui::click(){
Point e; e.read();
if(e.inRect(comp)){
cout << "Compressor is active." << endl;
tstring a;
a.compress();
}
else if(e.inRect(decomp)){
cout << "Decompressor is active." << endl;
tstring b;
b.decompress();
}
else if(e.inRect(analyse)){
cout << "Analysis." << endl;
tstring c;
c.analyse();
}
else if( e.inCircle(exitui) ){
readytostay=false;
}
}
tcui::tcui(){ //tcui layout
w = 800,h = 600;
//AppBounds
double wp = (6*w)/8,hp = (4*h)/6;
rm.init(w/2,h/2,wp,hp); Rectangle rmoutl(w/2,h/2,wp,hp);
rm.setColor(COLOR(230,228,227));rm.setFill();
rectAlloc(rm); rectAlloc(rmoutl);
//AppTaskBar
int it=25; // Task bar
Rectangle tk[2*it];
double t=it, ht=h/16; double pdown=0;
for(int i=0; i<t; i++){
tk[i+it].init(w/2,(h/2) - (hp/2 )- (ht/2)+(ht/(2*t))*i + (pdown),wp,ht/(2*t));
tk[i+it].setColor(COLOR(0,0,0));
tk[i+it].setFill(true);
tk[i].init(w/2,(h/2) - (hp/2 )- (ht/2)-(ht/(2*t))*i + (pdown),wp,ht/(2*t));
tk[i].setColor(COLOR(65+(60.0/t)*i,65+(60.0/t)*i,65+(60.0/t)*i));
tk[i].setFill(true);
rectAlloc(tk[i]); rectAlloc(tk[i+it]);
}
//exitButton
float rad = h/20; // setting r to the size of exitui button
exitui.init(w-rad-10,rad+10,rad); exitui.setColor(COLOR(243,81,79)); exitui.setFill();
Circle olexitui(w-rad-10,rad+10,rad); circAlloc(exitui); circAlloc(olexitui);
// links
comp.init( w/2, h/2-hp/3, wp, hp/3);
Text comptxt( w/2, h/2-hp/3 , "Compress");// the dimensions of the dialog box
//textAlloc(painttxt);
decomp.init(w/2, h/2, wp, hp/3);
Text decomptxt( w/2, h/2 , "Decompress");
//textAlloc(polytxt);
analyse.init(w/2, h/2+hp/3, wp, hp/3);
Text analysetxt(w/2, h/2+hp/3, "Analysis");
//textAlloc(textprtxt);
Line compdecomp(w/2-wp/2+20,h/2-hp/6, w/2+wp/2-20, h/2-hp/6);
Line decompanalyse(w/2-wp/2+20,h/2+hp/6, w/2+wp/2-20, h/2+hp/6);
//rectAlloc(Paint); rectAlloc(PolyPr); rectAlloc(TextPr); // allocations
cout << "The files under analysis in this processor should be of txt type." << endl;
cout << "The text should be written in one paragraph with none of the lines having an empty line between them." << endl;
cout << "The files analysed, created or read should and will be in the same directory as the Application." << endl;
while(readytostay){
click();
}
}
tcui::~tcui(){
cout << "Closing Text Processor." << endl;
for(int x = 0;x<m;x++)
delete r[x];
for(int x = 0;x<i;x++)
delete c[x];
for(int x = 0;x<j;x++)
delete l[x];
for(int x = 0;x<k;x++)
delete t[x];
}
class tcui{
float h,w;
int i=0,j=0,k=0,m=0; //pointers
Circle* c[20];
Line* l[20];
Text* t[10];
Rectangle* r[100];
Rectangle rm,rc,r1,r2,r3;
Circle exitui;
Rectangle comp, decomp, analyse;
bool readytostay = true;
public:
tcui();
~tcui();
void rectAlloc(Rectangle rec);
void circAlloc(Circle cir);
void lineAlloc(Line lin);
void textAlloc(Text txt);
void click();
};
\ No newline at end of file
This diff is collapsed.
struct dword{
string substring;
int frequency = 1;
int stecode;
};
struct Word{
string substring;
int stecode;
dword * ptr;
};
class tstring{
char * dir;
string str;
Word* wptr;
dword * dptr; dword * dptrb;
int wordcount, dotcount, count, dcount, assignedcodes;
bool huffman;
int n,ncharinp,ncharout;
public:
~tstring();
void read(); // input through terminal
void readTxtFile(); // input from text file
int length(); // length of the string
void wordProcess(); // searches the string for a word and creates words & dots array
void distWord();
void freqAssign(); // assigns frequency // creates parallel array of frequencies // optional ; can be enabled later
void isequalto(tstring p);
void codeassign(); // assigns lowest code to most frequent word
void encode();
void decode();
void compress(); // creates text file or prints out text // #*#*# First Call This #*#*#
void decompress(); // reverses all these processes
int stec(int i);
int revstec(int i);
int stroint(string a);
void analyse();
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment