Infarction 503 Posting Virtuoso

As mentioned, destructors are for freeing resources when an object is being deleted. If the object only uses non-dynamically assigned resources, the destructor will do nothing (this is also the default if you don't explicitly code one). If you do use dynamic allocation for any member data, those need to be freed in the destructor or eles you'll have memory leaks - the default doesn't work here.

As to why it uses the ~, well, I guess that was the decision of the guy who wrote C++. My guess is that the ~ (two's complement) of the constuctor is the destructor, but that's just what my tired brain is making up... :p

Infarction 503 Posting Virtuoso

up to the last bit, I was thinking a snowflake...

Infarction 503 Posting Virtuoso

You could also do something like this:

printf("%4d", (int)ceil(solution - 0.5));

This'll print the rounded value without actually changing the double, so your other numbers should be fine.

#include <math.h> for the ceil function

Infarction 503 Posting Virtuoso

Huh? :confused: Did you read my post thoroughly? Seems not. There are no turns in a static sense.

Yeah, actually, I did read it. As well as the first post in the thread, which declared a turn-based system. Oh well, it's not worth the argument...

Don't mind infarction.

He's just cranky cos he looks like hawking.

Wouldn't you be? :cheesy: ;)

Ouch. You got me on that one. :eek::lol:

Infarction 503 Posting Virtuoso

hm, so if someone posts a guess, then goes away for the day/night and doesnt find out for a few hours whether or not they were right, then the riddle poster confirms their answer, and the solver still hasn't returned, they lose their turn?

You really do just want another spam thread, don't you?

mattyd commented: . -1
Infarction 503 Posting Virtuoso

I just posted a bunch on page 3 of the aforementioned thread and I'm too lazy to repost them :P

Infarction 503 Posting Virtuoso

Cannons.

jBennet is... correct. ;)

Go, Sir.

Because I'm in a cranky mood, I feel like pointing out that you took joeprogrammer's turn. :p

Infarction 503 Posting Virtuoso

Oh, and all the above were from my laptop. This is my desktop from December (fresh FC6 install) and here it is with open windows.

Infarction 503 Posting Virtuoso

oh, these threads are so fun. I might even help the necromancy along :p

Current which I've not had time to fix up since re-installing about a month ago.

December's which I was just getting used to before my laptop went to the shop

This is what I had for a few months before that. And with stuff opened it looked about like this

Infarction 503 Posting Virtuoso

OS or kernel was what I was looking for, but I guess it was too easy.

And my project is actually just a filesystem this time 'round, but we had to do a syscall and a threading library earlier in the quarter. Very fun class, very hard projects T_T

Infarction 503 Posting Virtuoso

Actually, my brain wasn't really functioning either, now that I look at it. The no-brainer algorithm we all jumped on works so long as the coins are multiples of each other, or have a fairly high greatest denominator.

A more complicated algorithm would be about as follows:
1. Take the largest coin possible and subtract it. Now find the best way of creating the remainder, recursively.
2. Then take the next best option from the original amount, and recursively find it's best. If at any point, the best cannot be better than a solution already found, break. Compare this to the result for part 1 and keep the better solution.
3. Repeat 2 as feasible. In this instance, you'd only have to do it twice (once for toonies, once for jonnies), since a $2 is always better than 2x$1.

Infarction 503 Posting Virtuoso

I'm the most essential software to use a computer.
My code is very low level.
I'm a bitch to debug.

What am I?

(more to the point, I hate my current school project :p)

Infarction 503 Posting Virtuoso

To summarize the algorithm provided by Lazarus, you just add as many of the biggest coin you can. Then repeat for the next biggest until you have the amount.

Infarction 503 Posting Virtuoso

And high quality tutorials are fairly hard to come by, I imagine. I've plenty of people trying to show off what they know through horribly inaccurate or poor quality tutorials. I'm glad DaniWeb has high standards ;)

Infarction 503 Posting Virtuoso

extensions:
- adblock plus
- dom inspector
- download statusbar
- fasterfox
- fayt
- tab mix plus
- web developer

No themes installed, but I have the qt theme for gtk installed, so it matches all the KDE apps.

Infarction 503 Posting Virtuoso

good help is hard to find

Infarction 503 Posting Virtuoso

I made this code to do that, but unfortunately it doesn't work...

for(int i = 1; i <= 10; i++)
{
   std::stringstream ss;
   ss << i << ".dat";
 }

thks

I think you're pretty close, actually. The problem is that you're never taking the string off of the stringstream. And since it goes out of scope at the end of the loop, you'll not get a chance later either. Just rough sketch, but what about something like this:

vector<string> filenames;
stringstream ss;
for(int i = 1; i <= 10; i++)
{
  ss << i << ".dat";
  string temp;
  ss >> temp;
  filenames.push_back(temp);
}
// then read through the files...

btw, welcome to the forums. While your post was generally well done, please do familiarize yourself with the rules (e.g. code tags). :)

Infarction 503 Posting Virtuoso

foe: death
you: old age

Infarction 503 Posting Virtuoso

Pretty much, you're trying to give a rough approximation of how much work you'll have to do with respect to the number of items you have. Generally, small overheads or statements that only execute one are ignored. Here's some examples:

int multiply(int a, int b) {
  return a*b;
}

int multiply2(int a, int b) {
  int total = 0;
  for(int i = 0; i < b; i++)
    total += a;
  return total;
}

The first will run in constant time ( O(1) ) since it will take just as long no matter what it's given. The second will run in linear time with respect to b ( O(n) where n=b). As b increases, the amount of work done by the function increases linearly.

Here's another one that works a bit differently:

int binarySearch(int* nums, int numLen, int searchFor)
{
  int beg = 0;
  int end = numLen - 1;
  int mid = (beg + end) / 2;
  do {
    if(nums[mid] == searchFor)
      return mid;
    if(nums[mid] < searchFor) {
      beg = mid;
      mid = (beg+end)/2;
    } else {
      end = mid;
      mid = (beg+end)/2;
    }
  } while(beg < end);
  return -1; // not found
}

In this case, you evaluate and throw 1/2 of the remaining list away. It turns out that the longest it will take to find something in a sorted list is log_2(numLen), so we approximate the runtime with O(log n).

Nested loops are typically a multiplier. If you have something like:

for(int …
Infarction 503 Posting Virtuoso

Geez guys, get some patience or go outside for a few hours. This thread had potential before everyone started whining when they couldn't get it on the first guess. There's plenty of other threads if you just want a spam fest.

We are little airy Creatures,
All of diff'rent Voice and Features,
One of us in Glass is set,
One of us you'll find in Jet,
T'other you may see in Tin,
And the fourth a Box within,
If the fifth you shou'd pursue,
It can never fly from you.

--Jonathan Swift (1667-1745)

vowels

I can't think of a riddle, so someone else can go. Severe lack of sleep ftw.

Infarction 503 Posting Virtuoso

It's 'cause you're calculating the shipping and total cost before the loop. You need to loop and get all the books before calculating the costs. A little re-arranging will probably fix it up.

[edit:] and for the record, it's better to reuse a thread if it's on topic. Otherwise it'll seem like a double post, which is bad.

Infarction 503 Posting Virtuoso

cout is part of the std namespace. You need to either prepend it with std:: (as in std::cout) or put using std::cout; in your file before you use it.

Now that I looked through your code, I'm surprised it compiles. You're not passing the necessary parameter to Properties in main(), and Properties isn't defined in the .h file. Plus, you don't even use cout anywhere.

Infarction 503 Posting Virtuoso

Did the OP want to eliminate duplicates or summarize the number of times they occur? If the latter, jwentings solution is better (as in, mine don't keep counts :o)

Infarction 503 Posting Virtuoso

Surely you've been covering loop constructs in class. Now your teacher wants you to use what you've been taught. Clue: for loops are very handy.

We won't do your homework for you, but post a reasonable attempt and explain what doesn't work and then we'll try to fix it up. ;)

Infarction 503 Posting Virtuoso
if (first != nil)
{
first = newnode; 
}

I'm just not seeing a reason for even having this part. You know first != nil because you set it above. And if you set first = newnode, you'll lose the first n-1 parts of your list. This is why you're only printing one thing at the end, btw.

Your sorting logic really has very little to do with sorting. You need to be reordering the list in the while loop without creating a circular list. You'll have to rewrite the loop to do that. After rewriting, you should probably run through a few example lists by hand to make sure it's doing what you want (i.e. not creating a circle and not losing nodes).

Two other small notes:
- post your code inside code tags.
- add spaces to usingnamespace and constint.

;)

Salem commented: Good say on the code tags and other stuff +6
Infarction 503 Posting Virtuoso

I guess I'm third in the don't-like group. I also prefer to know precisely when people have posted things. The hybrid idea would be nice as well though.

Infarction 503 Posting Virtuoso

I'd like a setup like that, except turning my head that much might tire the neck muscles. And it needs more ambient light so's I don't go blind.

Infarction 503 Posting Virtuoso

Here's two ways to do it:
1) Before you print a value, iterate over the list from beginning to that value and check if it's a duplicate. If it is, skip it. This will make your print loop run in O(n^2) time worst case.
2) Create a hash table. Before printing something, check if it's in the hash table. If not, print it and add it to the table. This will make your print loop use up to double the memory, but on large data sets it will run faster than the first option.

Infarction 503 Posting Virtuoso

I found a fix, figured I'd post if anyone comes across the thread later. The problem was that there was a line in the frame constructor:

setMaximizedBounds(new Rectangle(0,0,0,0));

This keeps the max size pretty small. Only reason I could see the app was because of a setMinimumSize() call elsewhere in the code. The setMaximizedBounds line was added by the NetBeans GUI editor thingy (my partner did that part of it, so I didn't know about that line till I stumbled on it). And yet another reason why I can't stand WYSIWYG editors...

Infarction 503 Posting Virtuoso

A switch is basically a nice clean version of an if-elseif-else chain. Consider the following:

switch(youVar)
{
  case 0:
    foo();
    // do some more stuff
    break;
  case 1:
    // do stuff
    break;
  case 2:
    // do more stuff
    break;
  default:
    // handle accordingly
    break; // not so important for the last one
}

This code is logically the same as above:

if(yourVar == 0) {
  foo();
  // do some more stuff
} else if(yourVar == 1) {
  // do stuff
} else if(yourVar == 2) {
  // do more stuff
} else /* default case */ {
  // handle accordingly
}

There's an intricacy to switches involving case fall-through, but we won't go there yet ;)

Infarction 503 Posting Virtuoso

Ok, a list of things.

First, as Lazaro pointed out, main should be type int, not void. A return 0; is then implied, but most people add it for clarity's sake.

Second, on a matter of style: your use of nil is good, but you might consider using NULL like everyone else does. You can usually get it from <cstdlib> but I think it's in <cstddef> if you're really worried about being precise.

Third, another note of style. Instead of the *(ptr).member syntax, you can use ptr->member. Example:

firs->num = number; // (*first).num = number;
first->next = NULL; // (*first).next = nil; and following note 2

Fourth, more style. Your for loop condition is whacky. Since you wrote it, it's probably obvious to you that you're creating nodes 2-13. Most people reading this would probabaly do a double-take at first. To make 12 more nodes, most people would just do for(int i = 0; i < 12; i++) .

Fifth, yet more style. Putting a blank line between for or if constructs is also confusing. The common styles are same line or next line. And, if the enclosed block only has a single statement, you can get away without braces. With respect to that last, having a blank line looks really weird, to me at least.

Now we get into solving problems (I've just been writing these as I read the code :o)

Sixth: Now that we've hit the real code, time for …

Infarction 503 Posting Virtuoso

Lazaro, please do everyone else a favor and don't quote hugely long threads for a one line reply. Or, if you're quoting to that your reply has context, please trim the quoted part as much as possible. Thanks.

Infarction 503 Posting Virtuoso

>but at the end of the day dwld accelerator dwld at the same speed if no other dwlds r on thru any other s/w.
Sorry I can't read Leet. Could you translate your post to English, please?

As the sun doth set, were none other softwares utilizing the downstream bandwidth, the gains brought forth from a download accelerator wouldst be for naught.

couldn't resist :lol:

Reverend Jim commented: I don't know about useful but it WAS highly amusing. +0
Infarction 503 Posting Virtuoso

After looking at the thread on personality defects, I thought it might be interesting to see what personality types y'all have. Here is a relatively short version of the test. And some of you may already know your type.

I'm INTJ

Infarction 503 Posting Virtuoso

Apparently I'm a robot. And after the last couple days, I'm inclined to agree. Damn these school projects :(

Infarction 503 Posting Virtuoso

Rhetorical question:

Which definition? :twisted:

The truth one, obviously :mrgreen:

Infarction 503 Posting Virtuoso

the local dialect here tends towards rowt-r, for apparent lack of IPA support in [tex] tags...

Infarction 503 Posting Virtuoso

3

proof that all numbers are odd... ;)

QFT :lol::lol:

Infarction 503 Posting Virtuoso

You get a snow cone (hope you used clean snow :P)

(oh don't act like you don't have myspace.)

Not everyone does ;)

I put in my partially done school project... *makes a wish*

Infarction 503 Posting Virtuoso

This is a common trend on all forums, like joeprogrammer said. Assuming most of them are not spam, it could be a situation wherein they come, sign up, find their answers, and leave.

Infarction 503 Posting Virtuoso

generate

Infarction 503 Posting Virtuoso

grand

Infarction 503 Posting Virtuoso

I wouldn't mind seeing more girls around the field. At my University, its an oddity to have a girl in a comp sci class

There's currently 7 in the lab I'm in right now. And 20 guys. It's a start at least...

Infarction 503 Posting Virtuoso

sporal

Infarction 503 Posting Virtuoso

thekashyap, if you haven't already, I suggest you read though this page, especially this section.

Infarction 503 Posting Virtuoso

marble

Infarction 503 Posting Virtuoso

harmless scripts and bleeding nanobots freed memory while attacking a MSFT server.

Infarction 503 Posting Virtuoso

tumbler

Infarction 503 Posting Virtuoso

limber

Infarction 503 Posting Virtuoso

plumber