homework

Distribution of a sum S over N diffent operands (b1, b2, .., bn), where b1, b2, ... bn are in a fixed ratio, which is determined by another set of operands (a1,a2, .. an)

If the title is completely misleading/unclear please suggest something relevant and better. Consider a situation where: Candidate A gets a total of Ta votes from N constituencies, with distribution: {a1, a2, a3 .. aN} Candidate B gets a total of Tb votes (Ta and Tb are unrelated, which means Ta < Tb, Ta = Tb & Ta > Tb are all possib...

Need to sum up fields of objects in objectarray, all within the constructor?

I have two classes, one for articles and another for the cart. the cart consists of an object-array, filled with articles. I need to sum up the prices of the articles with a foreach-loop within the constructor. When i write the method (that is probably wrong) within the constructor than its type is not accepted as double. How can i sum ...

How to construct an object with parameters from an array in Java? Or how to add a parameter to a array during construction

I have a class with this constructor: Artikel(String name, double preis){ this.name = name; verkaufspreis = preis; Art = Warengruppe.S; I have a second class with this constructor: Warenkorb(String kunde, Artikel[] artikel){ this.kunde = kunde; artikelliste = artikel; sessionid = s.nextInt(); summe = 0; for(Artikel preis : ar...

How to get rid of type mismatch errors when creating objects into arrays of different type?

This is my class: public class Test { Test(){ new Webshop (new Warenkorb[]{"Max", new Artikel[]{new Artikel("AAA",3.0)}, "Joe", new Artikel[]{new Artikel("BBB",3.0), new Artikel("CCC",3.0)} }, new Warenkorb[]{"Sam"...

assembly code help

Can someone please help me with this assembly code? an explanation of what goes in with each step will be great. thanks! the following code used to implement the instruction sllv $s0, $s1, $s2 which uses the least significant 5 bits of the value in register $s2 to specify the amount register $s1 should be shifted left: ...

Assembly mod algorithm on processor with no division operator

This is pretty basic, but I figure it should be on SO for posterity. I need to implement a simple macro that finds the modulo of two numbers on a processor that doesn't have a division operator (think ARM). I could use division by repeated subtraction, but I don't know if this was the most efficient or easiest to work with. Any suggest...

SIC Assembler I/O question

I've coded a SIC assembler and everything seems to be working fine except for the I/O aspect of it. I've loaded the object code into memory (converted char format into machine representation), but when I call SICRun(); to execute the code, I get an error stating "devf1 cannot be found". I know this is related to the input/output devi...

ArrayList of Integers to one int?

what would be the easiest way to convert an ArrayList of Integers to one int, with the 1st Integer in the list being the 1st number in the int, etc. in Java? For example an ArrayList of Integers: 1 4 6 7 8 3 8 becomes the int value 1467838 ...

assigning character to char pointer

With c-style strings, how do you assign a char to a memory address that a character pointer points to? For example, in the example below, I want to change num to "123456", so I tried to set p to the digit where '0' is located and I try to overwrite it with '4'. Thanks. #include <stdio.h> #include <stdlib.h> int main() { char* num ...

C++ long to string

Yes, it is for homework.... Anyway - how to convert long into string? THANK YOU! ^^ ...

C++ class instances

I am working on intro c++ homework, but I am stuck. Account *GetAccount(int an); int main() { Account *a1,*a2,*b1; a1=GetAccount(123); a2=GetAccount(456); b1=GetAccount(123); if(a1==b1) cout<<"YES"<<endl; else cout<<"NO"<<endl; GetAccount method is supposed to check whether the instance already exists with the same account number...

String Problem in C++

I have problem in string maniputation with c++. The Rule : if the same 'word' is repeated from sentences or paragraph i want it to become an integer. Please help me ?! example input : we prefer questions that can be answered, not just we discussed that. output: 1 prefer questions 2 can be answered, not just 1 discussed 2. 1 we 2 th...

Hard Algorithm Problem: Categorizing Words and Category Values

Hi Guys, We were set an algorithm problem in class today, as a "if you figure out a solution you dont have to do this subject". SO of course, we all thought we will give it a go. Basically, we were provided a DB of 100 words and 10 categories. There is no match between either the words or the categories. So its basically a list of 100 ...

Recursive Function palindrome in Python

I need help writing a recursive function which detects whether a string is a palindrome. But i can't use any loops it must be recursive. Can anyone help show me how this is done. I need to learn this for an upcoming midterm. Im using Python. ...

Serial Port Communication

Hello, I want to send data hex format (0x01) or (0xff) to the port where rs232 cable is connected. I am using the MSCOMM control in VC++ 6.0. Is that the correct way to send the hex data. This is the code I have. CString output; UCHAR data1,data2; data1=0x01; output.Format("%x",data1); m_mscom.SetOutput(COleVariant(output)); data2=0xff;...

How to swap String characters in Java?

How can I swap two characters in a String? For example, "abcde" will become "bacde". Thanks. ...

Generating truth tables for logic expressions in Haskell

I completely forgot about my Haskell project which is due in a couple of hours, any help would be appreciated. The first part is an evaluation function that has the following type signature: evaluate :: Logic Expr -> [(Variable, Bool)] -> Bool This takes a logic expression and a list of assignment pairs as input and returns the value...

How to calculate the inverse key matrix in Hill Cipher algorithm?

I am finding it very hard to understand the way the inverse of the matrix is calculated in the Hill Cipher algorithm. I get the idea of it all being done in modulo arithmetic, but somehow things are not adding up. I would really appreciate a simple explanation! Consider the following Hill Cipher key matrix: 5 8 17 3 Please use the...

How can I write a real time chat using XAJAX and PHP?

How can I write a real time chat using XAJAX and PHP? In other words, is there a way to send xajax responses from the server to multiple clients? Or is the only possibility to check for new messages every few seconds on client side? ...

How does JDBC use abstract factory?

Hi I got an exam in two days and one of the questions is how JDBC uses the abstract factory. I myself is not so skilled with design patterns, so maybe somebody here had the answer. I was thinking that maybe, DriverManager.getConnection(url) is an example of abstract factory, but am not sure. Or is it a factory method? ...