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);
};
void polyui::rectAlloc(Rectangle rec){
r[m] = new Rectangle;
*r[m] = rec;
m++;
}
void polyui::textAlloc(Text txt){
t[k] = new Text;
*t[k] = txt;
k++;
}
void polyui::circAlloc(Circle cir){
c[i] = new Circle;
*c[i] = cir;
i++;
}
void polyui::lineAlloc(Line lin){
l[j] = new Line;
*l[j] = lin;
j++;
}
polyui::polyui(){ // poly ui Layout
w = 800,h = 600;
//AppBounds
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);
//AppTaskBar
int it=25; // Task bar
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 - 80;
rc.init(w/2,h/2 + 30,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);
// control panel of the polynomial
// left half // wdb = width of buttons on the left
double wdb=(wc/2-50)/5, htb=20;
ppolyread.init(w/2-wc/2+wdb/2,h/2-hp/2+10+htb/2, wdb, htb); ppolyread.setColor(COLOR(255,255,255));
ppolyread.setFill();
Text ppolyreadtext(w/2-wc/2+wdb/2,h/2-hp/2+10+htb/2, "P");
qpolyread.init(w/2-wc/2+wdb/2,h/2-hp/2+10+htb/2 + htb + 10, wdb, htb); qpolyread.setColor(COLOR(255,255,255));
qpolyread.setFill(); // below ppolyread
Text qpolyreadtext(w/2-wc/2+wdb/2,h/2-hp/2+10+htb/2 + htb + 10, "Q");
pqswap.init(w/2-wc/2+wdb/2 + (wdb + 10),h/2-hp/2+10+htb/2 + htb/2 + 5, wdb, htb); pqswap.setColor(COLOR(255,255,255));
pqswap.setFill();
Text pqswaptext(w/2-wc/2+wdb/2 + (wdb + 10),h/2-hp/2+10+htb/2 + htb/2 + 5, "Swap");
add.init(w/2-wc/2+wdb/2 + 2*(wdb + 10),h/2-hp/2+10+htb/2, wdb, htb); add.setColor(COLOR(255,255,255));
add.setFill();
Text addtext(w/2-wc/2+wdb/2 + 2*(wdb + 10),h/2-hp/2+10+htb/2, "+");
minus.init(w/2-wc/2+wdb/2 + 3*(wdb + 10),h/2-hp/2+10+htb/2, wdb, htb); minus.setColor(COLOR(255,255,255));
minus.setFill();
Text minustext(w/2-wc/2+wdb/2 + 3*(wdb + 10),h/2-hp/2+10+htb/2, "-");
remain.init(w/2-wc/2+wdb/2 + 4*(wdb + 10),h/2-hp/2+10+htb/2, wdb, htb); remain.setColor(COLOR(255,255,255));
remain.setFill();
Text remaintext(w/2-wc/2+wdb/2 + 4*(wdb + 10),h/2-hp/2+10+htb/2, "%"); // top row till here
multiply.init(w/2-wc/2+wdb/2 + 2*(wdb + 10) + (5+wdb/2) ,h/2-hp/2+10+htb/2 + htb + 10, wdb, htb); multiply.setColor(COLOR(255,255,255));
multiply.setFill();
Text multiplytext(w/2-wc/2+wdb/2 + 2*(wdb + 10) + (5+wdb/2) ,h/2-hp/2+10+htb/2 + htb + 10, "x");
divide.init(w/2-wc/2+wdb/2 + 3*(wdb + 10) + (5+wdb/2) ,h/2-hp/2+10+htb/2 + htb + 10, wdb, htb); divide.setColor(COLOR(255,255,255));
divide.setFill();
Text dividetext(w/2-wc/2+wdb/2 + 3*(wdb + 10) + (5+wdb/2) ,h/2-hp/2+10+htb/2 + htb + 10, "/");
// control panel
// right half // wrb = width of buttons on the right
double wrb = wc/6-10;
plotp.init(w/2 + wrb/2, h/2-hp/2+10+htb/2, wrb, htb ); plotp.setColor(COLOR(255,255,255));
plotp.setFill();
Text plotptext(w/2 + wrb/2, h/2-hp/2+10+htb/2, "Plot P");
plotq.init(w/2 + wrb/2, h/2-hp/2+10+htb/2 + htb + 10, wrb, htb ); plotq.setColor(COLOR(255,255,255));
plotq.setFill();
Text plotqtext(w/2 + wrb/2, h/2-hp/2+10+htb/2 + htb + 10, "Plot Q");
diffp.init(w/2 + wrb/2 + (wrb+15), h/2-hp/2+10+htb/2, wrb, htb ); diffp.setColor(COLOR(255,255,255));
diffp.setFill();
Text diffptext(w/2 + wrb/2 + (wrb+15), h/2-hp/2+10+htb/2, "Differentiate P");
diffq.init(w/2 + wrb/2 + (wrb+15), h/2-hp/2+10+htb/2 + htb + 10, wrb, htb ); diffq.setColor(COLOR(255,255,255));
diffq.setFill();
Text diffqtext(w/2 + wrb/2 + (wrb+15), h/2-hp/2+10+htb/2 + htb + 10, "Differentiate Q");
integp.init(w/2 + wrb/2 + 2*(wrb+15), h/2-hp/2+10+htb/2, wrb, htb ); integp.setColor(COLOR(255,255,255));
integp.setFill();
Text integptext(w/2 + wrb/2 + 2*(wrb+15), h/2-hp/2+10+htb/2, "Integrate P");
integq.init(w/2 + wrb/2 + 2*(wrb+15), h/2-hp/2+10+htb/2 + htb + 10, wrb, htb ); integq.setColor(COLOR(255,255,255));
integq.setFill();
Text integqtext(w/2 + wrb/2 + 2*(wrb+15), h/2-hp/2+10+htb/2 + htb + 10, "Integrate Q");
/*
// allocations rectangles
rectAlloc(ppolyread); rectAlloc(qpolyread); rectAlloc(pqswap);
rectAlloc(add); rectAlloc(minus); rectAlloc(remain);
rectAlloc(multiply); rectAlloc(divide);
rectAlloc(plotp); rectAlloc(plotq);
rectAlloc(diffp); rectAlloc(diffq);
rectAlloc(integp); rectAlloc(integq);
// allocations text
textAlloc(ppolyreadtext); textAlloc(qpolyreadtext); textAlloc(pqswaptext);
textAlloc(addtext); textAlloc(minustext); textAlloc(remaintext);
textAlloc(multiplytext); textAlloc(dividetext);
textAlloc(plotptext); textAlloc(plotqtext);
textAlloc(diffptext); textAlloc(diffqtext);
textAlloc(integptext); textAlloc(integqtext);
*/
cout << "Welcome to Polynomial Processor." << endl;
cout << "Please read the Polynomials P, Q before proceeding to use operations on them." << endl;
while(readytostay){
click();
}
}
void polyui::click(){
Point e; e.read();
if(e.inRect(ppolyread )) ppolyreadfn();
else if(e.inRect(qpolyread )) qpolyreadfn();
else if(e.inRect(pqswap )) pqswapfn();
else if(e.inRect(add )) addfn();
else if(e.inRect(minus )) minusfn();
else if(e.inRect(remain )) remainfn();
else if(e.inRect(multiply )) multiplyfn();
else if(e.inRect(divide )) dividefn();
else if(e.inRect(plotp )) plotpfn();
else if(e.inRect(plotq )) plotqfn();
else if(e.inRect(diffp )) diffpfn();
else if(e.inRect(diffq )) diffqfn();
else if(e.inRect(integp )) integpfn();
else if(e.inRect(integq )) integqfn();
else if( e.inCircle(exitui) ){
readytostay=false;
}
}
polyui::~polyui(){
cout << "Closing Polynomial 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];
}
void polyui::ppolyreadfn(){
cout << "Input Polynomial P." << endl;
cout << "No of terms; followed by index of the term and the coefficients." << endl;
p.read();
cout << "P read successfully." << endl;
pread=true;
}
void polyui::qpolyreadfn(){
cout << "Input Polynomial Q." << endl;
cout << "No of terms; followed by index of the term and the coefficients." << endl;
q.read();
cout << "Q read successfully." << endl;
qread=true;
}
void polyui::pqswapfn(){
if (pread and qread){
polynomial temp;
temp=q;
q=p;
p=temp;
cout << "Swapping P and Q." << endl;
}
else if(!pread and !qread){ cout << "Enter P and Q and try again." << endl; }
else if(!pread){ cout << "Enter P and try again." << endl; }
else if(!qread){ cout << "Enter Q and try again." << endl; }
}
void polyui::addfn(){
if (pread and qread){
polynomial r=p+q;
cout << "Addition:" << endl;
r.print();
}
else if(!pread and !qread){ cout << "Enter P and Q and try again." << endl; }
else if(!pread){ cout << "Enter P and try again." << endl; }
else if(!qread){ cout << "Enter Q and try again." << endl; }
}
void polyui::minusfn(){
if (pread and qread){
polynomial r=p-q;
cout << "Sutraction:" << endl;
r.print();
}
else if(!pread and !qread){ cout << "Enter P and Q and try again." << endl; }
else if(!pread){ cout << "Enter P and try again." << endl; }
else if(!qread){ cout << "Enter Q and try again." << endl; }
}
void polyui::remainfn(){
if (pread and qread){
polynomial r=p%q;
cout << "Remiander:" << endl;
r.print();
}
else if(!pread and !qread){ cout << "Enter P and Q and try again." << endl; }
else if(!pread){ cout << "Enter P and try again." << endl; }
else if(!qread){ cout << "Enter Q and try again." << endl; }
}
void polyui::multiplyfn(){
if (pread and qread){
polynomial r=p*q;
cout << "Product:" << endl;
r.print();
}
else if(!pread and !qread){ cout << "Enter P and Q and try again." << endl; }
else if(!pread){ cout << "Enter P and try again." << endl; }
else if(!qread){ cout << "Enter Q and try again." << endl; }
}
void polyui::dividefn(){
if (pread and qread){
polynomial r=p/q;
cout << "Quotient:" << endl;
r.print();
}
else if(!pread and !qread){ cout << "Enter P and Q and try again." << endl; }
else if(!pread){ cout << "Enter P and try again." << endl; }
else if(!qread){ cout << "Enter Q and try again." << endl; }
}
// next batch of buttons
void polyui::plotpfn(){
if(!pread){ cout << "Enter P and try again." << endl; }
else{
cout << "Plotting P." << endl << "Graph between?" << endl;
long double a,b;
cin >> a >> b;
if(a<=b) {}
else{
long double temp=b;
b=a; a=temp;
cout << "Swapped." << endl;
}
cout << "Plotting..." << endl << "Please wait." << endl;
p.plot(a,b,rc);
}
}
void polyui::plotqfn(){
if(!qread){ cout << "Enter Q and try again." << endl; }
else{
cout << "Plotting Q." << endl << "Graph between?" << endl;
long double a,b;
cin >> a >> b;
if(a<=b) {}
else{
long double temp=b;
b=a; a=temp;
cout << "Swapped." << endl;
}
cout << "Plotting..." << endl << "Please wait." << endl;
q.plot(a,b,rc);
}
}
void polyui::diffpfn(){
if(!pread){ cout << "Enter P and try again." << endl; }
else{
polynomial r=p.diff();
cout << "Derivative of P:" << endl;
r.print();
}
}
void polyui::diffqfn(){
if(!qread){ cout << "Enter Q and try again." << endl; }
else{
polynomial r=q.diff();
cout << "Derivative of Q:" << endl;
r.print();
}
}
void polyui::integpfn(){
if(!pread){ cout << "Enter P and try again." << endl; }
else{
polynomial r=p.integrate();
cout << "Integral of P:" << endl;
r.print();
}
}
void polyui::integqfn(){
if(!qread){ cout << "Enter Q and try again." << endl; }
else{
polynomial r=q.integrate();
cout << "Integral of Q:" << endl;
r.print();
}
}
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
int tstring::stroint(const string a){
int n=a.length();
int fint = 0;
for(int q=0; q<n; q++){
int temp=a[n-q-1] - 48;
fint = fint + temp * pow(10,q);
}
return fint;
}
int tstring::stec(int i){
// zerototwelve; // +33
// thirteen; // 47
// fourteentoeightytwo; // +44
// eightythreetotwoten; // +45
if(0<=i and i<=12) return i+33;
else if(i==13) return 47;
else if(14<=i and i<=82) return i+44;
else if(83<=i and i<=210) return i+45;
else return 0;
}
int tstring::revstec(int i){
if(33<=i and i<=45) return i-33;
else if(i==47) return 13;
else if(58<=i and i<=126) return i-44;
else if(128<=i and i<=255) return i-45;
else return 0;
}
void tstring::read(){
string temp;
do{
getline(cin,temp);
if(temp.length() > 0){
if(str.length()!=0) str.append(" ");
str.append(temp);
}
}while(temp.length() > 0);
}
void tstring::readTxtFile(){
string temp,direc;
cout << "Name of the file: " ;
cin >> direc;
dir = new char[direc.length()+1];
for(unsigned int i =0 ;i<direc.length()+1;i++){
dir[i] = direc[i];
}
ifstream in(dir);
do{
getline(in,temp);
if(temp.length() > 0){
str.append(" ");
str.append(temp);
}
}while(temp.length() > 0);
ncharinp = str.length();
}
void tstring::wordProcess(){
ifstream in(dir);
wordcount=0; // finds the number of words
size_t i=0,b = str.length();
while(i<b){
if (str[i] == ' ') wordcount++;
i++;
if(i==b) { break; }
}
dotcount=0; i = 0; // finds no of dots
while(i<b){
if (str[i] == '.' and (str[i+1]==' ' or str[i+1] == '\0')) dotcount++;
i++;
if(i==b) { break; }
}
count = wordcount + dotcount;
wptr = new Word[wordcount+dotcount]; // creates words
string buffer;
for(int i = 0; i < count ; i++){
in >> buffer; int bl = buffer.length();
if(buffer[bl - 1] == '.'){
buffer.erase(bl-1,1);
wptr[i].substring = buffer;
wptr[i+1].substring = '.';
i++;
}
else wptr[i].substring = buffer;
}
}
void tstring::distWord(){
dcount = 0;
for(int i = 0;i< count ; i++){
bool b = true;
for(int j =0;j< i ; j++){
if(wptr[j].substring == wptr[i].substring){ b = false; break; }
}
if(b) dcount ++;
}
dptr = new dword[dcount]; int k = 0;
for(int i = 0;i< count ; i++){
bool repfound=false;
for(int j =0;j< i ; j++){
if(wptr[j].substring == wptr[i].substring){ repfound=true; wptr[i].ptr = wptr[j].ptr; }
}
if(!repfound){
dptr[k].substring = wptr[i].substring;
wptr[i].ptr = &(dptr[k]);
k++;
}
}
for(int i = 0;i < count;i++){
for (int j = 0; j < i ; j++){
if(wptr[i].substring == wptr[j].substring){
(wptr[i].ptr)->frequency++;
break;
}
}
}
}
void tstring::codeassign(){
assignedcodes = 0;
dptrb = new dword[dcount];
for(int i=0; i < dcount; i++){
dptrb[i].frequency = dptr[i].frequency ;
}
while(assignedcodes<dcount){
int maxsofar=0, index=0;
/* probably better code
int maxsofarn=0;
for(int i=0; i<dcount ; i++){
maxsofarn=max( maxsofar, dptrb[i].frequency );
if( maxsofarn == dptrb[i].frequency and maxsofar!=dptrb[i].frequency ) index=i;
maxsofarn=maxsofar;
} */
//alternate code
for(int i=0; i<dcount ; i++){
maxsofar=max( maxsofar, dptrb[i].frequency );
}
for(int i=0; i<dcount ; i++){
if(maxsofar == dptrb[i].frequency) { index = i; break; }
}
dptrb[index].stecode = assignedcodes;
dptrb[index].frequency = 0;
assignedcodes++;
}
for(int i=0; i<dcount; i++){ // copying stecode into the main array
dptr[i].stecode = dptrb[i].stecode;
}
}
void tstring::compress(){
readTxtFile();
wordProcess();
distWord();
codeassign();
cout << "Name of the compressed file to be created: ";
string direc;
cin >> direc;
direc = direc + ".stec";
dir = new char[direc.length()+1];
for(size_t i =0 ;i<direc.length()+1;i++){
dir[i] = direc[i];
}
ofstream out(dir);
for(int i = 0;i < dcount;i++){
out << dptr[i].substring;
if(i < dcount -1){
if(dptr[i].stecode <= 210){
char c = stec(dptr[i].stecode);
out << " " << c <<" ";
} else {
out << " " << dptr[i].stecode - 211 << " ";
}
}
else {if(dptr[i].stecode <= 210){
char c = stec(dptr[i].stecode);
out << " " << c <<" ";
} else {
out << " " << dptr[i].stecode - 211 << " ";
}
}
}
out << endl;
for(int i = 0; i < count;i++){
if((wptr[i].ptr)->stecode <= 210){
char c = stec((wptr[i].ptr)->stecode);
out << c;
}
else {
if(i <count -1){
if((wptr[i + 1].ptr)->stecode - 211 < 0){
out << " " << ((wptr[i].ptr)->stecode - 211) << " ";
} else {
out << " " << ((wptr[i].ptr)->stecode - 211);
}
}
else out << " " << ((wptr[i].ptr)->stecode - 211);
}
}
//input the name the compressed file
ifstream com(dir);
string temp;
do{
getline(com,temp);
if(temp.length() > 0){
str.append(" ");
str.append(temp);
}
}while(temp.length() > 0);
ncharout = str.length();
}
void tstring::decompress(){
dcount = 0;
string temp,direc;
cout << "Name of the file to be decompressed: ";
cin >> direc;
char * dir;
dir = new char[direc.length()+1];
for(size_t i =0 ;i<direc.length()+1;i++){
dir[i] = direc[i];
}
ifstream in1(dir);
string tem;
getline(in1,tem);
for(int i = 0;tem[i] != '\0';i++){
if(tem[i] == ' ') dcount++;
}
dcount = (dcount/2);
dptr = new dword[dcount];
ifstream in2(dir);
for(int i = 0; i < dcount ; i++){
in2 >> dptr[i].substring;
in2 >> tem;
if(tem[0]>57 or tem[0] <48){
char c = tem[0];
int x = c;
if(x < 0){ x += 256;}
dptr[i].stecode = revstec(x);
}
else {
dptr[i].stecode = stroint(tem) + 211;
}
}
ifstream in3(dir);
getline(in3,tem);
getline(in3,tem);
int nos = 1;
for(int i = 0;tem[i] != '\0';i++){
if(tem[i] == ' ') nos++;
}
ifstream in4(dir);
getline(in4,tem);
count = 0;
for(int i = 0;i < nos;i++){
int ind;
in4 >> tem;
ind = tem[0];
if (ind>=48 and ind <=57){
count++;
}else count+= tem.length();
}
wptr = new Word[count];
int wi = 0;
ifstream in5(dir);
getline(in5,tem);
for(int i = 0;i < nos;i++){
int ind;
in5 >> tem; ;ind = tem[0];
if (ind >= 48 and ind <= 57){
wptr[wi].stecode = stroint(tem) + 211; wi++;
}else {
for(size_t i = 0 ; i < tem.length();i++){
int x = tem[i];
if(x < 0) { x += 256;}
wptr[wi].stecode = revstec(x); wi++;
}
}
}
for(int i = 0;i < count;i++){
for(int j = 0;j < dcount;j++){
if(wptr[i].stecode == (dptr[j].stecode) ){
wptr[i].ptr = &(dptr[j]);
}
}
}
//input the name of the decompressed output file
cout << "Enter the name of the decompressed file to created: ";
cin >> direc;
dir = new char[direc.length()+1];
for(size_t i =0 ;i<direc.length()+1;i++){
dir[i] = direc[i];
}
ofstream out(dir);
for(int i = 0;i<count;i++){
if(i < count - 1){
if((wptr[i + 1].ptr)->substring == "."){
out << (wptr[i].ptr)->substring;
}else {
out << (wptr[i].ptr)->substring << " ";
}
}
else out << (wptr[i].ptr)->substring;
}
}
tstring::~tstring(){
//delete[] dir;
//delete[] wptr;
//delete[] dptr;
//delete[] dptrb;
cout << "Process Complete." << endl;
}
void tstring::analyse(){
readTxtFile();
wordProcess();
distWord();
codeassign();
ofstream out("temp");
for(int i = 0;i < dcount;i++){
out << dptr[i].substring;
if(i < dcount -1){
if(dptr[i].stecode <= 210){
char c = stec(dptr[i].stecode);
out << " " << c <<" ";
} else {
out << " " << dptr[i].stecode - 211 << " ";
}
}
else {if(dptr[i].stecode <= 210){
char c = stec(dptr[i].stecode);
out << " " << c <<" ";
} else {
out << " " << dptr[i].stecode - 211 << " ";
}
}
}
out << endl;
for(int i = 0; i < count;i++){
if((wptr[i].ptr)->stecode <= 210){
char c = stec((wptr[i].ptr)->stecode);
out << c;
}
else {
if(i <count -1){
if((wptr[i + 1].ptr)->stecode - 211 < 0){
out << " " << ((wptr[i].ptr)->stecode - 211) << " ";
} else {
out << " " << ((wptr[i].ptr)->stecode - 211);
}
}
else out << " " << ((wptr[i].ptr)->stecode - 211);
}
}
//input the name the compressed file
ifstream com("temp");
string temp;
do{
getline(com,temp);
if(temp.length() > 0){
str.append(" ");
str.append(temp);
}
}while(temp.length() > 0);
ncharout = str.length();
cout << "No of characters in the file: " << ncharinp << endl;
cout << "No of characters if compressed: " << ncharout << endl;
cout << "The above result may not be significant if the file doesnt have repeated words." << endl;
cout << "Click on the Canvas to continue." << endl;
getClick();
remove("temp");
}
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