homework

barebones sort algorithm

i have been asked to make a simple sort aglorithm to sort a random series of 6 numbers into numerical order. However i have been asked to do this using "Barebones" a theoretical language put forward in the Book Computer Science an overview. Some information on the language can be found here http://www.brouhaha.com/~eric/software/barebo...

How to count bits for a number in Python?

1 -> 1 5 -> 3 10 -> 4 100 -> 7 1000 -> 10 How to count bits for a number in Python? ...

NSString stringWithFormat: with C array?

Hi, I'm writing a program that calculates the Jacobi algorithm. It's written in Objective-C since it runs on a Mac, but the majority is written in standard C. I'm using a two-dimensional C array and an NSArray containing 5 NSTextField labels. The following code yields an EXC_BAD_ACCESS error: for ( int i = 0; i < 5; i++ ) { NSStr...

joining two tables and getting aggregate data

how do i write a query that returns aggregate sales data for California in the past x months. ----------------------- ----------------------- | order | | customer | |-----------------------| |-----------------------| | orderId int | | customerId int | | customerId ...

Taking User Input in Java

I'm creating a program that checks if a word or phrase is a palindrome. I have the actual "palindrome tester" figured out. What I'm stuck with is where and what to place in my code to have the console read out "Enter palindrome..." and then text. I've tried with IO but it doesnt work out right. Also, how do I create a loop to keep go...

LL(1) cannot be ambiguous

How can it be shown that no LL(1) grammar can be ambiguous? I know what is ambiguous grammar but could not prove the above theorem/lemma. ...

Regular Expression

Ohh! this regular expression thing is eating my brain up. I have been reading it from Introduction to Automata Theory, Languages and Computer by Hopcroft, Motwani and Ullman. I have solved a few exercises too but could not solve the following even after trying for almost one hr. The problem is to write a regular expression that defines...

Java swing app can't find image

Hello, I'm making a torpedo game for school in java with swing gui, please see the zipped source HERE. I use custom button icons and mouse cursors of images stored in the /bin/resource/graphics/default folder's subfolders, where the root folder is the program's root folder (it will be the root in the final .jar as well I suppose) which...

Power function in prolog

Exactly what's the prolog definition for power function. I wrote this code and it give some errors I wanna know exact code for the power function. pow(X,0,1). pow(X,Y,Z):-Y1=Y-1,pow(X,Y1,Z1),Z1=Z*X. Anything wrong with this code? ...

C++ problem with string stream istringstream

I am reading a file in the following format 1001 16000 300 12.50 2002 24000 360 10.50 3003 30000 300 9.50 where the items are: loan id, principal, months, interest rate. I'm not sure what it is that I am doing wrong with my input string stream, but I am not reading the values correctly because only the ...

What are these values representative of in C bitwise operations?

Hi All, I'm trying to reverse the order of bits in C (homework question, subject: bitwise operators). I found this solution, but I'm a little confused by the hex values (?) used -- 0x01 and 0x80. unsigned char reverse(unsigned char c) { int shift; unsigned char result = 0; for (shift = 0; shift < CHAR_BITS; shift++) ...

storage classes

What is the difference between a variable declared as an auto and static? What is the difference in allocation of memory in auto and static variable? Why do we use static with array of pointers and what is its significance? ...

Java textfile I/O problem

Hello, I have to make a torpedo game for school with a toplist for it. I want to store it in a folder structure near the JAR: /Torpedo/local/toplist/top_i.dat, where the i is the place of that score. The files will be created at the first start of the program with this call: File f; f = new File(Toplist.toplistPath+"/top_1.dat"); if(!f...

Java : Sorting unsorted array in descending order

hi guys i had an array of objects , i need to know how should i sort my unsorted array in descending order according to the highest value inside objects i need this using for loops not the easy way. i had done this but it seems there is a problem code student[] temp=new student[s.length]; for (int i=0;i<s.length;i++) { if (s[i]...

user input question

My program checks to test if a word or phrase is a palindrome (reads the same both backward and forward, ex "racecar"). The issue I'm having is after someone enters in "racecar" getting it to actually test. In the below code, I marked where if I type in "racecar" and run, Java returns the correct answer so I know I'm right there. But ...

C++: Saving the class object in archived format which is having char * attributes and read it back from file.

Hi all, Assume I have a class class A { char *attr1,*attr2; public: . . . }; How to save the object of this class to file in a binary format and read it back? Thanks. ...

How to compare two arrays of integers order-insensitively

I want Java code that can compare in this way (for example): <1 2 3 4> = <3 1 2 4> <1 2 3 4> != <3 4 1 1> I can't use hashmap table or anything; just pure code without library. I know there are two ways. sort them and compare the array index by index use two for loops and compare the outer index with the inner index. I have been ...

How to determine the best case and worst case of an program(algorithm)?

Suppose I have this program, I want to compare 2 input lists. Assume array A and array B. How do I determine the best case and worst case of the function? Here is my code in [php]: foreach($array_1 as $k){ if(!in_array($k, $array_2)){ array_push($array_2, $k); } } What is the best case and worst case of the for loo...

How to prove this statement of big o notation?

How to prove this: 4n = O(8n) 8n = O(4n)? So what are the C and n0 values for both cases? ...

Why is my file being cleared if I don't save it?

My program is suppose to maintain a collection of Photos in a PhotoAlbum. It begins by reading a folder of photos and adds them to my PhotoAlbum. It then prints a menu that allows the user to list all the photos, add a photo, find a photo, save, and quit the program. Right now if I run my program it will add the 100 photos to the PhotoAl...