mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

On most systems, there are a number of different accessible clocks, some more precise than others. And the C++11 standard reflects that with the use of std::chrono::system_clock::now() and std::chrono::high_resolution_clock::now(). The actual precision of those clocks is dependent on the system.

I'm afraid Ancient Dragon's statement is somewhat out-dated. For a long time, Windows had a fairly coarse system clock, at around 15ms precision. Now, however, the more typical precision is 1ms or 100us (micro-seconds). Similarly, Linux versions that are not ancient have a system clock set at either 4ms or 1ms precision, and you can configure that.

Furthermore, the standard high_resolution_clock is a clock that tries to exploit the finest possible precision that the system can offer, which is usually the CPU tick counts (which means nano-seconds on > 1 GHz CPUs), to provide high-resolution time values. These days, many computers and systems deliver nano-second "resolution" on that clock. This used to be unreliable, and still might be on some systems, because at that scale, the clock needs time to keep time, so to speak, and you also get issues of precision and multi-core synchronization. What happens is, the value given will be precise to the nano-second, but there can be some drift or readjustments. The intervals between those depend directly on your CPU's capabilities, but it's usually in the micro-seconds range.

For example, on my system (Linux), I get the following resolutions:

Resolution of real-time clock: 1 nanosec.
Resolution of coarse real-time clock: 4000000 nanosec.

The "coarse" …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Sorry that I initially didn't know that stoi existed (it's new).

The stoi function exists at least since GCC 4.6.0, that's how far back I can check, it might have existed even before that.

So, there must be something else going on here. I don't know what.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Did you put Date as a base class? Well, I guess I realize now that it doesn't really make much sense for Person to be a special kind of Date.

Please show the full declaration of the class Person.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You should call the constructor of Date in your initialization list, and you can pass it the three integers you get in the Person constructor:

Person(const char * their_name, const char * email, int aDay, int aMonth, int aYear) : 
       Date(aDay, aMonth, aYear), 
       name(0), email_address(0) {
    name = new char[strlen(their_name) + 1]; 
    strcpy_s(name, strlen(their_name) + 1, their_name); 
    email_address = new char[strlen(email) + 1]; 
    strcpy_s(email_address, strlen(email) + 1, email); 
    cout << "\nPerson(...) CREATING: ";
    printOn(cout);
}

That should work.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

This forum uses English only. Please restate your question in English. It is against the rules to post in another language, so this is a warning.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You have a typo on line 78, in your constructor, you have setz(yin); when it should be setz(zin);.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

the function stoi does not exist. The function you probably meant to use is atoi. And you need to include the <cstdlib> for that one.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I just want to point out one thing: Many programmers hate VB with a passion. So, aiming for something like "great (think of VB6)" is not exactly something most people would find attractive. Most people associate VB with qualificatives like "aweful", "verbose", "archaic", "obsolete", "inflexible", ... in other words, bad.

If you want to make a DSEL that is oriented towards expressing the creation of GUIs (what VB is for), then that's a noble pursuit, but I wouldn't really take VB as an example.

If you just want to be able to write VB-looking code in C++, then I guess that's a good exercise (for DSEL), but not exactly a very appealing thought to most, I would say.

more dificulty is how detect all types of errors;)

You probably can't even imagine how spot-on that is. The best and the worst part of making a DSEL is enforcing the DSEL's rules (i.e., detect errors). It's the best part because it's something you can do, and if you do it well, the results are amazing. It's the worse part because it's really really hard to produce, and requires huge test-harnesses.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Hmmm... it is very much sounding like you want to develop an Domain-Specific Embedded Language (DSEL). C++ is definitely the best, if not the only, programming language that truly allows you to do that. However, making a DSEL is very complicated and requires a very high level of competence in C++ and deep knowledge of the language mechanism.

The main tool that you use for that is template meta-programming, which is a kind of advanced use of templates to perform complex compile-time type-manufacturing. In short, this is really advanced stuff, it takes years to really master that art.

And relying on MACROs to try to do this is not realistic. MACROs are far too limited, and error-prone.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Yeah, the whole "trying to make things simple" road can be a tricky one. It is easy to get obsessed with a particular path and lose sight of the original objective, i.e., making things simpler and easier. It is noble to try to make the user-side code simpler (e.g., avoiding explicit template arguments), but if that means requiring the user to learn a whole new MACRO-based pseudo-language with many pitfalls, it isn't really achieving the real objective, is it? The real objective is to make things as simple as possible, not to eliminate the one thing you perceive as "not simple enough", especially not if it involves introducing some other weird, complicated and tricky scheme.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

My guess is that if you try to compile this with a C++ compiler, it will work just fine. So, why do you need to convert it further?

(btw, I have my suspicions, I'm no fool)

In any case, you need to show that you tried something. We will not just do a "conversion" to C++ for you.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

This is going too deep down a road I cannot follow. There is only so much I can do in terms of giving good advice on how to implement a terrible solution. When going down that road, at some point, there's a rupture, and I have to just say: Don't do that, don't try.

You seem obsessed with this, and I don't see any reason why you are doing this. Why would you want to use a MACRO (with all the problems that come with it) just to avoid a minor inconvenience (explicit template arguments)? The trade-off is terrible.

This whole thing just seems like a classic case of an XY problem.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The FILE* way of reading from a file is just the legacy that was inherited from C. The C++ language was developed with the aim of largely keeping compatibility with C (i.e., C is nearly a subset of C++, with only minor incompatibilities). This means that the entire C standard library is included in the C++ standard library, and in C++, they are preceeded with a "c", as in <cstdlib>, <cmath>, <cstdio>, etc... This is why there are a number of things that are repetitive. By and large, you should just try to stick to "real C++" libraries, like the iostream library.

Another example of that is all the string functionality which you have for C-style strings (char*) in the C <cstring> library, but you should prefer using the C++ string library <string> and the std::string class.

At this point (especially with C++11 additions), the only C library really worth using is <cmath>, which contains all those simple math functions like sine / cosine. Almost everything else has a better and easier-to-use equivalent in the C++ libraries.

And by the way, the code you posted is C code, not C++, although it is also valid C++ code (as I said, by compatibility). The C++ equivalent of that code is:

#include <iostream>
#include <fstream>
#include <string>

int main()
{

    std::ifstream file_in("myfile.txt");
    if( ! file_in.is_open() ) 
        std::cerr << "Error opening file" << std::endl;
    else
    {
        std::string buf;
        while( std::getline(file_in, buf) )
            std::cout << buf << std::endl;
    }

    return 0;
}
furalise commented: Very helpful answer.. Thanks +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Write an example of object-oriented programming in C, including dynamic dispatching mechanisms and run-time type identification. This is something people do often in C, and always in a clumsy, ad-hoc way.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The general approach to find the "range" of elements of the same value is to just look for the lower-bound and upper-bound elements. Like the standard functions std::lower_bound and std::upper_bound. The lower-bound is the first element that is not less-than the value. The upper-bound is the first element for which the value is less-than that element. In other words, if the array does not contain the value you are looking for, then those two elements will be the same, i.e., have a distance of 0 between them. And if the value is in the array, then you will know how many there are.

Modifying the binary-search algorithm to get either one of these bounds is very straight-forward, as shown in the reference pages. Also notice that the "lower-bound" element is also the first equal element, if there is one, meaning that it can be used as the primary algorithm too.

Generally, this is the way you would do it. However, another simple solution is to find an element equal to the value you are looking for, and then, see how many adjacent elements have the same value.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

First of all, from your algorithm, it seems that the array is sorted from greatest value to lowest value, right? Otherwise your if(array[middle] > value) has the wrong < / > sign.

What seems bizarre with your binary-search algorithm is that it doesn't seem to allow for or detect the possibility that the number does not exist anywhere in the range. First, a good binary search algorithm should detect that (and return an error). Second, this is usually indicative of errors in the logic of algorithm.

You have to understand that the iterations of a binary search algorithm always assumes that (1) the sought value is within the bounds (first,last), and possibly, (2) that the bounds have been checked. And generally, if you inforce those assumptions, you will naturally detect error situations, and avoid other special problems.

For example, when you change your bounds, with first = middle + 1; and last = middle - 1;, how do you know that you are not actually increasing the interval, or that you are moving outside the array? If the sought value does not exist in the array, that can happen with this method.

Here is an alternative implementation:

// search (very standard)
int bSearch(double array[], int size, double value)
{
  int first = 0;
  int last = size - 1;

  // first, check the interval:
  if( ( array[first] < value ) || 
      ( array[last]  > value ) )
    return -1;  // "not found"

  // then, check the bounds:
  if( array[first] …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

EVENTS(a)(...) is not a valid way to declare a MACRO, it has to be EVENTS(a,...). In other words, a MACRO declaration cannot be anything else, just a name, a set of parenthesis with a list of names in it. That's it. MACROs are very simple and cannot accommodate anything fancy.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The way you call the function is wrong, and I would not call the f function like that, it's confusing. Try this:

using namespace std;

int double_value(int a)
{
 return 2*a;

}

template <class Sequence  , class UnaryFunction>
Sequence mapf(Sequence c , UnaryFunction f)
{
    for (auto i = 0; i < c.size(); ++i)
    {
        c[i] = f(c[i]);
    }
    return c;
}  

int main()
{
     vector<int> c = {3,4,5};
     mapf(c, double_value);
     return 0;
}

However, one of the issues here is that your iteration of the sequence c is not very "generic". Currently, your function only works for a container that has random-access capabilities (i.e., an indexing operator). If you want to make it more generic, you have to use a less restrictive method to iterate it, in particular, use iterators:

template <class Sequence  , class UnaryFunction>
Sequence mapf(Sequence c , UnaryFunction f)
{
    for (auto it = c.begin(); it != c.end(); ++it)
    {
        *it = f(*it);
    }
    return c;
} 

This way, any sequence container would work, including std::list.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Think of it this way. The steps you need to perform are as follows:

1) Copy the sequence.
2) Iterate through the sequence:
2-1) Replace the element value x by f(x).
3) Return the modified sequence.

The first step is already done, because the sequence c is passed by value, i.e., already copied. All you have left to do is iterate and return. I trust you know how to do that.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Very interesting post. However, one thing that I noticed was that it doesn't seem like there is any incompatibility with the implementation of strtol and atoi. And so, I checked the GNU GCC's implementation of the standard C library, and here is what I found:

__extern_inline int
__NTH (atoi (const char *__nptr))
{
  return (int) strtol (__nptr, (char **) NULL, 10);
}

But, of course, that doesn't change anything of what you said, i.e., you should still just use strtol instead. But I would guess all implementations of atoi are just forwarding to strtol anyways. In other words, it's just a legacy name and specification for the same function, such that the old and unsafe code would still work.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I just replied. I initially thought that nullptr would come back around to answer.

why I do not get answer to my question???

That can vary. Sometimes the post is just too long. Sometimes you don't get the feeling that the original poster is really pull his weight (not making real efforts, just wanting to be spoon-fed the answers / explanations). Sometimes, like in this case, you see that another member (that you trust) has already started to "take care of that thread". Sometimes, it's not interesting to answer. Sometimes the question is unclear. Sometimes the question is just off-putting somehow (bad code formatting, unclear questions, or bad attitude). Sometimes you explain and explain and it seems to lead no-where, so you stop trying. There are many reasons why some threads go unanswered or people lose interest in answering it.

Remember, this is all just voluntary. Like in real life, if you want people to help you, you have to be nice, not too demanding, and just generally make it easy for them to want to help you, or keep helping you.

deceptikon commented: Well said. +0
Assembly Guy commented: Woo +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

1) how did you get the million and the thousand????? in other words , how did the power_to_text[ chunk_count ] work so that the compiler knows where to put the thousand , the million and the billion without making mistakes by putting them in the wrong place or missing them????

At the first iteration, the chunk_count variable is 0, and so, the power_to_text[ chunk_count ] is the element 0 of the array power_to_text, which is "". At the second iteration, chunk_count is 1, and thus, power_to_text[ chunk_count ] is "thousand". And so on, for "million" and "billion". They will be placed in the correct place just because the iterations go in order, I mean, it's a loop. First, the base numbers, then the thousands, then the millions, and so on. That's all there is to explain here.

2) why we do not put the :

n /= 1000;
chunk_count++;

inside the if statement of the while loop like this:

The only reason why the if-statement exists is to avoid adding anything to the number string when there is no number to describe. For example, if you have 2000, then you don't print anything for the base numbers, only when you get to the thousands. The thing is, you need to divide n by 1000 and increment the chunk_count variable regardless of whether the previous (0,999) number was 0 or not. That's why those statements are outside the if-statement.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

@Agilemind: I completely agree. I probably shouldn't have said "compelling", it's more like "promising" or "warranting further investigation". And yes, eliminating the need to use animals in experiments is completely unrealistic, and reckless.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Well, you only need to declare the virtual function you wish to re-implement in the derived class. If you don't need to re-implement it, then you don't need to re-declare it.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Why on earth do you want to do this?

I don't get it. All your MACRO achieves is making everything cumbersome and unclear.

As far as adding some, virtual functions, I don't see why you can't:

#define EVENTS2(Y,X) \
    class X : public Y { public: \
    X(); \
    ~X(); \
    virtual void tests(); \
    }

class b
{
    public:
    virtual void tests(){};
    b()
    {
        tests();
    }
};


EVENTS2(b,a);

a::a()
{
    cout << "oi";
}

a::~a()
{
    cout << "bye";
}

a::tests()
{
    cout << "test";
}

It's that simple.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

sugar should be avoided.

That might be hard, because sugar (in all its forms) form roughly 75% of the total mass of food you eat. This is no accident. The main reason to eat is to get energy, and the most effective source of energy is sugar. Now, by sugar, I mean all sugars, including what is typically called "carbohydrates", which are just longer sugar chains. The reason why "refined sugar" (e.g., table sugar, sweet drinks, etc.) should avoided is because they are absorbed quickly (giving the "rush") and wear out quickly (regulated by your body, i.e., it eliminates the excess sugar, mostly as stored body-fat), and then, you "crash" on low energy and usually go for more sugar, perpetuating this "refined sugar" roller-coaster that adds successive layers of fat to your body. Other kinds of sugars, in naturally sweet foods (e.g., fruits) or in starches (e.g., flour / bread / pasta, rice, potatoes, etc.), are simply longer chains, and get absorbed by your body more slowly, providing a more constant supply of sugar in your blood, giving you a more sustained energy level, getting you going for many hours without feeling hungry or in need of energy.

Reducing sugar to avoid growth of cancer is essentially the same as saying that you will kill yourself to make sure you don't get cancer. The point is, cancer cells feed on the same nutrients that your healthy cells feed on, meaning that you cannot just "starve" them out of …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I don't think that MACROs can be wrapped in parentheses. The rules that the pre-processor works by are far simpler and crude than the rules by which the compiler works. The pre-processor is just a simple parser, a find-and-replace type of parser. So, the MACRO definition should be something like this:

#define events2(y,x) ..

Then, by convention, MACROs should always be written in UPPER-CASE LETTERS. This is a universal convention in C, C++, and any other language featuring a similar pre-processor feature. Do not break that convention. If you do, you will only attract the ire of 99% of the programmers who ever set their eyes on your code. I know that, personally, if I see code that breaks that convention, I will dismiss it, mock it, and shun it with extreme prejudice. In other words, use this instead:

#define EVENTS2(Y,X) ..

Then, I assume you have read somewhere that MACROs are dangerous because they can take almost anything as a "parameter" that is simply substituted into the MACRO's expression (in a "find-and-replace" style). And also, that MACROs are dangerous because they could be put in any weird places. And that one of the guidelines related to these two problems is to be very generous with parentheses, to make sure that whatever is provided as a parameter to the MACRO is going to be inserted between parentheses and that the MACRO expression as a whole should be wrapped in a set of parentheses (because of the …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Go in the bios menu, and disable the "secure boot". It is a Microsoft-controlled "feature" to boot only "approved" operating systems, in other words, it's to prevent you from not using the Windows installation that came with the computer. The good news is, you can disable it, it's required by law to be possible to disable it.

There are probably instructions out there for your brand / model. But usually, it should be quite easy to find once you are in the bios menu (see example), which you can access by following these instructions.

Oh, and my condolences for having to deal with Windows 8, I can't imagine the pain you are going through.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

This should give you a pretty good hint.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

There was a similar thread not too long ago. You might want to give it a read: Need help with university scheduling using Genetic Algorithm

I can't really say much more than what I explained in that thread. And, of course, I agree with gusano79, the tricky part is coming up with a good model / parametrization for the problem, the actual implementation of GA is quite easy (and any reasonably decent programming language will do just fine).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The search algorithm is pretty trivial, that's why you always get back to the "Binary Search Tree". Once you have a binary search tree constructed, searching for a particular element or range is a simple matter of recursively going down the branch which should contain the sought-after value depending on whether it's less-than (go left) or not (go right).

The real trick is constructing that tree, and especially, maintaining it (i.e., dynamically inserting and removing elements from it). This is where different binary search tree methods differ, like mainly the AVL trees and the Red-Black trees. This is where you would add some bits of information and/or design special algorithms to keep the tree reasonably balanced (all leaf nodes at roughly the same depth) after an insertion or deletion. If the tree cannot be kept balanced, the performance is going to degrade, and also, using a recursive search algorithm would start to be dangerous (stack overflow issues).

And then there are other kinds of binary search trees that are more complex because they don't involve a single-dimensional quantity (e.g., like a set of numbers or words in alphabetical order). But all the same principles apply, it's just that everything is more complicated, including the search algorithm (but still pretty straight-forward, compared to the create / insert / remove algorithms).

And then there are different storage methods (e.g., linked-structures, compact layouts, cache-oblivious layouts, or hybrids). But that is a separate issue (memory locality).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

What deceptikon said. In addition, I want to mention that this deduction of the template arguments is also the reason for having the make_foo functions to create class templates in a way that avoids explicitely listing the template arguments. What you would do is this:

template <typename A>
class test
{
  test(A argument)
  {
     cout << argument;
  }
};

template <typename A>
test<A> make_test(A argument) {
  return test<A>(argument);
};


//declare it:
int main()
{
   make_test("hello");

   // or, in C++11, with the 'auto' type deduction:
   auto a = make_test("hello");

   return 0;
};

This is a classic technique, used in many places, for example, in the STL, with class templates like std::pair, std::tuple, std::shared_ptr, etc...

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Here is a nice TED talk about this subject. A bit frightening too.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Yeah, I had noticed that a while back. Me and some others have talked about it on the initial "bug thread" for the new interface.

I guess this may be a forgotten item on Dani's todo list. Thanks for the reminder.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Each year your salary will be increased by some 8-10%

Yeah, right. I want to meet your employer. Yearly raises are more towards the 1-3% range.

after 30 years of life, what exactly we have in our hand ? Bank balance and experience of work in that company? Right ?

Hopefully, after 30 years of working, you will have accomplished some things that you are happy about or proud of. Whether you were on the assembly line of products that people enjoyed or needed, or whether you helped a lot of people, or whether you participated in some big and important projects. That's called taking pride in your work. So, that's one thing that you get, even as a "mere employee". And that's also why you should pick a profession that is fulfilling in that way, whether as employee or entrepreneur.

Also, a lot can change in 30 years. And at that point, your career or personal fulfillment ambitions might no longer be a priority. Priorities might be your children and/or leasure (i.e., retirement-style leasure). Running a business might actually be a burden at that point. I know my uncle seemed kind of relieved when his business went bankrupt in the recession, as he was close to retirement and his children were well off on their own. If it wasn't for the recession he might have had to keep running that business for another 20 years, out of duty to the employees.

So, things are more …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Ahh.. now I see what you mean. I had never noticed the DMCA notice at the bottom of searches. I'm guessing it's fairly new.

I think this just speaks to how insanely poorly constructed this law is. I understand that Google is just following the law, an insane law. By the logic of the law, one could outlaw the entire internet.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

"Who can solve this algorithm?"

Hmmm... you maybe? Usually, when you get an assignment to do, it is because it is something that you could benefit from doing yourself.

We don't provide ready-made answers to assignment questions here, because it helps no-one to do so. And, we aren't tricked that easily either. You must show what you have done towards solving the problem and what specific problems are you stuck on.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Exactly, don't blaim the messenger.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

using methods which would be difficult (though perhaps not impossible) in C++. ....
This specific approach won't work in C++, as it relies on the ability to generate new functions programmatically.

Is that some kind of a joke? Or maybe you're taunting me?

The code you posted is trivial to translate to C++. In fact, I can make almost a literal line-by-line translation of it, here's how it turns out:

bool fp_close_enough(double v1, double v2) { 
  const double tolerance = 0.0001;
  return std::fabs(v2 - v1) < tolerance;
};

template <typename Func>
double fixed_point(Func f, double guess) {
  double next = f(guess);
  if( fp_close_enough(guess, next) )
    return next;
  return fixed_point(f, next);
};

template <typename Func>
std::function<double(double)> deriv(Func g) {
  const double dx = 0.00001;
  return [dx,g](double x) {
    return (g(x + dx) - g(x)) / dx;
  };
};

template <typename Func>
std::function<double(double)> newton_transform(Func g) {
  return [g](double x) {
    return x - (g(x) / deriv(g)(x));
  };
};

template <typename Func>
double newtons_method(Func g, double guess) {
  return fixed_point(newton_transform(g), guess);
};

With a test for it:

int main() {

  std::cout << "The square-root of 2 is " 
            << newtons_method([](double x) { 
                 return 2 - x * x; 
               }, 1.1) << std::endl;

  return 0;
};

If I couldn't have used lambda expressions, the code would just have been a bit more verbose, lambdas are mostly just syntactic sugar.

This kind of code is nothing more than just your day-to-day generic programming stuff, and an example of …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Can you clarify what you mean by "violating the DMCA"? Can you provide some examples of search hits that direct to such "violations"? I really don't understand exactly what you are referring to.

And also, the internet is full of "questionable" content, so I would expect that any decent and respectable search engine would find a lot of that content. Any search engine that would do the opposite (aggressively filtering the searches) is not a search engine I would want to use. After all, a search engine should be a completely neutral player, the same goes for ISPs.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I think it's just a matter of you having fairly low counts and that you've had quite a bit of activity in the past week or so (lots of posts, and several "post comments" with reputation points associated). This can make your rank jump quite a lot. It's all relative. At your ranking levels, a reputation increase of 15 points can make you jump nearly 100 rank positions. And 10 additional posts can make that rank position jump by about 50 position. I think you just didn't notice it, because it jumped quickly.

I don't think that anything changed about the ranking system or points awarded.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The Godfather

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The problem is coming from the fact that you delete the terrain pointer in the destructor, but that pointer points nowhere, i.e., you have not created an object to which it points to using the new operator. You can only call delete on pointers that point to memory allocated with new, which isn't the case here.

Also, your code is dangerous because you have not defined the copy-constructor and assignment operator. Read this tutorial.

And in modern C++, you should never really need to use delete, if you follow the guidelines in this tutorial.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The value of i is whatever its value is in the current iteration of the outer loop. The outer loop is like this:

for(int i = 3; i <= num; i++) {

So, at the first iteration, the value of i is 3. At the second iteration, the value is 4. At the third iteration, the value is 5. And so on, until i is no longer less than or equal to num.

And the value of i - 1 is one less than the value of i.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

+1 on Seasick Steve. I discovered Seasick Steve about six months ago. I really dig his style of music.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

If you have a for-loop like this:

for(int i = 3; i <= num; i++) {
  /* some code */
};

It means that the loop starts by creating a variable called i and initialize it with a value of 3, as if you did int i = 3; on its own. Then, it says that the loop continues as long as i <= num is true, i.e., while i is less-than or equal to num. Finally, it says that between each iteration (i.e., after executing the body of the loop, and before checking the condition), the variable i will be incremented by one, i.e., i++. In other words, the for-loop is equivalent to:

{
  int i = 3;
  while( i <= num ) {
    /* some code */
    ++i;
  };
};

In other words, the logic is this:

for( /* A */ ; /* B */ ; /* C */ ) {
  /* some code */
};

// is equivalent to:

{
  /* A */;
  while( /* B */ ) {
    /* some code */
    /* C */;
  };
};

As for the other for-loop (nested inside the body of the first), it follows the same logic. So, this loop:

for(int n = 2; n <= i - 1; n++)

means that it creates a new variable called n which starts at value 2, then executes the loop while it is less than or equal to i - 1, and increments …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

These stereotypical "welfare queens" do exist, but they are a tiny fraction of the whole, a very tiny fraction. Right-wing rhetorics keep painting the entire population receiving gov. benefits as all being welfare queens / kings, exactly as you've painted it. The reality is, if you were to "solve" that problem, i.e., having "effective controls against abuse of the system", it would barely be noticeable in the overall budget. Right-wing politicians / pundits keep peddling that stereotype in an effort to justify cutting these programs, that's all this is, class warfare.

saying that they are not educated in sex-ed .. well, no offence. that's just crock. by now they're smart enough to have figured out where the babies come from, and what condoms can do.

What do you mean by "by now"? You do understand that teenagers today are the same age as teenagers from previous generations. They haven't lived longer or know more stuff somehow "by now", they still need to be educated and taught about stuff, like sex-ed. The truth is, sex-ed does have a clear effect, like, for example, the fact that teenage pregnancies are most common is areas that prone "abstinence-only" education (or no sex-ed at all). Clearly, if you don't teach teenagers about contraception and protection against STDs, they will have a lack of knowledge about it, which will lead to more teenage pregnancies and STD spreads.

Your argument makes no sense. I could say "by now kids are smart enough to have …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Well, 125 / 10 = 12, because this is using integer arithmetic.

So, because the type of x is int (i.e., cannot represent floating-point numbers), then, the meaning of x / 10 is that the value of x is divided by 10, but the remainder is discarded. The remainder is the "rest", i.e., the part that is not divisible by 10. In the case of 125, the remainder is 5, which is discarded. You can also get the remainder alone by using the "modulus" operator (with symbol %), as r = x % 10; which will give you 5 in the case of 125.

This is a common "pitfall" or thing that surprises beginners. This is just the way it works when all the types involved are integers.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Do you know calculus?

If you have a first-order differential equation like this:

dN/dt = -l * N(t)

You get the following analytical solution:

N(t) = N(t0) * exp(-l*t)

Here's how you get it:
1) Separate the variables:

dN / N(t) = -l * dt

2) Take the integral of both sides:

ln( N(t) ) = -l * t + C

3) Isolate the dependent variable:

N(t) = exp( -l * t + C ) = K * exp( -l * t )

4) Apply the initial condition N(0) = N0:

N(0) = K * exp( 0 ) = K = N0

N(t) = N0 * exp( -l * t )

And that's it. This is the most elementary form of ODE (Ordinary Differential Equation), a particular kind ODE that you usually learn in high-school calculus. Methods like Euler integration are methods used to solve these ODE problems numerically, because most of them cannot be solved analytically, except for the simplest ones like the above example.

And yes, your solution:

N=N0-1*N0*dt;

is correct.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I use mostly public transit. In a big city, or when being a student, it is the most convenient means of transportation. I have a driver's license and occasionally borrow a car for trips that require it. But mostly, having a car is a hassle where I live. Most things are a few blocks away or within a quick subway/bus trip. Most of the cars around my neighborhood only move in order to change side of the street for when the street-cleaning trucks come by.

I do a lot of walking too. A bicycle is also a good / popular choice, but I don't use a bike, personally.