homework

Which windows form control is best for presenting data in a tabular fashion?

I need to present the output on the form in rows and columns. Is there a control to make that task easier? I am using visual studio 2010 and coding in C#. ...

8 Queens using One array

Possible Duplicate: Dumb 8 Queens problem in C++ using goto and backtrack Having problems understanding how to use an one dimensional array to implement the eight queens problem. Also can't figure out how to print the array to print out all possible solutions. #include "stdafx.h" #include <iostream> using namespace std; in...

Java Array Resizing

Ok so I'm supposed to resize an image given to me by half using arrays. I have no idea where to begin. I'm given a function public static int[][] resizeImage(int[][] original, int newWd, int newHt) and I'm supposed to use 2d arrays to map pixels from original to new image. Not sure if Im giving enough info. I dont want the answer, j...

Java Array - Calculate average of surrounding numbers

Ok, so I have an array like so: 1 2 3 4 5 6 7 8 9 Doesn't necessarily have to be any specific size, just showing it so you guys have something to look at. So I have to go through each number, and calculate the average of the numbers that are surrounding it. For example, for the number 1 I have to calculate the average of 2, 5, and 4....

C++: Why does my binary search function run into an infinite loop?

I am having a bit of trouble with creating a Binary Search using a templated dynamic array class and iterators. In my class I have the following function that causes an infinite loop. iterator binarySearch(const T& value) { T * indexOfFirst = begin(); T * indexOfLast = (end() - 1); size_t tempSize = m_size; while (ind...

C 2D linked list

So i have struct node { int number; struct node *next; struct deck{ int number; struct deck *next; }; }; I want to create a 2D linked list. How can i initialize something like this? Thanks. ...

Java: NoSuchElementException, help!

Looking for help with the following code... package pkgPeople; import java.io.File; import java.io.PrintWriter; import java.util.Scanner; public class CreateWithoutSerialization { public static void main(String[] args) throws Exception { BankAccount bankAccount = new BankAccount(0, 0); Person person = new Pers...

Java: Double % formatting question for printf

%s is a string in printf, and %d is a decimal I thought...yet when putting in writer.printf("%d dollars is the balance of %s\r\n", bal, nm); ..an exception is thrown telling me that %d != lang.double. Ideas? ...

How many objects are created here - Java

Possible Duplicate: How to know how many objects will be created with the following code? I have following lines of code in a program String str1 = "abc"; String str2 = str1; String str3 = "abc"; I want to know how many objects are created when above 3 lines of code is executed. ...

Fastest way to sort in Python

What is the fastest way to sort an array of whole integers bigger than 0 and less than 100000 in Python? But not using the built in functions like sort. Im looking at the possibility to combine 2 sport functions depending on input size. ...

Getting the visitors MAC Address using PHP and ipTables

Hey guys, I'm doing a project for class and the professor has asked me to store the visitors IP address and MAC address to my database when they log in. So far after hours of looking around I have been able to get the IP using PHP, but now I need to figure out how to get the MAC address. From my research I can see that using iptables i...

How to tokenize in java without using the java.util tokenizer?

Consider the following as tokens: +, -, ), ( alpha charactors and underscore integer Implement 1.getToken() - returns a string corresponding to the next token 2.getTokPos() - returns the position of the current token in the input string Example input: (a+b)-21) Output: (| a| +| b| )| -| 21| )|...

Java array question..

I have a 3x4 array that I want to rotate left once, so that it becomes a 4x3. Imagine a box of values, and just rotate that box left. Here's the function I wrote: public static int[][] rotLeft(int[][] source) { int[][] newImage=new int[source[0].length][source.length]; for (int i=0;i<source.length;i++) for (int j=0;j<sou...

How do you define an XML schema ID attribute that has a pattern??

This XML documentation seems to say that the ID derived type supports a pattern, but when I try to define one with this code: <complexType name="CourseType"> <attribute name="courseNumber" type="ID"> <pattern value="[A-Z]{2}(\d{3}).(\d{3})" /> </attribute> <attribute name="numOfCredits"...

Program to read a code and count the number of lines in it,do not include comments and blank lines in count

I am trying to create a program which, given an input file, returns the count of all the lines of code in the input file, excluding blank lines and comment lines. I have written the following code, however I need help with how to exclude lines containing comments and blank lines. #include<stdio.h> int main() { int count; char ch...

How to get a sublist without using the sublist method in java

This is what I have right now: public ArrayList subList(int fromIndex, int toIndex){ ArrayList a = new ArrayList(); for (int i=fromIndex;i<toIndex;i++) { a.add(stuff[i]); //stuff is a array of strings } return list; } But is it possible to return the sublist without creating a new array? I am restrict...

Haskell List Reversal Error

Hi guys, I'm writing a list reversal program for haskell. I've got the idea for the list reversal and that has lead to the following code: myreverse list1 | list1 == [] = list1 | otherwise = (myreverse(tail list1)):(head list1) Unfortunately the above code results in the following error: Occurs check: cannot construct the...

Transforming 'X' to 1 or 0, if its > 0 or == 0

Currently, my algorithm is someValue + x. I am trying to figure out how I can transform x to 1 if its greater than 0, or to 0 if its equal to 0. I don't want to use an if-else to produce this, but rather just transform x in my algorithm by itself. For example: If someValue = 20, x = 4. It would produce 20 + 1 = 21. But if x = 0. It wou...

How to cut specified words from string

There is a list of banned words ( or strings to be more general) and another list with let's say users mails. I would like to excise all banned words from all mails. trivial example: foreach(string word in wordsList) { foreach(string mail in mailList) { mail.Replace(word,String.Empty); } } how I can improve this algori...

Why the output of the following 3 programs is like this ?

#include<stdio.h> int add(int,int); int main() { int p=add(10,20); printf("%d",p); return 0; } int add(int x, int y) { int sum=x+y; } O/P: 30 #include<stdio.h> int add(int,int); int main() { int p=add(10,20); printf("%d",p); return 0; } int add(int x, int y) { int sum=x+y; printf("Hello"); } O/P: 5 #include<s...