Jedi Master
Jedi Master
Posts: 336
Joined: Sun Aug 09, 2009 9:16 am
Allegiance:: Jedi
User avatar
Jedi Master
Jedi Master
Re: C++/C programming discussion

Post by Matthew »

I'd only be willing to help if you swapped vectors for arrays. Learning how to use dynamic arrays will be useful to you, so I recommend it. It's a skill you'll need eventually if you are serious about programming.
Administrator
Administrator
Posts: 3307
Joined: Thu Dec 24, 2009 2:06 am
Allegiance:: Space Rome
Location: ON, Canada
User avatar
Administrator
Administrator
Re: C++/C programming discussion

Post by Scott »

Matthew wrote:I'd only be willing to help if you swapped vectors for arrays. Learning how to use dynamic arrays will be useful to you, so I recommend it. It's a skill you'll need eventually if you are serious about programming.
Wikipedia wrote:C++'s std::vector is an implementation of dynamic arrays
Image
Jedi Master
Jedi Master
Posts: 336
Joined: Sun Aug 09, 2009 9:16 am
Allegiance:: Jedi
User avatar
Jedi Master
Jedi Master
Re: C++/C programming discussion

Post by Matthew »

It's not your own dynamic array. I don't want to look into vectors again right now. I can think about dynamic arrays you make yourself. I'd be the best help if you used malloc.
Administrator
Administrator
Posts: 3307
Joined: Thu Dec 24, 2009 2:06 am
Allegiance:: Space Rome
Location: ON, Canada
User avatar
Administrator
Administrator
Re: C++/C programming discussion

Post by Scott »

Matthew wrote:It's not your own dynamic array. I don't want to look into vectors again right now. I can think about dynamic arrays you make yourself. I'd be the best help if you used malloc.
I'll look into the allocating methods and see what I can come up with.

EDIT:

Didn't mean to kill the conversation. I am quite busy right now so I won't get around trying the new parameter for a while, but I will post it when I do.
Image
Jedi Master
Jedi Master
Posts: 336
Joined: Sun Aug 09, 2009 9:16 am
Allegiance:: Jedi
User avatar
Jedi Master
Jedi Master
Re: C++/C programming discussion

Post by Matthew »

Thats fine. I'll likely be busy getting my iphone application ready. I just got my iphone.
Administrator
Administrator
Posts: 3307
Joined: Thu Dec 24, 2009 2:06 am
Allegiance:: Space Rome
Location: ON, Canada
User avatar
Administrator
Administrator
Re: C++/C programming discussion

Post by Scott »

Matthew wrote:I just got my iphone.
Unlocked?
Image
Jedi Master
Jedi Master
Posts: 336
Joined: Sun Aug 09, 2009 9:16 am
Allegiance:: Jedi
User avatar
Jedi Master
Jedi Master
Re: C++/C programming discussion

Post by Matthew »

Well, it uses a SIM so I guess so? I'm typing this on it on a bus right now :) Hopefully the university has wifi.
Administrator
Administrator
Posts: 3307
Joined: Thu Dec 24, 2009 2:06 am
Allegiance:: Space Rome
Location: ON, Canada
User avatar
Administrator
Administrator
Re: C++/C programming discussion

Post by Scott »

I got my textbook back finally and will do some reading this weekend (attempting to read 600+ pages to finish) and should be much more versed in C++ :)
Image
Jedi Master
Jedi Master
Posts: 336
Joined: Sun Aug 09, 2009 9:16 am
Allegiance:: Jedi
User avatar
Jedi Master
Jedi Master
Re: C++/C programming discussion

Post by Matthew »

I learn things by reading the specific parts I want to know and then trying it out myself. I never follow any particular pattern either. I never read from one side of a book to the other.
Administrator
Administrator
Posts: 3307
Joined: Thu Dec 24, 2009 2:06 am
Allegiance:: Space Rome
Location: ON, Canada
User avatar
Administrator
Administrator
Re: C++/C programming discussion

Post by Scott »

Matthew wrote:I learn things by reading the specific parts I want to know and then trying it out myself. I never follow any particular pattern either. I never read from one side of a book to the other.
Somethings are hard to know if they exist if you never learn about them though. For instance, I would never think of the need for virtual methods because it is has a fairly specific, yet useful purpose, and describing that need would be difficult, so finding it would also be a struggle. I read as much as I can in case I ever need it.
Image
Jedi Master
Jedi Master
Posts: 336
Joined: Sun Aug 09, 2009 9:16 am
Allegiance:: Jedi
User avatar
Jedi Master
Jedi Master
Re: C++/C programming discussion

Post by Matthew »

I learn everything I consider important in the order I wish to learn it. I can always do research on particular features later.
Administrator
Administrator
Posts: 3307
Joined: Thu Dec 24, 2009 2:06 am
Allegiance:: Space Rome
Location: ON, Canada
User avatar
Administrator
Administrator
Re: C++/C programming discussion

Post by Scott »

Matthew wrote:I learn everything I consider important in the order I wish to learn it. I can always do research on particular features later.
Scott wrote:Somethings are hard to know if they exist if you never learn about them though. For instance, I would never think of the need for virtual methods because it is has a fairly specific, yet useful purpose, and describing that need would be difficult, so finding it would also be a struggle. I read as much as I can in case I ever need it.
:)-

EDIT:

Quicksort is really getting to me...Hopefully I can come up with something so I can at least get some guidance because as of now, I'm completely distraught...
Image
Jedi Master
Jedi Master
Posts: 336
Joined: Sun Aug 09, 2009 9:16 am
Allegiance:: Jedi
User avatar
Jedi Master
Jedi Master
Re: C++/C programming discussion

Post by Matthew »

You might like this simple approximate normally distributed random number generator:

Code: Select all

double normal_distribution_rand(double mu, double sigma) {
	float i = 0;
	for (int x = 0; x < 32; x++) {
		i += ((float) rand()/ RAND_MAX) - 0.5;
	}
	i /= 32;
	i *= (sigma/0.05);
	i += mu;
	return i;
}
Administrator
Administrator
Posts: 3307
Joined: Thu Dec 24, 2009 2:06 am
Allegiance:: Space Rome
Location: ON, Canada
User avatar
Administrator
Administrator
Re: C++/C programming discussion

Post by Scott »

The random pivot is not what's getting to me. It's checking the size of an array.
Image
Jedi Master
Jedi Master
Posts: 336
Joined: Sun Aug 09, 2009 9:16 am
Allegiance:: Jedi
User avatar
Jedi Master
Jedi Master
Re: C++/C programming discussion

Post by Matthew »

That algorithm is unrelated. It creates random numbers which are normally distributed with a certain mean and standard deviation. I just made it today. It uses the central limit theory, a theory my maths teacher said was practically useless. :lol:

Checking the size of an array? You should store the array in a structure with an integer keeping the size.
Post Reply