Unofficial Programming Thread II

Post » Tue May 17, 2011 2:50 pm

Which input data do you have?

I don't have the source code atm because my uni's servers are down so I can't access it, but all the input was just done as letting the user input x, y and z values for each vertex.

Oh yeah, I should probably have specified that it's using user-defined values and then calculating the volume.
User avatar
Len swann
 
Posts: 3466
Joined: Mon Jun 18, 2007 5:02 pm

Post » Tue May 17, 2011 3:49 am

Oh yeah, I should probably have specified that it's using user-defined values and then calculating the volume.

Well that was obvious, but it was unclear whether the input data is just the coordinates of four vertices or something else.

So the input is:
(x1, y1, z1)
(x2, y2, z2)
(x3, y3, z3)
(x4, y4, z4)

Is that correct?
User avatar
victoria johnstone
 
Posts: 3424
Joined: Sat Oct 14, 2006 9:56 am

Post » Tue May 17, 2011 4:29 am

Well that was obvious, but it was unclear whether the input data is just the coordinates of four vertices or something else.

So the input is:
(x1, y1, z1)
(x2, y2, z2)
(x3, y3, z3)
(x4, y4, z4)

Is that correct?

It is indeed. Although each x, y and z value are stored in their own variable in my code and their inputs by the user are also separate ReadDouble functions, if that makes any difference.
User avatar
lucile
 
Posts: 3371
Joined: Thu Mar 22, 2007 4:37 pm

Post » Tue May 17, 2011 12:08 pm

It is indeed. Although each x, y and z value are stored in their own variable in my code and their inputs by the user are also separate ReadDouble functions, if that makes any difference.

No difference.

You're going to need http://en.wikipedia.org/wiki/Plane_%28geometry%29#Define_a_plane_through_three_points and http://mathworld.wolfram.com/Point-PlaneDistance.html.
User avatar
mollypop
 
Posts: 3420
Joined: Fri Jan 05, 2007 1:47 am

Post » Tue May 17, 2011 1:47 pm

I'm currently writing a program that is causing me a lot of headaches, now, the Java itself isn't too complicated, it's more so the maths, so I figured it was worth asking you guys.

Basically, I've got a triangular based pyramid, and I have to find the volume. So I'm using the formula for the volume of a pyramid, of course. I worked out the base using Heron's formula but the issue is that I can't for the life of me figure out the height for when it's an irregular pyramid with the 4th vertex off centre.

edit: Venzar, let me know if you ever figure out how to configure Eclipse so it's not terrible, I am stuck using it at Uni.

Do you mean setting up Eclipse for Android development?
User avatar
Amanda Furtado
 
Posts: 3454
Joined: Fri Dec 15, 2006 4:22 pm

Post » Tue May 17, 2011 4:43 am

[censored] you java, I hate you :brokencomputer:

I tried to write a simple backup application in java (to backup my minecraft server), gave up after a few hours with a massive headache. Switched over to Python ( <3 ) and just finished the application using wxPython for the GUI. It took me 30 minutes and the entire code is 50 lines.
User avatar
Juanita Hernandez
 
Posts: 3269
Joined: Sat Jan 06, 2007 10:36 am

Post » Tue May 17, 2011 5:15 am

Do you mean setting up Eclipse for Android development?

No, just in general. I hate the UI and the layout.
User avatar
Emily abigail Villarreal
 
Posts: 3433
Joined: Mon Aug 27, 2007 9:38 am

Post » Tue May 17, 2011 10:42 am

No, just in general. I hate the UI and the layout.

You can always try http://netbeans.org/, I chose it over Eclipse for the same reasons ^
User avatar
Samantha hulme
 
Posts: 3373
Joined: Wed Jun 21, 2006 4:22 pm

Post » Tue May 17, 2011 8:03 am

You can always try http://netbeans.org/, I chose it over Eclipse for the same reasons ^

Yeah I use Netbeans at home, but unfortunately all my uni labs have to be done via Eclipse for some reason.
User avatar
Your Mum
 
Posts: 3434
Joined: Sun Jun 25, 2006 6:23 pm

Post » Tue May 17, 2011 9:16 am

My uni labs handed out tutorials for Emacs in the into talk <_<
User avatar
Barbequtie
 
Posts: 3410
Joined: Mon Jun 19, 2006 11:34 pm

Post » Tue May 17, 2011 1:20 am

You can always try http://netbeans.org/, I chose it over Eclipse for the same reasons ^

Which version would you recommend for Android development? The full Java package or would the Java SE package be enough?
User avatar
Gill Mackin
 
Posts: 3384
Joined: Sat Dec 16, 2006 9:58 pm

Post » Tue May 17, 2011 12:54 pm

Which version would you recommend for Android development? The full Java package or would the Java SE package be enough?

I'd probably get the full package but it really doesn't matter since you can always update your version of Netbeans via the http://goo.gl/pgrb. Very handy.
User avatar
Destinyscharm
 
Posts: 3404
Joined: Sun Jul 23, 2006 6:06 pm

Post » Tue May 17, 2011 2:17 pm

Hm.... I hate to be that guy who just comes into a thread when he has a question but.... well, I've got another code that isn't executing properly. Right now, after entering the numbers, the program will just immediately crash.

It's supposed to be able to add two ten-thousand digit numbers(I've got it set up to test with smaller numbers for obvious reasons), and it should be able to at least handle adding numbers that don't need carrying(I'm still working that part out- right now I just want to get it to work on numbers like 12+12, then I'll fine tune that part).


#include #include #include int main(){	char firstNumber[2], secondNumber[2], totalNumber[2];	int counter='1';	char digitIndicator='1';	char* charSum="0";	int digitOne, digitTwo, intSum, carry;	printf("Enter your first number here:");	fgets(firstNumber, 11111, stdin);	printf("Enter your second number here:");	fgets(secondNumber, 11111, stdin);	for(counter; counter>=0; counter--){   		digitTwo=secondNumber[digitIndicator]-'0';		digitOne=firstNumber[digitIndicator]-'0';         // supposed to find a single element in a string(e.g. '1' in 31), and convert it to int; I found it on the 'net, so I'm not sure if it might be contributing to problems		intSum=digitTwo+digitOne;		if(intSum<10){			sprintf(charSum, "%d", intSum);			strcat(totalNumber, charSum);			digitOne=0;			digitTwo=0;		}		else if(intSum>10){			carry=intSum%10;			sprintf(charSum, "%d", carry);			strcat(totalNumber, charSum);			digitOne=1;			digitTwo=0;		}		digitIndicator--;	}	strrev(totalNumber);	printf("%s", totalNumber);	return 0;}

User avatar
Matt Gammond
 
Posts: 3410
Joined: Mon Jul 02, 2007 2:38 pm

Post » Tue May 17, 2011 12:47 am

Using Python 2.7 to copy some files, I've got the shutil module imported and os as well.

shutil.copytree(directory, destination, ignore = 'Images')


The problem is the ignore value. No matter what I use I always get an error saying that the ignore must be callable.

I'm trying to copy all the files in the directory EXCEPT a folder named Images.
User avatar
Carolyne Bolt
 
Posts: 3401
Joined: Mon Jul 10, 2006 4:56 am

Post » Tue May 17, 2011 9:24 am

Forums won't let me edit my last post, but I wanted to add a few things:

I noticed that 1 in counter had ' ' around it, giving it an ascii value. I also noticed in the debugger that it seems to crash at strcat, so I must be using that function wrong...
User avatar
Mark Churchman
 
Posts: 3363
Joined: Sun Aug 05, 2007 5:58 am

Post » Tue May 17, 2011 2:05 am

Here's a program I did for my CS class. Just posting it for fun. I hated getting the proof for this program, though (our professor gets us to take a screen shot of our code and our successfully ran program), as I wanted to both show how it worked while it was incorrect, and also have the final guess be correct. I got into a habit of entering the numbers really fast, but because I was going so fast the system time hadn't changed yet, so I got like 5 of the same numbers in a row. Hehe, it was pretty silly.

/*File: Chapter_6_Problem_19a.c	Generates random numbers that the user must guess. Loops until correct */#include #include  //needed for seeding timeint correct(); //prototype for the function that deals with correct answersint incorrect(); //prototype for the function that deals with incorrect answersvoid main(){	int a; //first random number	int b; //second random number	int ans; //the user's input answer	int sum; //the sum of the two random numbers	do{ //loops, allowing the random numbers to be different each time	srand(time(NULL)); //seeds time	a = 1+rand()%10; //first random number	b = 1+rand()%10; //second random number	sum = a + b; //sum of those two	printf("Enter a number between 2 and 20.\n"); /*each random number is between 1 and 10			                                            combined the minimum is 2, and max is 20*/	scanf("%d", &ans); //recieves the user's input	printf("\nThe random number was: %d\n", sum); //prints the sum	printf("You guessed: %d\n", ans); //prints the user's guess	if(ans == sum) //if the answer is correct		correct(); //then a correct message is printed using the called function	else		incorrect(); //if the answer is incorrect, the user is told using the called function	}while(ans != sum); //loops until the user enters the correct answer}int correct(){	switch(1+rand()%4){ //uses a random number between 1 and 4 to decide what to print		case 1:			printf("Correct!\n\n");			break;		case 2:			printf("Good job!\n\n");			break;		case 3:			printf("That's right!\n\n");			break;		case 4:			printf("You win!\n\n");			break;		default:			break;	}}int incorrect(){	switch(1+rand()%4){ //uses a random number between 1 and 4 to decide what to print		case 1:			printf("Incorrect!\n\n");			break;		case 2:			printf("Sorry!\n\n");			break;		case 3:			printf("Try again!\n\n");			break;		case 4:			printf("Wrong, try again!\n\n");			break;		default:			break;	}}

User avatar
steve brewin
 
Posts: 3411
Joined: Thu Jun 21, 2007 7:17 am

Post » Mon May 16, 2011 11:10 pm

So, Java is kind of my bread and butter. It was my major language throughout college, I've spent the last 8 months doing Android development, and in about a month I'm off to a new job, where I'll be doing BlackBerry development. (Both are in Java.)

All good and well, but I wanna learn Python. I've dabbled in Django, but I more or less jumped in without knowing any Python at all. Was a pretty painless experience, and I was able to set up a personal website with it, but the net result is that I can't even do substrings in Python without looking at a reference... :)

Can anyone suggest some good learning material for Python (perhaps even directed at Java programmers), preferably free. Please, no guides for beginning programmers, those get boring too fast. ;) Also, please don't just link me to what you found on Google, I could've http://www.google.com/search?q=python+for+java+programmers. I'm looking for recommendations and personal input. :)

Cheers.


tl;dr Suggest a Java developer some (free) Python courses.
User avatar
Rowena
 
Posts: 3471
Joined: Sun Nov 05, 2006 11:40 am

Post » Tue May 17, 2011 12:38 pm

Here's a program I did for my CS class. Just posting it for fun. I hated getting the proof for this program, though (our professor gets us to take a screen shot of our code and our successfully ran program), as I wanted to both show how it worked while it was incorrect, and also have the final guess be correct. I got into a habit of entering the numbers really fast, but because I was going so fast the system time hadn't changed yet, so I got like 5 of the same numbers in a row. Hehe, it was pretty silly.

/*File: Chapter_6_Problem_19a.c	Generates random numbers that the user must guess. Loops until correct */#include #include  //needed for seeding timeint correct(); //prototype for the function that deals with correct answersint incorrect(); //prototype for the function that deals with incorrect answersvoid main(){	int a; //first random number	int b; //second random number	int ans; //the user's input answer	int sum; //the sum of the two random numbers	do{ //loops, allowing the random numbers to be different each time	srand(time(NULL)); //seeds time	a = 1+rand()%10; //first random number	b = 1+rand()%10; //second random number	sum = a + b; //sum of those two	printf("Enter a number between 2 and 20.\n"); /*each random number is between 1 and 10			                                            combined the minimum is 2, and max is 20*/	scanf("%d", &ans); //recieves the user's input	printf("\nThe random number was: %d\n", sum); //prints the sum	printf("You guessed: %d\n", ans); //prints the user's guess	if(ans == sum) //if the answer is correct		correct(); //then a correct message is printed using the called function	else		incorrect(); //if the answer is incorrect, the user is told using the called function	}while(ans != sum); //loops until the user enters the correct answer}int correct(){	switch(1+rand()%4){ //uses a random number between 1 and 4 to decide what to print		case 1:			printf("Correct!\n\n");			break;		case 2:			printf("Good job!\n\n");			break;		case 3:			printf("That's right!\n\n");			break;		case 4:			printf("You win!\n\n");			break;		default:			break;	}}int incorrect(){	switch(1+rand()%4){ //uses a random number between 1 and 4 to decide what to print		case 1:			printf("Incorrect!\n\n");			break;		case 2:			printf("Sorry!\n\n");			break;		case 3:			printf("Try again!\n\n");			break;		case 4:			printf("Wrong, try again!\n\n");			break;		default:			break;	}}



You know your random number isn't uniform? I don't know if this was intended or not :shrug:
User avatar
Toby Green
 
Posts: 3365
Joined: Sun May 27, 2007 5:27 pm

Post » Tue May 17, 2011 12:47 pm

I've got another code that isn't executing properly.

That's impossible, unless there's a bug in the compiler/interpreter.
User avatar
suzan
 
Posts: 3329
Joined: Mon Jul 17, 2006 5:32 pm

Post » Tue May 17, 2011 11:35 am

I need some help with editing a normal text file in C#. Can anyone help?
User avatar
Strawberry
 
Posts: 3446
Joined: Thu Jul 05, 2007 11:08 am

Post » Tue May 17, 2011 12:42 pm

I need some help with editing a normal text file in C#. Can anyone help?

You can read and write to text files using System and System.IO

example:

string text = "this is some text";System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\yourfile.txt");file.WriteLine(lines);file.Close();





Right, my problem is similar to his ^

I'm trying to copy an entire directory in Java and I'm stuck, I have no idea what I'm doing.

Is it correct that there is no native java module for doing that? (copying files)
User avatar
BaNK.RoLL
 
Posts: 3451
Joined: Sun Nov 18, 2007 3:55 pm

Post » Tue May 17, 2011 11:27 am

I'm trying to copy an entire directory in Java and I'm stuck, I have no idea what I'm doing.

Is it correct that there is no native java module for doing that? (copying files)

There's no File#copy() method, if that's what you're asking, but it's definitely possible using plain Java:

File src = http://forums.bethsoft.com/index.php?/topic/1123394-unofficial-programming-thread-ii/new File("/path/to/source");File dest = new File("/path/to/dest");InputStream in = new FileInputStream(src);OutputStream out = new FileOutputStream(dest);byte[] buffer = new byte[1024];int length;while ((length = in.read(buffer)) > 0){    out.write(buffer, 0, length);}in.close();out.close();


Of course, it's trivial to wrap a copy() function around this and call that for each file in your folder.
User avatar
Theodore Walling
 
Posts: 3420
Joined: Sat Jun 02, 2007 12:48 pm

Post » Tue May 17, 2011 11:28 am

Thanks that's exactly what I was looking for :)
User avatar
Taylor Bakos
 
Posts: 3408
Joined: Mon Jan 15, 2007 12:05 am

Post » Tue May 17, 2011 8:04 am

Does anybody know how to make a non-affine transformation of this type:

x' = f(z)*x,
y' = f(z)*y,
z' = z

in OpenGL? It seems to me that I can't do something like this just by modifying the modelview and projection matrices.
User avatar
Lily
 
Posts: 3357
Joined: Mon Aug 28, 2006 10:32 am

Post » Tue May 17, 2011 4:53 am

Does anybody know how to make a non-affine transformation of this type:

x' = f(z)*x,
y' = f(z)*y,
z' = z

in OpenGL? It seems to me that I can't do something like this just by modifying the modelview and projection matrices.

Except for linear f()s, you can't do it via a matrix alone. Use a vertex shader.
User avatar
Jaki Birch
 
Posts: 3379
Joined: Fri Jan 26, 2007 3:16 am

PreviousNext

Return to Othor Games