Standardization does not produce, although admirable as an efficiency method. - Reginald Fessenden (another alumni of my high school...)
Labdabeta 182 Posting Pro in Training Featured Poster
Labdabeta 182 Posting Pro in Training Featured Poster
Veni, Vidi, Vici (I came, I saw, I conquered) - Julius Caesar
Veni, Vidi, Didici (I came, I saw, I learnt) - Me :)
cproger commented: lol :) +0
Labdabeta 182 Posting Pro in Training Featured Poster
"The natural man has only two primal passions, to get and to beget." - Sir William Osler (Incidentally an alumni of my high school!)
Labdabeta 182 Posting Pro in Training Featured Poster
"I'd hate to die twice. Its so boring." - Richard Feynman's dying words.
Labdabeta 182 Posting Pro in Training Featured Poster
Hello,
I am making a number of libraries to help me with my projects and I am torn between two approaches. I will show you what each looks like. I have no idea which would be considered 'better' in general.
Locals:
#ifndef SOME_GUARD
#define SOME_GUARD VERSION_NUMBER
#ifdef __cplusplus
extern "C" {
#endif
typedef struct { /*something here*/ } myNewTypeTAG, *myNewType;
myNewType function(myNewType); // for example
#ifdef __cplusplus
}
class myNewTypeCppMode
{
//private:
myNewType t;
public:
myNewTypeCppMode &function(myNewType o) {
t=function(o);
return *this;
}
};
#endif
#endif
Context (weightless):
#ifndef SOME_GUARD
#define SOME_GUARD VERSION_NUMBER
#ifdef __cplusplus
extern "C"{
#endif
typedef struct { /*something here*/ } myNewTypeTAG__, *myNewType__;
typedef struct {
myNewType *x;
size_t s;
} myNewContextTAG, *myNewContext;
typedef size_t myNewType;
myNewContext getContext();
myNewType function(myNewType, myNewContext); // uses context->x[object] to access the data
#ifdef __cplusplus
}
class myNewTypeCppMode
//see above example
#endif
//optional main override:
#ifdef OVERRIDE_MAIN
int myNewMain( /*any args I wish to pass*/ , myNewContext);
#define main(X,Y) \
main(X,Y) { \
myNewContext con = getContext(); \
return myNewMain( /*args again*/ , con); \
} \
int myNewMain( /*args*/ , myNewContext con__)
#define REALfunction(X) function(X,con__)
#endif // OVERRIDE_MAIN
#endif
Context (heavy):
#ifndef SOME_GUARD
#define SOME_GUARD VERSION_NUMBER
#ifdef __cplusplus
extern "C"{
#endif
typedef struct { /*something here*/ } myNewTypeTAG__, *myNewType__;
typedef struct {
myNewType *x;
size_t s;
} myNewContextTAG, *myNewContext;
typedef size_t myNewType;
myNewContext current_context__;
myNewContext newContext(); // also sets the context
void setContext(myNewContext);
myNewType function(myNewType); // uses current_context__->x[object] to access the data
#ifdef __cplusplus
}
class …
Labdabeta 182 Posting Pro in Training Featured Poster
The point is that energy drinks will undoubtedly contain either caffeine or something that acts like caffeine. This will mess with your circadian rhythms, making you tired more often. Moreover, most energy drinks cause an abrupt increase in heart rate, greatly increasing your chances of getting certain heart issues, such as heart attacks!
Labdabeta 182 Posting Pro in Training Featured Poster
Both of my parents are doctors... here are some tips that work wonders:
1) STAY HYDRATED!!!
2) Try leaning your head to the left, then right. Make your head look like this \/\/\/... do it slowly-ish. This causes your jugular veins to get compressed. The brain, fearing that something is compressing them, takes a large amount of blood in to compensate. This leads to it becoming temporarily more awake.
3) Buy a false sunlight. Especially if you live in extreme latitudes (like me) you can trick your body into thinking it is daytime by shining a bright light that simulates sunlight onto you (not just your eyes, your skin too). If you live in dark countries normally, you should do this during the day as well. Also most of these lights have alarm clocks built in... I know from exprience, it is hard to sleep through a false sunlight shining on your face! (Ill provide a link to one if required)
4) Excersize (I can never spell it right)
5) Stay away from caffeine. First of all caffeine only works if you are well hydrated, if you are dehydrated it will make you tired. Secondly caffeine messes with your circadian rhythms, making you far more likely to be tired at unusual times. Finally caffeine only works for a short while, afterwards you would need more to keep you awake.
6) Get onto a solid circadian rhythm (sleep cycle). Basically set aside a specific time where …
Labdabeta 182 Posting Pro in Training Featured Poster
I was born Wednesday July 13th, 1994... it was Harrison Ford's 52nd birthday (if my math is correct).
Labdabeta 182 Posting Pro in Training Featured Poster
I got 22... but that was with a 0 in the relationship questions, but I have never really been in any serious relationships and I am pretty sure that I would eek a few more points out of those. Also I have been diagnosed with ADHD,OCD, and Aspberger's syndrome... so the test is likely fairly inaccurate for me. I have also been through a lot of psychological testing, so I am pretty sure that if I were a psychopath, one of the psychiatrists would have noticed. :)
Labdabeta 182 Posting Pro in Training Featured Poster
We need to know more... how does your find function work? what is an emp_data object? What is the problem with the code?
Labdabeta 182 Posting Pro in Training Featured Poster
As for when to use && and when to use || you should really learn about boolean algebra. That way you may be able to actually reduce some of your expressions. Basically boolean algebra deals with true/false, 1/0. It has 2 fundamental operators + (or, ||) and x (and, &&). It has many of the rules that normal algebra has. For example a(b+c)=ab+bc. Replace a with for example sign!='+' and b with sign!='-' and you can create logical expressions that do what you want them to do.
Labdabeta 182 Posting Pro in Training Featured Poster
The issue is on line 26. You check if the sign isnt + OR isnt - OR isnt etc.. you want ANDs there. :)
Labdabeta 182 Posting Pro in Training Featured Poster
Okay... first of all this forum really isn't for just giving away free code, so I doubt anybody will just give you the solution. Now, I assume you are familiar with c++, but judging by your question it is hard to tell. For instance, how are you storing your matrices? is it type matrix[width][height]
? or maybe type matrix[width*height]
? or could it be vector<vector<type>> matrix
? We need more to go off of. On top of that, the way you asked the question makes me think that you haven't even tried to figure this one out yet. I assume you know how to multiply matrices, so try solving the most general case. IE: multiply
A B C ... X
D E F ... X
. . .
. . .
X X X
where A,B,C... are just variables. With this matrix:
a b c ... x
d e f ... x
. . .
. . .
x x x
While you are doing this think of what the constraints might be? Once you can solve the problem on paper, then you are ready to program it.
As for making the program user friendly, one thing that really helps with that is proper modularization in the code. You should break your code up into as many functions as makes sense. If any function does more than 1 distinct things, it should really be broken up into two things. EG:
int f(int a, int b)
{
return a+a*b; …
Labdabeta 182 Posting Pro in Training Featured Poster
I think you might be looking for the wrong software, or looking in the wrong places, i.e., using Windows-reflexes when looking for solutions to your problems.
What I meant by complicated is that it takes extra knowledge. I am well aware that installing things on my Ubuntu is far faster and takes far fewer steps than on windows (especially since most software that you would ever need can probably be gotten via the sudo apt-get install SoftwareName line). The issue is that A) you need to have the raw knowledge to know that for example you want gimp, instead of photoshop (not to mention that (at least IMO) photoshop tends to have a few more useful tools than gimp. On top of that I am really talking about when somebody says "Hey you should get <Insert software name here>!" if you want to download that... you may have some issues.
On a serious note, let's target gamers. They're going to be a big driving force in OS switch.
I agree completely. Especially as video games gain respect in the art community gaming is going to get really awesome (if interested in the artistic theory of games [not to be confused with game theory] I would have you watch Penny Arcade's Extra Credits). As it stands right now pretty much every decent game out there is either for a console or windows, with the odd one ported to apple computers. Steam IS available on linux now, but …
Labdabeta 182 Posting Pro in Training Featured Poster
Interesting... reading the tutorial page it says "Note that you must also have installed the ImageMagick package in order to be able to read JPG images." I think I know what that means! So far CImg is a good candidate, especially since I intend to edit pixel-level data and jpegs really don't work well that way, but I am a picky person. I am going to keep looking. Any other suggestions? Actually just any way you could define this class is good for me as long as it is weightless and doesnt take extra files to be installed with your program:
#ifndef SOME_GUARD
#define SOME_GUARD
//no globals, otherwise it isnt weightless
typedef SomeType Colour;//yes I am canadian... u need the u!!!
enum ImageType
{
Bitmap,
JPEG,
GIF,
//etc...
};
template <ImageType T>
class Image
{ //private:
//some stuff
public:
Image();//default constructor
Image(const char *);//file-name constructor
#ifdef _STDIO_H_
Image(FILE *);//it definately has its uses! (that way you wouldn't have to keep re-opening files
#endif
#ifdef _GLIBCXX_FSTREAM
Image(fstream &);
#endif
colour &operator()(int,int);//so you can go Img(x,y)
void Save();
};//I would be adding a bit more, but this is all enough!
#endif
Labdabeta 182 Posting Pro in Training Featured Poster
My friend made this one (a little quality lost in resize):
Labdabeta 182 Posting Pro in Training Featured Poster
Here is what I have to say. I used a mac all throughout my childhood, then got a windows computer for school and got used to it. Then when I got really into programming I put a linux partition on my laptop. So I have experience with most OSs and I try to have an unbiased view (even though personally I hate crapples). So here we go... Pro/Con list and ideal users:
Apple OSs: Computer N00bs with money
The good thing about apple computers is that, while saying that they are the most user-friendly is quite an exageration, they tend to need very little maintanance. When they do need maintenance apple stores will be able to help, although it can be very hard to find one near you. On top of that Apple OSs tend to come with a lot of default software and easy to get apps. These programs are not as well designed as more expensive ones, but because they give easy access to some basic computer skills novice computer users are capable of doing near-professional grade work. The two biggest downsides I have found are cost and efficiency. Apples are waaay overpriced. As far as I am concerned there is really no argument there... about a year ago I looked at the price for an apple laptop and found that for just the price of the hard drive upgrade I could create the upgraded version with a slightly larger form-factor. The only difference would be size/weight/lack of …
Labdabeta 182 Posting Pro in Training Featured Poster
Hello. I have been looking long and hard for an image library that meets these criteria that I have for pretty much any library I will use (with some obvious exceptions):
A) Cross-Platform (If at all possible)
B) Weightless (or nearly weightless)
C) Stand-alone (I hate having to include DLLs in my projects, SLLs are fine though)
D) Relatively Simple
E) Standards complient (If there are standards for image loading?)
F) Long-lasting (I hate when I have code that I have to re-write tons of code because a library I used ceases to be supported. [Of course I use modularization to make it relatively easy, it just annoys me])
G) Documented (Even rudimentally is fine)
I want this library to be able to load as many image types as possible and store them in some kind of relatively easy to manipulate array, then allow me to save the data afterwards. Basically I don't want to have to deal with decompressing all the assorted compressed file formats. I will if I have to, but I am certain that somebody already has. Anyways, thanks in advance for any help. :)
Labdabeta 182 Posting Pro in Training Featured Poster
I only recently learned to use GUIs but for the most part I think that it is a complomise. I use photoshop to create my images/textures then load them into my program. For 2d programs I usually draw out my view by hand to try to find out where to place the desired graphical elements. I still have issues designing 3d worlds (although I hear Autodesk Maya is THE tool for it?). From what I have learnt from others it seems that the more your code and your design work together, the better your final project will be. Leaning too far to either of them creates issues. For example, leaning too far to the code side tends to create substandard visuals, leaning too far towards design leads to substandard mechanics. You need both, and lots of both. If you have issues making images, or placing them, try asking a visual arts student (if you can bear it) or at least look up some of the principle theories on visual art and image composition. Realize that just as every frame in a movie should follow the rules of image composition, so should any screen capture of your program, but not at the price of usability and smoothness. Short answer: You really should code and design GUIs. If you use a tool to design it I would suggest trying to find the exact coordinates of everything so that you can put it into the code from the design area.
Labdabeta 182 Posting Pro in Training Featured Poster
Except that the char type is only for standard ASCII characters, sometimes one must deal with Unicode characters, which (if I remember correctly) are stored in ints. As such he only has a few options aside from renaming the second functions. Off the top of my head he could use a charMode() or intMode() setup of some kind. (with either boolean parameters or function pointers, or something)
Labdabeta 182 Posting Pro in Training Featured Poster
I think what Nathan Oliver was trying to say is that cin>>X; and getline(X,Y) do not mix very well. This is because of how those functions modify the internal pointer for cin. Putting cin.get() (without arguments) can sometimes rectify the problem by forcing cin to "catch up" to getline. Basically lets say you type "The quick brown fox jumps over the lazy dog." into the console. STD_IN (cin/getline) gets filled with: "The quick brown fox jumps over the lazy dog.\n". cin reads by word so cin>> will get you these: "The","quick","brown","fox","jumps","over","the","lazy","dog." one at a time (storing its current location internally). By contrast getline will just grab everything before the \n instead. As such lets say you enter the above phrase. getline() should fetch you what you would expect, but then cin>> would probably (I do not have a compiler on this computer so I can't check) give you "The". The point is that getline() does not act like cin>>x until endline. They are seperate mechanisms working on the same stream. It leads to complications. Anyways, cin.get() where NathanOliver suggested could fix your problem.
Labdabeta 182 Posting Pro in Training Featured Poster
Based on how you are describing your problem I think you may be facing an irreducible problem. From what I understand from your post it seems that your problem can be boiled down to this:
Find the subset of n objects from a given set with the highest value, given certain criteria for the set. Or as a function: set<object> problem(int n, int(*value)(const object &), bool(*validSet)(set<object>))
In your case n=3, objects are words with a value attached, and the criteria is that the words do not overlap.
If this indeed is your problem then I think that it is NP-Complete just because it reminds me a lot of the backpack problem. In that case the only solution will have time complexity of O(N^^n) where N is the number of objects, n is how many you want, and ^^ is two Knuth's up arrows (A^^B=A^A^A...^A B times)
As such your solution may very well be optimal for your problem (at least asymptotically).
Of course I have been wrong before too. :)
Labdabeta 182 Posting Pro in Training Featured Poster
Okay, problem solved. It turns out my wireless headset was causing interference. This explained the extremely odd symptoms such as youtube videos that would load a large chunk of their video then suddenly stop as soon as I began listening to them, and why when I got frustrated and put on music the problem got worse. Thanks for your help anyways :)
Labdabeta 182 Posting Pro in Training Featured Poster
Sorry about the lack of information. Both computers are running windows 7. The laptop is the only one with a linux distribution installed since the second one has a small SSD for my system and it is mostly full, so I don't want to add a linux distribution to it (I am thinking of buying a relatively fast HDD just for a linux drive, but have not yet done so). If you think it would help I could give you the exact models of both my wireless adapter card and my router. On my laptop the wireless card is working fine (at least according to the device manager, and my intuition since I can connect to the internet on my Ubuntu partition), but my desktop's might not be. The device manager does say that the device is working fine, but when I look at its lights they seem to turn off then back on every few seconds (the status and activity lights). Interestingly enough skype seems to work (I have only tested the chat system though). The issue with the desktop then is just that no website will load in any reasonable amount of time (google.com takes a solid 5 minutes to load, daniweb takes maybe 10). Also starting in a couple days I will be taking an online course, so if I cannot get the wireless to work I may have to look for another place to live that will have wired internet. I need to know if you …
Labdabeta 182 Posting Pro in Training Featured Poster
In general when faced with such problems you should try to do it yourself first. Typically grabbing pencil and paper is a good start. Write out a number in some base and try to convert it to some other base. First try a full example, then try to convert a generic example from one base to another, then try to do it where both bases are generic (IE: variables) and the number is generic. Once you can derive a nice formula or algorithm for base conversion you can implement a function like this:
char *convert(int initialBase, int finalBase, char *number)
{
#warning todo: implement!
}
If you find that you cannot derive a formula for the general case there is a wonderful website called google that may be able to assist you. Once that fails you may ask here again, this time showing your previous attempts. This forum is not a homework hotline, it is an IT discussion forum.
Nonetheless I will give you some hints:
1) Since you are only dealing with relatively small numbers you can store their value in an integer type, thus you only have to find out how to convert any base to an actual integer value, and then how to output any integer value in any base. So your function can become:
int calculateValue(int base, char *number)
{
#warning todo: implement!
}
char *valueToBase(int value, int base)
{
#warning todo: implement!
}
char *convert(int initialBase, int finalBase, char *number)
{
int …
Labdabeta 182 Posting Pro in Training Featured Poster
Thank you, and sorry about the poor re-post. I will try to do better.
Labdabeta 182 Posting Pro in Training Featured Poster
Hello. As a Software Engineer I admit a slight lack of knowledge with hardware. I am usually quite good with any hardware that is contained within the case, my issues lie in networking. Usually I fix my own computer problems, but now I have a couple networking problems that I frankly have no idea how to solve. I am wondering if anyone here can solve them:
1) My laptop cannot connect to the internet at all while in windows mode. When I "troubleshoot problems" it says the diagnostic policy service isn't running. I have tried manually starting it, but I cannot seem to get it to start. Oddly enough as long as I boot into Ubuntu I have no trouble whatsoever connecting to the internet. (This repair is non-essential since the only reason I want it is because I play certain games that have not yet been ported to Wine so I need internet on my windows partition to play them)
2) ESSENTIAL - I just moved into a new place, and there is no way for me to get wired internet. Luckily they have wireless. So I went out and bought a wireless N adapter and installed it. It worked fine at my house where I tested it, but now in this apartment I am having issues. Basically I can get a bit of internet after 0.5-1.5 hours of messing around with the tp-link software and the router (which I bought, and is also tp-link). However when I do …
Labdabeta 182 Posting Pro in Training Featured Poster
Oops... I rushed to the mark as solved button too fast. The program worked fine while there was a valid solution (7*215=1505) but failed when that line was commented out. Any ideas on why?
#include <iostream>
#include <vector>
using namespace std;
template <typename T>//function DFS(desired,choices=options,ret to hold current)
T NPMenuProblem(T desired, vector<T> options, vector<T> &ret)
{
vector<T> save=ret;
T remainder;
//you can consider the next two variables as best_solution
T min=desired;//best solution has leftover of desired (this is okay, though
// not obviously!)
vector<T> minsol;//this stores the DFS()+choice part
for (int i=0; i<options.size(); ++i)
{
ret=save;//reset the return parameter
if (desired-options[i]>0.0)//stop searching after invalid value
{
ret.push_back(options[i]);//append the current option (+choice)
//this sorta ends up becoming DFS()+choice
remainder=NPMenuProblem(desired-options[i],options,ret);
if (remainder==0)//we win! and ret is already modified! YAY!!!
return 0;
else if (remainder<min)//still a better solution though
{
minsol=ret;
min=remainder;
}
//no else needed... we dont care if we got a worse solution!
}
else if (desired-options[i]==0.0)
{
ret.push_back(options[i]);
return 0;
}
}
//this is return best_solution
ret=minsol;
return min;
}
int main()
{
vector<int> opts;
//opts.push_back(215);
opts.push_back(275);
opts.push_back(335);
opts.push_back(355);
opts.push_back(420);
opts.push_back(580);
vector<int> ret;
int des=1505;
int rem=NPMenuProblem(des,opts,ret);
for (int i=0; i<ret.size()-1; ++i)
cout<<ret[i]<<" + ";
cout<<ret[ret.size()-1]<<" ";
cout<<" = "<<des<<" - "<<rem<<endl;
return 0;
}
Labdabeta 182 Posting Pro in Training Featured Poster
ok thanks! It works now (although the output is odd due to the additional + sign).
Labdabeta 182 Posting Pro in Training Featured Poster
Okay, the issue is that void f(int *a, int b)
is literally identical to void f(int a[], int b)
from the compilers perspective, as such there is a conflict. This is because arrays are just stored as pointers. You can either remove the duplicate functions or rename them to fix the problem.
Labdabeta 182 Posting Pro in Training Featured Poster
No NP-complete problems are not unsolveable... its just that they are unsolveable in POLYNOMIAL time (IE there is no n such that their solution has worst case time complexity of O(x^n) where x is the number of elements in the problem). My solution is definately NOT polynomial (its a simple depth-first search which runs in a^b where a is the depth of the tree (how many prices added together are less than the total) and b is the number of elements (how many prices)) this is exponential time (O(n^x)) which is far worse than polynomial time. My solution can be expressed in pseudo-code as:
function DFS(desired,choices)
best_solution=worst possible solution
for each choice in choices
temp_solution=DFS(desired-choice,choices)+choice //this is simple appending
if temp_solution is better than best_solution
best_solution=temp_solution
return best_solution
Of course since c++ requires a little more work this simple solution gets morphed a little. Nonetheless here is my code, rewritten with the pseudo-code comments next to it:
#include <iostream>
#include <vector>
using namespace std;
template <typename T>//function DFS(desired,choices=options,ret to hold current)
T NPMenuProblem(T desired, vector<T> options, vector<T> &ret)
{
vector<T> save=ret;
T remainder;
//you can consider the next two variables as best_solution
T min=desired;//best solution has leftover of desired (this is okay, though
// not obviously!)
vector<T> minsol;//this stores the DFS()+choice part
for (int i=0; i<options.size(); ++i)
{
ret=save;//reset the return parameter
if (desired-options[i]>0.0)//stop searching after invalid value
{
ret.push_back(options[i]);//append the current option (+choice)
//this sorta ends up becoming DFS()+choice
remainder=NPMenuProblem(desired-options[i],options,ret);
if (remainder==0)//we win! and ret is …
Labdabeta 182 Posting Pro in Training Featured Poster
Hello. I was reading http://xkcd.com/287/ while bored and thus decided to write a program that would solve such np complete problems. Here is what I got:
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
T NPMenuProblem(T desired, vector<T> options, vector<T> &ret)
{
vector<T> save=ret;
T remainder;
T min=desired;
vector<T> minsol;
for (int i=0; i<options.size(); ++i)
{
ret=save;
if (desired-options[i]>0.0)
{
ret.push_back(options[i]);
remainder=NPMenuProblem(desired-options[i],options,ret);
if (remainder==0)
return 0;
else if (remainder<min)
{
minsol=ret;
min=remainder;
}
}
}
ret=minsol;
return min;
}
int main()
{
vector<int> opts;
opts.push_back(215);
opts.push_back(275);
opts.push_back(335);
opts.push_back(355);
opts.push_back(420);
opts.push_back(580);
vector<int> ret;
int des=1505;
int rem=NPMenuProblem(des,opts,ret);
for (int i=0; i<ret.size(); ++i)
cout<<ret[i]<<" + ";
cout<<" = "<<des<<" - "<<rem<<endl;
return 0;
}
The issue is that it doesn't work and I cannot figure out why... any advice?
Labdabeta 182 Posting Pro in Training Featured Poster
I intend to make a program that will hide a message in the parity of each pixel's colour of an image. As such I need access to the actual pixels and ability to write the image back to the file when I am done. The libbmp looks promising! Although it would be nice if I could get per-pixel access to other file types too (even though for some per-pixel access makes very little sense). Thanks. :)
Labdabeta 182 Posting Pro in Training Featured Poster
Ok. Thank you for your code, but it seems as though you are correct in that it is very hard to be able to read ANY bitmap file. Instead of going through all of this hassle I think it might be better to just use a library that can load more image types. I just have no idea which image library to use for easy, fast access to the individual pixels in an image. Any suggestions?
Labdabeta 182 Posting Pro in Training Featured Poster
Hello,
I am making a program that deals with bitmap files and I want to try to load bitmap data manually. The issue is that I cannot find a good resource for exactly what bitmap files can contain. Wikipedia has a decent article, but it is missing some important information. For example, it only explains how BITMAPINFOHEADERs work, but I would need to know how all of them work. Also the examples on wikipedia show integers stored in a sort of interleaved-endianness... I am wondering if normal c-style stdio file io would accurately read these values. Basically I just need a bit of help filling out this class:
class BitmapImage
{
struct{
unsigned short headerField :16;
unsigned int fileSize :32;
unsigned short reserved1 :16;
unsigned short reserved2 :16;
unsigned int startAddress :32;
}BitmapFileHeader;
struct{
//probably a union of the different possible header structs???
}DIBHeader;
struct{
}ExtraBitMasks;
struct{
}ColourTable;
unsigned int gap1,gap2;
struct{
}PixelArray;
struct{
}ICCColourProfile;
public:
void LoadBMP(FILE*);
void SaveBMP(FILE*);
int width();
int height();
unsigned int &operator()(int x, int y);//pixel access
unsigned int alphaMask();
unsigned int redMask();
unsigned int greenMask();
unsigned int blueMask();
unsigned int bpp();
};
Thanks.
Labdabeta 182 Posting Pro in Training Featured Poster
Header files act like a massive copy-paste. When you say #include "header.h" it copies all the code in header.h directly into your code, replacing the #include statement. As such, you can have a namespace (which is a type of c++ construct) inside a header file. So for example:
header.h:
int thisIsGlobal;
namespace myNamespace
{
int thisIsInMyNamespace;
};
main.cpp:
#include <iostream>
#include "header.h"
using namespace std;
using namespace myNamespace;
int main()
{
thisIsGlobal=7;
thisIsInMyNamespace=10;
cout<<thisIsGlobal<<endl<<thisIsInMyNamespace;
return 0;
}
what main.cpp is compiled like:
#include <iostream>
int thisIsGlobal;
namespace myNamespace
{
int thisIsInMyNamespace;
};
using namespace std;
using namespace myNamespace;
int main()
{
thisIsGlobal=7;
thisIsInMyNamespace=10;
cout<<thisIsGlobal<<endl<<thisIsInMyNamespace;
return 0;
}
Labdabeta 182 Posting Pro in Training Featured Poster
I may be wrong, and I know I am not saying it all, but as I understand it the namespace in which cin/cout live (std::) is full of stuff... literally anything that is standard c++ should be in there (thats why they call it std, its short for standard, not sexually transmitted diseases!). cin and cout are actually just global variables that sit inside the std namespace (so I guess they are only sorta global). Their types are istream and ostream respectively. Now the question is what do istream and ostream do? istreams and ostreams (input and output streams) are defined in iostream.h (which incidentally also defines iostreams which combine the uses of istreams and ostreams) and they deal with streaming data. Data streaming is when you send data bit by bit rather than all at once. When you read this your eyes stream the information to your brain, then if you need to remember it, the memory part of your brain streams it to the thinking part of your brain. Similarly iostreams let you stream data into or out of a stream. A stream can be pretty much anything (I don't actually know off-hand how to define a stream, but it shouldnt be too hard to look up). In the case of cin/cout the streams are the console. cout streams "Every age has a language of its own" to the console, which does some magic graphics stuff to show the user the text. Similarly cin asks the console to …
Labdabeta 182 Posting Pro in Training Featured Poster
It isn't skipping it... I'll explain: When you created searchId you defined it as returning void, and taking an integer array (id[]) and a reference to an integer (idNum). Then you told the compiler that right now the function does nothing (that ; actually kinda means {}... kinda). Anyways, normally you would later define what this function does and the compiler would fill it in. You probably think you did that because you recreated searchID and defined what it did. The issue is that IT WASN'T THE SAME! Basically, you can pretend that the compiler called your first function void_searchId_int[]_int& (incorporating its types) and the second one would be called void_searchId_int_int... note that these are not the same! What you need to do is ensure that they match, or define the first one. You have another issue as well, you aren't giving enough info to your searchId function. It will of necessity require an integer array (the IDs to search) as well as the size of said array (to tell you how long to search for) and the value to search. It is the middle one that you are missing. Here is the pseudo-c++ code for what you want to do:
void searchId(int ids[], int idLength, int val);
int main()
{
//you actually got this part pretty much correct as far as I can tell
}
void searchId(int ids[], int idLength, int val)//note that the NAMES of these don't matter, but the TYPES definately do!
{
for each element …
Labdabeta 182 Posting Pro in Training Featured Poster
Your code is incomplete. All you do is read 1 high and 1 low value, then output them... there is no code for anything more. To input more than one value you will need a loop of some sort, and to calculate the average you will need another. Your code isn't working because it isn't done! I feel like maybe you copied the code from somewhere and thus don't understand it, try learning c++ so you can become c++ literate, then you will find that this problem is quite simple. (A good source for learning c++ is learncpp.com)
Labdabeta 182 Posting Pro in Training Featured Poster
I have heard a similar answer before, and I have tried pretty much every combination of X+Y+SPACE+Z possible. I don't think it is a space-bar problem. It seems to me that the character is generated any time I activate the C::B window by clicking in the code editing area (this causes the character to appear, but does not account for all of them). I am still in the dark about this, its a minor thing, but it gets annoying pretty fast. I will try to find out exactly what happens to cause the character, but so far all my attempts have been in vain. I was wondering if anybody had any theories as to what might be causing them so I could test them out.
Labdabeta 182 Posting Pro in Training Featured Poster
Ok, so occassionally as I write my code, a non-printing character is insterted... according to code::blocks this character is actually two characters (\302 and \206). I have done much searching to solve the problem, but a solution has eluded me. I tried using the windows console type command on a file containing the character in question and it printed what I believe to be ASCII values 194 and 134 (first character is sorta like a T for making tables and second is an a with a circle above it). I have tried everything to stop this problem, but have not been successful... any advice?
Labdabeta 182 Posting Pro in Training Featured Poster
Basically, a linked list for a stack will only have one link, pointing to the next element. As such your stack will look something like this:
First->Second->Third->NULL (where -> indicates that the value has a pointer to the value to the right)
In terms of the "standard" linked list struct:
struct LinkedListNode
{
string val;//this doesnt have to be a string, it can be literally anything!
LinkedListNode *next;//this is the key to linked lists
};
With the above structure the example would look like this:
Your stack object would be First and would contain "First" and a pointer to Second, which would contain "Second" and a pointer to Third, which would contain "Third" and a pointer to NULL.
The key to linked list implementations is that when you add a node you can't do it like this:
void addNode(LinkedListNode *myStack)//this is an epic hint!!!
{
LinkedListNode newNode={"New",myStack};
myStack=&newNode;
}
The reason is that newNode will go out of scope. The answer is to use the new operator. IE:
LinkedListNode *newNode=new LinkedListNode;//ta-da!
The new operator makes the new structure "global" (in a way). Other than that a stack is actually pretty easy to implement. If you are stuck on a particular function I would suggest a diagram. Draw each node as a box. In each box put all the values that a node should store, then draw an arrow from the box to whatever its "next" pointer points to. Then using just this diagram implement …
Labdabeta 182 Posting Pro in Training Featured Poster
I think this has to do with a disconnect between cin/cout token and line reads. As I understand it, when you cout<<"Text"; the console gets "Text" put into it and the cin read point goes to 5 (the position after "Text") but getline doesnt use this read point, so it reads starting at "Text". As such if after that you type "test", getline will fill your string with "Texttest" which is not what you want. I would suggest testing this by turning your if (str==option1){stuff} if (str==option2){stuff} into if (str==option1){stuff}else if (str==option2){stuff}else{output some error message}
Hope this helps.
Labdabeta 182 Posting Pro in Training Featured Poster
The issue is that reverselist as you wrote it expects a reference to a pointer of a nodetype, but you passed it num#.head_ptr which is of type pointer which will be converted to a const reference to a pointer of a nodetype (since num1,num2 are declared const in the function definition). Basically you either need to edit reverselist so that it takes const references (I doubt that will work at all!) or you can edit the binary + operator so that it takes binary references (minus the const).
Labdabeta 182 Posting Pro in Training Featured Poster
Yeah, I already changed my storage technique to num+exponent. Also I am working in base 256 (so that I use 1 byte per digit) which allows me to easily use the base 2 arithmetic of the computer. It is true that my last library used decimal... and I quickly realized my mistake. I am not sure how the std::complex system works (I may look into it later) but I want to overload operators so that my arbitrary precision type can be used fully. As such calling sqrt() should always return a valid result, which requires that I have access to imaginary numbers inherently in my data type. I was also considering storing my number as a fraction (numeratorbase,numeratorexponent,denominatorbase,denominatorexponent) but I am not sure how efficient that will be.
That comment about precision... that is genious! I never thought about it like that. I have functions to obtain irrational numbers up to a certain level of precision, but I never thought about the fact that my precision will only drop. I don't think I will use std::array, since manually storing a non-growing dynamically allocated array is trivial.
I guess you definately answered my question about complex number representation. I was never really going to use linked lists, the overhead is silly and it wouldnt be that great a speed boost since I need to use a decent amount of random data access, it was more for the sake of my friends that are helping me out (since we are software engineering …
Labdabeta 182 Posting Pro in Training Featured Poster
Hello,
I am working on an arbitrary precision arithmetic library. I already created a version that just stored numbers as "before decimal point [unsigned array]" and "after decimal point [unsigned array]". The issue is that it is both inefficient and incomplete. I would like to incorporate complex numbers into the system (I am not, however going to incorporate quartic numbers). I am also going to incorporate vectors and matrices. My issue is that I cannot decide how to store complex numbers and (maybe?) vectors. I realize that the optimal approach would probably be to store it as either standard representation [a+bi] or polar representation [re^i(theta)] but I do not yet have the skills to create an algorithm that chooses a format heuristically. I am now faced with the problem of choosing one of the representations. I realize that certain things are easier to represent in standard representation and others in polar, but my question is which do you think would be most efficient and easiest (efficiency trumping ease) once implemented? Also I was wondering if it was worth using a linked list in my number representation rather than a standard dynamically allocated array. I think it would be best to use a dynamically allocated array since I will usually know the required size to store my results (even if I have to over-estimate), but I am wondering if someone can think of a more efficient solution. Thank you.
Labdabeta 182 Posting Pro in Training Featured Poster
Ok, I tried removing the else, and calling the mazeStep from both the if and the else, neither worked... any other ideas?
Labdabeta 182 Posting Pro in Training Featured Poster
Yeah, the problem is that ^ is not the exponent operator in c++. Rather a^b performs the bit xor operator on the two operands. As the bit xor operator requires two integer types to work (or even to make decent sense) it makes no sense to have it work on floats. Instead you have to find another way to implement exponents. (phorce gave the simplest solution to the ^2 problem, ie a*a
)
Labdabeta 182 Posting Pro in Training Featured Poster
Well I am not sure how easy it will be to debug it all, but here is all of my code as it appears when I compile it:
main.cpp:
#include <windows.h>
#include <windowsx.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <vector>
#include "SOIL.h"
#define PLAYER_HEIGHT_STAND 2.0f
#define PLAYER_HEIGHT_CROUCH 1.0f
#define ROOM_HEIGHT 4.0f
#define FLOOR_HEIGHT -1.0f
#define CRUMB_DIM 0.5f
#define CRUMB_H 1.0f
#define INIT_W 10
#define INIT_H 10
#define MAX_CRUMBS 100
#define FOV 45.0
#define NEAR_RENDER 0.01
#define FAR_RENDER 100.0
#define VELOCITY 0.15
#define WALL_WIDTH 0.1
#define WALL_LENGTH 0.5f
#define LOOK_FACTOR 0.2
#define PI180 0.01745329
#include <iostream>
float size_factors[]={10.0f,1.05f,1.1f,1.15f,1.2f,1.25f,1.3f,1.4f,1.5f,1.6f,
1.7f,1.8f,1.9f};
bool Left,Right,Up,Down,W,A,S,D,Space,Ctrl,LMB,RMB,Esc,Comma,O,E;
float dty,dtx,x,y,z,height;
GLuint wall[14],ground,cred,cgreen,cblue,startWall,endWall;
struct WallDef
{
float xi,xf,zi,zf;
};
std::vector<WallDef> walls;
WallDef start,end;
struct CrumbDef
{
float x,z;
GLuint tex;
};
std::vector<CrumbDef> crumbs;
int level,winWidth,winHeight,nred,ngreen,nblue,winLeft,winTop,mazeDimx,mazeDimy;
short mx,my,dy,dx;
#include "MazeMain.h"
#include "MazeStep.h"
LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
void EnableOpenGL(HWND hwnd, HDC*, HGLRC*);
void DisableOpenGL(HWND, HDC, HGLRC);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
winWidth=winHeight=500;
WNDCLASSEX wcex;
HWND hwnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
/* register window class */
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_OWNDC;
wcex.lpfnWndProc = WindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "GLSample";
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);;
if (!RegisterClassEx(&wcex))
return 0;
/* create main window */
hwnd = CreateWindowEx(0,
"GLSample",
"MazeThru!",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
winWidth,
winHeight,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, nCmdShow);
RECT *tmp;
BOOL b=GetWindowRect(hwnd,tmp);
winLeft=tmp->left;
winTop=tmp->top;
/* enable …
Labdabeta 182 Posting Pro in Training Featured Poster
I am not too well versed in how OpenGL works (I am still learning it, there is so much to learn) but I don't think that that is the problem because I have already added movement and view controls, and I have tried looking around and moving to no avail. Here is the code for my movement:
double stheta=sin(dtx*PI180);
double ctheta=cos(dtx*PI180);
int nx=x,ny=y;
if (W||Up||Comma)
{
ny+=VELOCITY*stheta;
nx+=VELOCITY*ctheta;
}
if (A||Left)
{
ny+=VELOCITY*ctheta;
nx+=VELOCITY*stheta;
}
if (S||Down||O)
{
ny-=VELOCITY*stheta;
nx-=VELOCITY*ctheta;
}
if (D||Right||E)
{
ny-=VELOCITY*ctheta;
nx-=VELOCITY*stheta;
}
if (Ctrl)
height=PLAYER_HEIGHT_CROUCH;
else
height=PLAYER_HEIGHT_STAND;
//Collision detection:
//start with start/end:
if (((end.xi==end.xf)&&(//horizontal wall case
(x<(end.xi-WALL_WIDTH)&&nx>(end.xi-WALL_WIDTH))||//to the left
(x>(end.xi+WALL_WIDTH)&&nx<(end.xi+WALL_WIDTH))))||//to the right
((end.zi==end.zf)&&(//vertical wall case
(y<(end.zi-WALL_WIDTH)&&ny>(end.zi-WALL_WIDTH))||//above
(y>(end.zi+WALL_WIDTH)&&ny<(end.zi+WALL_WIDTH)))))//below
{
mazeDimx*=size_factors[level];
mazeDimy*=size_factors[level++];
if (level>19)
{
int sel=MessageBox(NULL,"OMG! You beat all the levels... do you want"
" to play again?","YOU WIN!",MB_YESNO);
if (sel==IDYES)
{
mazeDimx=INIT_W;
mazeDimy=INIT_H;
level=0;
GenMaze(mazeDimx,mazeDimy);
}
else
{
q=true;
return;
}
}
else
{
GenMaze(mazeDimx,mazeDimy);
nred=ngreen=nblue=MAX_CRUMBS;
}
}
if (start.xi==start.xf)
{
if ((x<(start.xi-WALL_WIDTH)&&nx>(start.xi-WALL_WIDTH))||//head-on-ish
(x>(start.xi-WALL_WIDTH)&&x<start.xi))//sneaky edge-on case
nx=start.xi-WALL_WIDTH;
if ((x>(start.xi+WALL_WIDTH)&&nx<(start.xi+WALL_WIDTH))||//head-on-ish
(x<(start.xi+WALL_WIDTH)&&x>start.xi))//sneaky edge-on case
nx=start.xi+WALL_WIDTH;
}
if (start.zi==start.zf)
{
if ((x<(start.zi-WALL_WIDTH)&&nx>(start.zi-WALL_WIDTH))||//head-on-ish
(x>(start.zi-WALL_WIDTH)&&x<start.zi))//sneaky edge-on case
nx=start.zi-WALL_WIDTH;
if ((x>(start.zi+WALL_WIDTH)&&nx<(start.zi+WALL_WIDTH))||//head-on-ish
(x<(start.zi+WALL_WIDTH)&&x>start.zi))//sneaky edge-on case
nx=start.zi+WALL_WIDTH;
}
for (int i=0; i<walls.size(); ++i)
{
if (walls[i].xi==walls[i].xf)
{
if ((x<(walls[i].xi-WALL_WIDTH)&&nx>(walls[i].xi-WALL_WIDTH))||
(x>(walls[i].xi-WALL_WIDTH)&&x<walls[i].xi))//sneaky edge-on
nx=walls[i].xi-WALL_WIDTH;
if ((x>(walls[i].xi+WALL_WIDTH)&&nx<(walls[i].xi+WALL_WIDTH))||
(x<(walls[i].xi+WALL_WIDTH)&&x>walls[i].xi))//sneaky edge-on
nx=walls[i].xi+WALL_WIDTH;
}
if (walls[i].zi==walls[i].zf)
{
if ((x<(walls[i].zi-WALL_WIDTH)&&nx>(walls[i].zi-WALL_WIDTH))||
(x>(walls[i].zi-WALL_WIDTH)&&x<walls[i].zi))//sneaky edge-on
nx=walls[i].zi-WALL_WIDTH;
if ((x>(walls[i].zi+WALL_WIDTH)&&nx<(walls[i].zi+WALL_WIDTH))||
(x<(walls[i].zi+WALL_WIDTH)&&x>walls[i].zi))//sneaky edge-on
nx=walls[i].zi+WALL_WIDTH;
}
}
x=nx;y=ny;
And my code for input:
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RECT *tmp;
short tmpy,tmpx;
switch (uMsg)
{
case WM_CLOSE: …