Jump to content
xisto Community

nooc9

Members
  • Content Count

    31
  • Joined

  • Last visited

  1. Here is an example solution where I'm using a b-tree on the stack. #include <stdio.h>#include <stdlib.h>/* node */typedef struct _item { char a[30]; int b, c; struct _item *l,*r;} item;/* print tree */void print(item* t){ if(t) { print(t->l); printf("%s %d %d\n",t->a, t->b, t->c); print(t->r); }}/* read items from file into tree stored on stack */void readItem(FILE* f, item** t){ item i,*n; if(fscanf(f,"%s %d %d",&i.a, &i.b, &i.c)==3) { i.l=i.r=0; /* clear leafs */ /* insert into tree */ if(*t == 0) *t = &i; else { n=*t; for(;;) { if(n->c <= i.c) { if(n->r) n = n->r; else { n->r = &i; break; } } else { if(n->l) n = n->l; else { n->l = &i; break; } } } } readItem(f, t); /* recurse to next read or print tree */ return; } print(*t); /* must print here because tree is on stack */}int main(void){ /* tree root */ item* tree = 0; FILE* f = fopen("input.txt","r"); if(f==0) { printf("file error\n"); return; } /* process */ readItem(f,&tree); fclose(f);}
  2. As this was posted in C/C++ I feel it should be mentioned that if on windows, there are the windows GDI functions/classes to use and thus, no need for 3rd party libs or .NET. #include <gdiplus.h>...Bitmap* bm = new Bitmap("image.jpg");...// bm->LockBits() or bm->GetPixel()...delete bm;...
  3. Personally I don't see any significant changes happening in that timespan. Maybe we will be hit by a space rock. Who knows.And speaking of rocks in space, you could use opengl to simulate a space rock hitting your country 2020.. You would need a sphere, a rock model and the textures (earth, rock, stars background).There is no fancy programming involved. I suppose you would have to know what a vector and matrix is and how to use them, and also be able to export a 3d model to some raw format that could easily be passed to opengl. There are plenty of good opengl "hello world" tutorials out there.
  4. You should try asking your question in blitzbasic forums: http://www.blitzbasic.com/Community/_index_.php
  5. I also googled some and found a flash game engine: http://www.hugedomains.com/domain_profile.cfm?d=pushbuttonengine&e=com According to the site, they're also working on an editor for it.
  6. No, not a slip up. Its just another regex constructor seen a lot in perl and it allows you to pass flags. In my expression I had the i flag (case insensitive). If you omit the $ at the end then you don't need ".*" either.
  7. Yes, indeed. I'm escaping the slashes because they have special meaning here, ie. you construct a regex by using /expression/flags.
  8. I guess you want something like this: function urlIsOk(url){ return url.match( /^http:\/\/(www\.)?example.com/i )) != null;}
  9. How good error messages are is not a language thing but a compiler thing. Sometimes the error message has to be very general to fit all scenarios and that can be a pain to debug, especially if your code is large and complex. C++ is my favorite language. It fills all my non web needs and I love pointers.. In other words, what annoys them is programming in general. I can understand that many find pointers difficult, but you can't write anything useful without data structures (any language). Templates are a huge help. Gui handling looks pretty much the same in almost every oo language.
  10. I think Wiktionary definition 2 is pretty nice: "An incompatibility of two things that cannot be simultaneously fulfilled." The word is pretty general and I think it would be wrong to try to specialize it. If you know the general meaning of the word then you will know what it refers to in whatever context it is used in.
  11. #include <iostream>class Resistor{ float R;public: Resistor& setR(float r) { R=r; return *this; } float getI(float E) { return E/R; } float getE(float I) { return R*I; } float getP(float I) { return I*getE(I); } Resistor() :R(0) {} Resistor(float r) :R(r) {}};int main() { Resistor r(5); std::cout << "Resistor(5).getE(0.5) = " << r.getE(0.5f) << " V" << std::endl; std::cout << "Resistor(100).getI(12) = " << r.setR(100).getI(12) << " A" << std::endl; std::cout << "Resistor(1200).getP(0.01) = " << r.setR(1200).getP(0.01) << " W" << std::endl; return 0;} Ok, so here is a silly one from me. Let Variables be a map of string to float: typedef std::map<std::string,float> Variables; Let Operation be an abstract class that has the following declaration: struct Operation { virtual float evaluate(const Variables& vars) = 0;}; Implement Add, Sub, Mul, Div, Const, Var that extend Operation so that the following example is possible: // Create expression: (A+10)*(1/(B-3))Mul expression( Add( Var("A"), Const(10) ), Div( Const(1), Sub(Var("B"),Const(3)) ) );// Create variable mapVariables vars;vars["A"] = 2.5;vars["B"] = 7;// Evaluate expression using variables in vars mapfloat result = expression.evaluate(vars);You may add abstract methods to Operation.
  12. I made a small game in flash a long time ago where you steer a space ship with the arrow keys through an obstacle field. I used MovieClip.hitTest() for that. Create a list of (x,y) points that define your characters perimeter. Put the collideable level in one movie clip and call clip.hitTest(x,y,true) for each item in the perimeter list each move frame.
  13. Did you request permissions in the jnlp and are the jars signed?
  14. Almost all the hosts that I've used that had outgoing access had the curl extension enabled. curl is a widely used add-on and is enabled on many hosts.
  15. Anything that has to do with browser security will probably require the user to manually change some setting.If you want to create a wrapper then you will need to use something like curl, if using php, to handle cookies and stuff.
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.