2,898 Posted Topics

Member Avatar for mystific

In the constructor, you shouldn't have "int boar..", repeating the type (int) will declare a new variable called "board" that is local to the constructor. so you are initializing a local array board and never initializing the data member "board". So that is why the private data member "board" remains …

Member Avatar for mike_2000_17
0
138
Member Avatar for csha_cs508

From looking at the original problem, it may be required, and it makes the "drawing vertically" problem a bit easier, to sort from most often occurring letter to least occurring letter. But as jonsca said you can do it without sorting too.

Member Avatar for jonsca
0
927
Member Avatar for crodriguez08

One big problem: [CODE] // Variables required for the function ...and all the code that follows... [/CODE] All those variables you declare are not initialized to any value, this can be dangerous and I would suspect (or know) that your compiler is probably complaining a lot when you attempt or …

Member Avatar for crodriguez08
0
475
Member Avatar for sifuhall

Well, the brute force method for this is to just make the list of all games that are to be played (as you have there) for x number of teams (btw. the number of teams have to be even for this to work, otherwise, every day there is one team …

Member Avatar for mike_2000_17
0
114
Member Avatar for vavazoom

First, INFINITY comes up because of a divide-by-zero, so check that you don't have a 0 divisor before dividing. NOTE: your random function is really unnecessarily complicated. Line 59 should read: "b[i] = b[i] + (A[i][j] * s[j]);" notice the index "j" for the vector s. Line 94 should read: …

Member Avatar for mike_2000_17
0
733
Member Avatar for Garrett2011

I see nothing wrong with that. Maybe if you are going to use this trick a lot, either you may want to have global (or namespaced) identifiers (enums) for your units or you may want to attach the unit to the type of the parameters, this way you don't have …

Member Avatar for Garrett2011
0
2K
Member Avatar for bleedi

Did you check the token string you get that should contain the balance? I would suspect it turns out to be "0" instead of "80" or errorneous. 3.35323e-307 is a really weird number, but it is a number very close to 0, so it might actually read 0 and not …

Member Avatar for mrnutty
0
256
Member Avatar for jagan605

Well as the compiler says, and he is always right, call to move() is ambiguous. [CODE] if(a==1) obj.move(); //What is the difference between this. else if(a==0) obj.move(); //And that. [/CODE] You need a final override method when you have a dreaded-diamond. move() needs to be implemented in the watercar class, …

Member Avatar for Fbody
0
560
Member Avatar for ThrasherK

Are you sure that your sort algorithm is doing what you want? or what is asked? In my understanding, you have to take each pair (x,y) and sort them from lowest row-index (which is x) to highest and if x's are the same then put the pair with the lowest …

Member Avatar for ThrasherK
0
188
Member Avatar for ThrustinDuffman

You should clarify what you mean either "read from an array" or "write into an array"... I'm not sure which one you mean. If you have a string that contains all questions.. then I guess you have to do a for-loop for each character until you hit a '?' character …

Member Avatar for ThrustinDuffman
0
167
Member Avatar for Frederick2

They are both correct. Both just make sure that you use the sizeof() function to determine the size of you buffer, like: char buffer[1024]; size_t bufferSize = 1024*sizeof(char); //NOT just 1024. From [url]www.cplusplus.com:[/url] void * memset ( void * ptr, int value, size_t num ); Fill block of memory: Sets …

Member Avatar for Frederick2
0
643
Member Avatar for Garrett2011

I remember, as I was looking into making an ABI for my projects, that there is very loose standards about how a compiler is allowed to lay out the variables of different scopes. From what I recall, public data members are required to be ordered in memory as they are …

Member Avatar for Garrett2011
0
292
Member Avatar for Garrett2011

Man.. you have some twisted questions.. I'm not sure of the rules. What I understand is, you mean what constructors will allow the compiler to build some constant values as literals. As in: [CODE] One some_variable(1,2); //would act like: int some_int(1); //in the sense that the constructor is not called …

Member Avatar for Garrett2011
0
403
Member Avatar for Garrett2011

Optimization by the compiler is always a nebulous matter because it is really up to the compiler to do the optimizations it deems necessary or not. One solution is to use scopes within your functions (I mean "{ ..code.. }" just like that). This way the compiler can more easily …

Member Avatar for Garrett2011
0
422
Member Avatar for Jackie91

Please wrap code in tags next time.. Why do you need to get the numbers a string first? Just use an array of int for "names" and get them from cin directly as integers, just like you do with "input". so change the type of "names" to "int names[5];" and …

Member Avatar for Lerner
0
152
Member Avatar for nahmartin

Look at [URL="http://www.cplusplus.com/reference/iostream/ostream/seekp/"]this[/URL]. When you are about to write the value of No_atoms (which I guess is a dummy value at first), call tellp() before writing the dummy value and save the location value it returns. Afterwards, when you have a real value of No_atoms, use seekp() to get back …

Member Avatar for mike_2000_17
0
432
Member Avatar for ssmg

I'm not sure there is syntaxically correct way provided by C++ (or C legacy stuff), but here is one slightly dirty way to get it done: [CODE] memmove(variable + 6, "YouMary", 7 * sizeof(char)); [/CODE]

Member Avatar for ssmg
0
123
Member Avatar for emps

Yet another alternative.. maybe a bit of overkill or too advanced but if you want to implement this is the future again in a robust manner, you should know this thing you are probably trying to do here is called a "singleton", at least from reading between the lines of …

Member Avatar for emps
0
1K
Member Avatar for angelinrajeesha

@thelamb, any class that has at least one pure virtual method in its declaration or in any of its ancestors (base classes) that has not be overriden (provided an implementation for) is by definition an "Abstract Class". So I don't know what you mean by "complete abstract class" (I guess …

Member Avatar for angelinrajeesha
0
622
Member Avatar for Garrett2011

Well look at [URL="http://beta.boost.org/doc/libs/1_43_0/libs/preprocessor/doc/index.html"]Boost::Preprocessor[/URL], if there isn't a way to do this with that library, there is no way to do it period. There is BOOST_PP_STRINGIFY which takes a non-literal string like just abc and turns it into a literal string "abc". There might be other things of that flavour …

Member Avatar for mike_2000_17
0
208
Member Avatar for Garrett2011

Well, at least with the current draft of C++0x, as implemented by the newest linux g++ compiler (with flag "-std=c++0x"), all of the following work, but not the _exact_ syntax you have up there. [CODE] Temp t = {'a','b'}; Final obj(t); Final obj2({'a','b'}); Final obj3(Temp({'a','b'})); [/CODE]

Member Avatar for mike_2000_17
0
257
Member Avatar for angelinrajeesha

Simple Google search gives [URL="http://www.parashift.com/c++-faq-lite/operator-overloading.html"]this[/URL].

Member Avatar for mike_2000_17
0
88
Member Avatar for solycutema

I guess you could start from a tutorial example (from msdn or somewhere else), just copy/paste the code and start tweaking it, that's the easiest way. Then I guess you will need two programs, one that sends (or at least initializes the communication) and one that receives. Or what you …

Member Avatar for solycutema
0
151
Member Avatar for arsenal_fan

1. Initially the constructor has its own allocated memory (which sizeof(string*) + 2*sizeof(int), for arr (pointer to string) and numAllocated and numUsed (two integers)), then the constructor itself allocates memory for two string objects (size = 2*sizeof(string)). I cannot tell you how big each of there are because that is …

Member Avatar for arsenal_fan
0
170
Member Avatar for Isabelle

You should always test, after you use dynamic_cast, whether the returned pointer is NULL. In this case it shouldn't though, so back to square one. This is not polymorphism (at least not what it usually refers to), you're not supposed to have to perform a dynamic_cast just to call a …

Member Avatar for Isabelle
0
126
Member Avatar for kooia

I'm not sure I understand what you want to accomplish exactly, but consider first using a shell file (.sh in Unix/Linux or .bat in win console). I'm not sure how you should write it because I don't understand the goal, but I'm pretty sure that will be enough. If you …

Member Avatar for kooia
0
171
Member Avatar for Jamesbch

I'm not sure how glutBitmapCharacter works, and these results are very weird indeed. Somehow it must treat each letter as an unclippable entity, which is weird. I used to render text to the screen the old-school way and it works without problem. That is, create 256 display lists, each rendering …

Member Avatar for Jamesbch
0
475
Member Avatar for c++learner

Your call to "cin >> phrase" will by default copy the string before the first space character. Just replace it with "cin.getline(phrase,1024,'\n');" and it will work.

Member Avatar for c++learner
0
184
Member Avatar for amit12

Use a mutex to protect the access to vector. Mutexes are your best friends in multi-threading. A mutex (short for "mutual exclusion") is a thing that is supported by all multi-threading-capable operating systems (the API functions to use may change depending on your OS). What it does is that it …

Member Avatar for Agni
0
334
Member Avatar for ichigo_cool

Well there is a very simple example (in C++): [CODE] //create an interface class for a visible objects. class VisibleObject { public: virtual void render() = 0; //pure virtual function that renders the object. }; class Box : public VisibleObject { private: .. public: void render(); //implement this such that …

Member Avatar for helioptra
0
122
Member Avatar for ichigo_cool

The purpose of a game engine is to facilitate development of one game, then another, then another, etc. (typically a real game is made of 80-90% game-engine code and the rest is the actual game logic, then you have the artistic part, all the 3D models and animations and everything). …

Member Avatar for mike_2000_17
0
122
Member Avatar for mrnutty

You can do a C-style cast (although the compiler will complain) or a reinterpret_cast of the pointer to one with no const restriction. Or as Agni said, just make it mutable. One thing that ticks me though... you say "I have a const-correct method".. well putting "const" at the end …

Member Avatar for Fbody
0
96
Member Avatar for Anocondo

I agree with Stu, you need to post some sign of an effort. Just a start-up idea, use a function (method) to compute the square-of-the-distance between two points (as in a method of class "point"), and you can pretty much use it for all the other methods. @StuXYZ: you should …

Member Avatar for mike_2000_17
0
268
Member Avatar for ota1it1iuss
Member Avatar for shabnamapi
0
424
Member Avatar for AamirH

Well \ is a special character. C++ still caries the remnants of C formatted strings, for good reason. So "\\" actually means the single character "\" and "\" or '' is an error. This is because you use \ to enter special characters like '\t' for tab, '\n' for newline, …

Member Avatar for mike_2000_17
0
109
Member Avatar for hking

@coolzinthis this is pretty straight-forward: [CODE] #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct Person { string first; int votes; }; int computeTotalVotes(Person* candidates, int count) { if(candidates == NULL) return 0; int sum = 0; for(int i = 0; i < count; i++) sum += …

Member Avatar for mike_2000_17
0
248
Member Avatar for ichigo_cool

Well, I have more than 12 years of experience in OOP programming and I started as a teen with 3D game programming (now doing more multi-body dynamics simulation, robotics control software and artificial intelligence). I jumped right into OpenGL from the start and painfully rammed through it all. I recommend …

Member Avatar for mike_2000_17
0
613
Member Avatar for Anyzen

@Agin: I think using generic algorithms goes against the purpose of the exercise.. First, a simple trick is to use a magic number like 0 or MAX_INTEGER or something to mark the already matched values as invalid, then check that a number is valid before looping for matches. Second, the …

Member Avatar for Anyzen
0
164
Member Avatar for katokato

I don't understand how "gradez = grade[] + 1;" is supposed to "try to match what letter grade the user typed". This makes absolutely no sense to me! well, doing "gradez++;" will effectively turn an 'A' into a 'B' and so on. I guess that line was mistyped on this …

Member Avatar for katokato
0
107
Member Avatar for ChaseRLewis

cin is a buffer, it needs to flush, just like cout. There is no guarantee that cin will flush every time you press a key but it is guaranteed that it will flush when you hit enter (just like cout is guaranteed to flush when you write std::endl or "\n"). …

Member Avatar for mike_2000_17
0
88
Member Avatar for aranjan

Wow... your prof. seems to be a d'bag. Not to mention that this is probably the worst possible way to implement a sparse matrix class. And it doesn't seem like your prof has much of an idea about C++ programming. Anyways, the explanation is very vague, but from what I …

Member Avatar for mike_2000_17
0
156
Member Avatar for Agni

the copy() function will try and increment the iterator on std::cin until it finds this null istream_iterator (which I doubt is a correct use, but I'm not so familiar with this class). The problem is that std::cin is special in the sense that every time to increment the iterator it …

Member Avatar for Agni
0
202
Member Avatar for localp

First of all, you need some kind of GUI for this, cin / cout won't be good enough for sure (or a least a lot of trouble). So figure out what you want to use first (Qt, MFC, SDL, whatever..), then you can start to solve that problem. Second, I'm …

Member Avatar for mike_2000_17
0
357
Member Avatar for crapgarden

First of all, inventory should be initialized to contain at least one element for case A (otherwise inventory.begin() is pointing nowhere) and at least two elements for case B,C,D. Then, you have to understand that an iterator is essentially a pointer (not exactly, but it behaves like one), so setting …

Member Avatar for mike_2000_17
1
147
Member Avatar for yap.nice

I think C++ can be hard at first.. a good way to ease into, if you already have some experience with C or other simple procedural languages, is to just keep programming in C but compile in C++ and slowly change you habits from printf to std::cout, from malloc to …

Member Avatar for akilank
0
159
Member Avatar for alokjadhav

You should find out where this error occurs: Is it before writing the first chunk? -something wrong with init. Is it right when you switch to second chunk? -something wrong with the switch. Is there anything special about the point at which the error occurs (middle of a chunk or …

Member Avatar for mike_2000_17
0
2K
Member Avatar for Lusiphur

This site was not mentioned yet, but I like it a lot for all the small details you might overlook while coding but that often are hugely important: [URL="http://www.parashift.com/c++-faq-lite/"]http://www.parashift.com/c++-faq-lite/[/URL] It nicely written and cover a plethora of issues from very simple to very complex.

Member Avatar for mike_2000_17
0
372
Member Avatar for dansnyderECE

Well from what I know if you use shared libs (as it is stated there) than don't expect your library to be completely statically linked.. it is not dependent on how you compile or link your code but how the libraries you use are made. As simple as that. A …

Member Avatar for mike_2000_17
0
355

The End.