homework

Pseudocode/Java Mystery Algorithm

I have an algorithm, and I want to figure it what it does. I'm sure some of you can just look at this and tell me what it does, but I've been looking at it for half an hour and I'm still not sure. It just gets messy when I try to play with it. What are your techniques for breaking down an algoritm like this? How do I analyze stuff like t...

flush() java file handling

What is the exact use of flush()? What is the difference between stream and buffer? Why do we need buffer? ...

Help with a Python Sudoku Verifier with Loops

Hi everyone, Im working on a a sudoku program for python and i need some help. The program will ask input from the user for 9 rows of numbers that hopefully contain the digits 1-9. Once they input all 9 rows the program should then go through each row and verify and see if it satisfies the conditions of a sudoku game. If it doesnt it w...

how to write a simple regular expression pattern matching function in c/c++?

This is a question in my paper test today, the function signature is int is_match(char* pattern,char* string) The pattern is limited to only ASCII chars and the quantification * and ?, so it is relatively simple. is_match should return 1 if matched, otherwise 0. so, how to do, i am really dizzy on this? thanks in advance! ...

python read from keyboard and detect end space or end of linue

I need a python code which does these 1.user enters a char 2.python gets it and displays whether its alphabets or numeric or space or newline char. output will be one of the following - its alphabets its numeric its space its newline ...

Need code for addition of 2 numbers

I am having the numbers follows taken as strings My actual number is 1234567890123456789 from this i have to separate it as s=12 s1=6789 s3=3456789012345 remaining as i said I would like to add as follows 1+3, 2+4, 6+5, 7+6, 8+7, 9+8 such that the output should be as follows 4613579012345 Any help please ...

SQL Query to join different three tables...

hi here we have 3 tables .table1 and table2 have seq as common column.table3 contains terms related to 1 and 2 .now we want to find the number of seq in which each row in table 3 occurs. table 1 col1 col2 seq1 m1 seq2 m1 seq3 m2 seq4 m3 seq1 m2 table2 col1 col2 seq...

Count words, java

Hi, I want to count words. I use the methods hasNextChar and getChar. The sentence may contain all kind of chars. Here's my code: boolean isWord = false; while(hasNextChar()){ char current = getChar(); switch(current){ case ' ' : case '.' : case ',' : case '-' : ...

How to retrieve file names and subdirectory names from a directory in C?

Ok I have something like this: struct dirent *dp; DIR *dir; char fullname[MAXPATHLEN]; char** tmp_paths = argv[1]; //Not the exact code but you get the idea. ... while ((dp = readdir(dir)) != NULL) { struct stat stat_buffer; sprintf(fullname, "%s/%s", *tmp_paths, dp->d_name); if (stat(fullname, &stat_buffer) != 0) ...

c++ for_each() and object functions

I have an assignment that is the following: For a given integer array, find the sum of its elements and print out the final result, but to get the sum, you need to execute the function for_each() in STL only once (without a loop). As of now this is my code: void myFunction (int i) { cout << " " << i << " " << endl; } int main() { ...

Java classes not interacting properly

I have two Java class files: primegen and primecheck sitting in the same directory. primegen calls a public static function from primecheck. primecheck compiles fine. However, I receive the following compilation error in primegen: primegen.java:31: cannot find symbol symbol : variable primecheck location: class primegen } wh...

storage size of ‘names’ isn’t known

I get this error while compiling this .c source file /INIT_SOURCE_BUILD/src/names_list.c:7: error: storage size of ‘names’ isn’t known #include <stdio.h> #include "list.h" int main(){ struct List names; names->size = 3; struct ListElmt michael; struct ListElmt john; struct ListElmt adams; names->head = michael; michael->d...

C++ for_each() and the function pointer

I am try to make the myFunction give me a sum of the values in the array, but I know I can not use a return value, and when I run my program with the code as so all I get is a print out of the values and no sum why is that? void myFunction (int i) { int total = 0; total += i; cout << total; } int main() { int array[] = { 1, 2, 3, 4, 5...

Transmission of files in buckets

a file is transferred from sender to receiver in buckets, each of size 10KB.Each gets filled at the rate of 0.0001KB/ms.Transmission time is 10ms per bucket.The total acknowledgement time from receiver to sender is 100ms.write a formula of total transmissio of a file of size N KB. ...

Bash script, need help with homework assignment

Bash script, need help with ...

Why can't I access private class methods in the class's companion object in Scala?

I'm working on a homework assignment for my object oriented design class, and I'm running into trouble with Scala's companion objects. I've read in a few places that companion objects are supposed to have access to their companion class's private methods, but I can't seem to get it to work. (Just as a note, the meat of the assignment had...

Trouble implementing collision in a breakout clone.

For this program, I've been using the OpenGL-based reni2D library in Visual C++ 2008 Express Edition. The said library is on this webpage: http://www.involuntaryexercise.com/apps/reni2D.zip The problem I get happens when trying to make a brick from the sprite structure. I've been using an array of bricks, but at the moment have restrict...

Beating a greedy algo

For class we have a grid and a bunch of squares on the grid that we need to detect and travel to. We start at (0,0). We scan tiny regions of the grid at a time (for reasons regarding our data structure it's mandatory), and when we detect squares that we need to travel, and then we travel. There are 32 locations on the grid, but we only n...

Checking if an ISBN number is correct

I'm given some ISBN numbers e.g. 3-528-03851 (not valid) , 3-528-16419-0 (valid). I'm supposed to write a program which tests if the ISBN number is valid. Here' my code: def check(isbn): check_digit = int(isbn[-1]) match = re.search(r'(\d)-(\d{3})-(\d{5})', isbn[:-1]) if match: digits = match.group(1) + match.group...

few simple questions about binary search algorithm

(1) consider the SelectionSorter method sort. Which of the following statements is true at the beginning of each iteration of the loop? explain a. for all j, such that 0 <= j < i, 0 <= a[j] <= a[i]. b. for all j, such that 0 <= j < i, a[j] is in its final position in the sorted array. c. for all j, such that 0 <= j < i, a[0...