homework

Simple division function in IA32 assembly

I am working on an assignment for my class. My C++ code calls the _Divide function to take in 2 values to divide and return into 'Result'. To start I move -1 into eax. Once I'm done with the process, my eax keeps returning '-1' as the value. What could I be doing wrong? Here's my assem code: public _Divide .386 .model flat .code _Divide...

How can I make the system call write() print to the screen?

For my OS class I'm supposed to implement Linux's cat using only system calls (no printf) Reading this reference I found it being used to print to a file. I guess I should manipulate ofstream. In the example appears: ofstream outfile ("new.txt",ofstream::binary); How can I make it write to the screen? EDIT: I realized this write() is...

How can I solve Codeforces Beta round#12 Problem D?

Click here to view the problem. I can't come to a solution better than O(n^2) but with n<=500000 this won't work! My Idea is to sort them by (beauty+intellect+richness) and test any of them with those after it. Please help! ...

Using system calls to implement the unix cat command.

For my OS class I have the assignment of implementing Unix's cat command with system calls (no scanf or printf). Here's what I got so far: (Edited thanks to responses) #include <sys/types.h> #include <unistd.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> main(void) { int fd1; ...

sml function that returns a list using exceptions

Hello, I have an sml assignment and one of the questions is to implement a function: findAll (int -> bool) -> binary search tree -> int list I have the following so far: datatype 'a tree = Empty | Node of (int * 'a tree * 'a tree) exception answer of int list fun findAll f Empty = raise answer [] | findAll f (Node(x, l, r)) = ...

What's the easiest way to convert from a bool to string in C#?

I am tempted to use an if ... else ... but I am wondering if there's an easier way? I need to display the true or false result in a message box. ...

Proving that a language is regular by giving a regular expression

I am stumped by this practice problem (not for marks): {w is an element of {a,b}* : the number of a's is even and the number of b's is even } I can't seem to figure this one out. In this case 0 is considered even. A few acceptable strings: {}, {aa}, {bb}, {aabb}, {abab}, {bbaa}, {babaabba}, and so on I've done similar examples where t...

Creating an Exclusive Or from two Deterministic Finite Automatons (Deterministic Finite-State Machines)

Two DFAs (Deterministic Finite Automaton or Deterministic Fininte-State Machines - Which will be called DFAs from here on) Defined over the set DFA 1: L1 = {Q1, E, D1, s1, F} DFA 2: L2 = {Q2, E, D2, s2, F} Q is the list of states. Ex 1, 2, 3, 4 or a, b, c, d E is the the language Ex. 0, 1 D is the transition set Ex. {(a,0,b)} state a ...

How do i print a file in my c++ program with words taken out?

I'm writing a program in c++ and I need to ask the user for a file name, print the file and then reprint it with every 5th word missing. I've gotten as far as to asking them file name, checking for errors and printing out the file, I'm just completely lost on how to reprint it with every 5th word missing, any help? #include <iostream> #...

how fork works with logical operators

main() { if (fork() || (fork() && fork())) printf("AA\n"); else if (!fork()) printf("BB\n"); else printf("CC\n"); } I have run the following code and get the results AA AA CC BB CC BB. While I understand how fork works, I don't understand what it does with logical operators. The teacher in our class wants us to ...

Java Array RGB Manipulation

Ok so lets say I have an int[][] arrayA and an int[][] arrayB. At any given coordinate in this array lies an RGB value. What I want to do is merge the RGB values from arrayA and array2 into a new array, newArray, using a weighted average method. So what I'm doing is extracting the red, green, and blue values from each RGB value like th...

Haskell Question on pattern matching

Hi everyone, I'm trying to write a function that takes in a list and returns true if it is in sorted order and false if not: So far what I have is: myordered [] = True myordered [x] = True myordered list1 | (head list1) <= (head (tail list1)) = myordered(tail list1) | otherwise = False Based on our ...

Running .class file with a .java file

I have a ListTester.java file in which I've created with some unit tests in there to check the built in List class in Java. I have also been given a List.class file to have the junit tests check against to make sure they are correct. However, i'm not sure how to make sure the .class file is utilized by my .java file when it runs the ...

Password masking does not terminate the program when needed

I developed the following application in which I needed to masking the PIN and terminate the program after the user has entered the wrong PIN thrice. However, the program terminates only if i close the stopThread at the beginning (I commented it in the code below), however the password masking does not occur for all the three channces wh...

Why does A work but not B?

I have a custom class written, which I instantiate from an event procedure similar to Private Sub EventHandler For intForCounter = 1 to intUserEntry Dim newObj As New MyClass newObj.Property newObj.Method() Next End Sub The class itself looks something like this Public Property Time As Date 'First atte...

In C++, how to I stop my pointers from being 'overridden' when a function is called again?

Hello, all! I don't know if 'overridden' is the right word here. In my programming class, I have to create a circular list, such that each node node contains a pointer pointing to the next node and the final node points to the first node. In addition, there is a tail node that points to the last node added (its null before any nodes are ...

Code with a potential deadlock

// down = acquire the resource // up = release the resource typedef int semaphore; semaphore resource_1; semaphore resource_2; void process_A(void) { down(&resource_1); down(&resource_2); use_both_resources(); up(&resource_2); up(&resource_1); } void process_B(void) { down(&resource_2); down(&resour...

When will Folder.Size not work in VBScript

http://stackoverflow.com/questions/3871260/how-to-get-the-size-of-the-network-folder-in-asp I have mentioned my problem on the above link and so far I have come to the conclusion that possibly a Folder has been given Protection rights because of which I cannot get it's Folder.Size in vbscript using FileSystem object.Can anyone shed ligh...

Big O complexity of finding cycles in an Undirected graph

Hello! I need to find the complexity of finding all the cycles in a undirected graph consisting of 50 nodes. Moreover, if the graph grows large, will the complexity be changed and what will be it if the network grows considerably large. In addition, if I find only few cycles then how do I find the complexity of finding few cycles in a g...

Having trouble with "if, else" calculation statements

I am using Microsoft Visual Studio 2008 with VB.NET, and in class we were assigned this project: A procedure should calculate a 2% price increase on all red shirts, but a 1% price increase on all other items. In addition to calculating the price increase, the procedure also should calculate the new price. You can use the variab...