homework

problem in scheme

.............................................. ...

how to count odd and even number with using PROLOG

question is: when we key in mem([1,2,3,4,5]). we will get the output as bellow: odd=3 even=2 my coding is like that but cannot run. can help me check where is my mistake?? mem(X,[X|L]). mem(X,[element|L]):- mem([X,L]). count([],L,L). count([X|H],L1,L2):- write(even), X%2=0,nl, write(odd), X%2>=1,nl, count...

How to find the largest and smallest number in an array in c

I have to find a way to display the Maximum and Minium number in an array, the size of the array is 100 and will not exceed that and there is not need for input validation. The program will keep asking for input until 0 is encountered and it too will get added to the array. I have everything figured out except how to keep track which is...

prove n = Big-O(1) using induction

I know that the relation n = Big-O(1) is false. But if we use induction involving Big-O it can be proved. But the fallacy is we cannot induct Big-O. But my question is how we can disprove the relation by using the constants. The false proof is here, please give me the proof of it being false using the constants. I'm getting confused wit...

I need some help clearing up a problem with sorting a Priority Queue+linked list in Java.

Hello I am trying to implement a Priority Queue in Java from scratch with a linked list but I am having a problem sorting elements on insertion. Here is my program thus far, any help would be massively appreciated. import java.util.Scanner; public class T0 { public static void main(String args[]) { Scanner keyboard = new...

How to create a formating and indentaion code in C#

How to start with creating a program to format C and their derived code into .net style formatted code so that if I input any program. This program can recognize and reformat by properly adding indentation and other things. ...

What's wrong with this For loop?

I can't get this program to count the spaces, I have a feeling there is a logic error in the loop, but I am too inexperienced to figure it out myself. Any tips? System.out.print("Enter a string: "); String myString = keyboard.next(); int numBlanks = 0; //find string length int length = myString.length() - 1; System.out.println("length ...

Conditional Using Bitwise Operators

How is the conditional operator represented using bitwise operators? Edit: Sorry for the poor explanation. It is a homework question where I have to implement the conditional operator using only bitwise operations. It would be simple if if statements were allowed, however it has to be strictly bitwise operators. The function takes in...

How to do Pattern Matching in Common Lisp

I have no idea if there exists a pattern matching function for Common Lisp, nevertheless I have to make my own function. I have no idea about Lisp. Can somebody give heads-up on learning Lisp and most importantly, how to go about doing pattern matching in Lisp. I will have to pass a pattern and a fact and say if they match. An example wo...

Program Runs Continually, but never actually executes anything.

I run the program, but none of my lines execute. When I tell it to stop it prints a red error message. Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Sourc...

Printing char pointer in C - I keep getting bad formatting

I am reading a line from a file containing the names of people, first line contains names of males, and seconds line contains names of females. Then I want to store these names in two arrays, one for males, one for females, however when I print them I get weird things. I'm not sure if I am not reading them correctly, or printing them inc...

different results in visual studio and linux(eclipse)

my code works perfectly in visual studio yet i encounter a problem running it in eclipse. in the function: City* Gps::FindCity(const char* city) { if(city != NULL) { City *tmp = NULL; if (! m_gpsCities.empty()) { for (list<City*>::iterator iter = m_gpsCities.begin(); iter != m_gpsCities.end();...

anti aliasing the lines

I used the pseudocode from wikipedia for wu's antialiasing algorithm, but when i run this code with draw function. i can draw a point when i click on next point everything disappears. It seems there is problem with color issue. Can you please tell what is going on, also this homework requires me to do manual antialiasing without using op...

Prolog: Doubling the value of each element in a list of lists and returning a single list

I need write a set of clauses that take a list of integer lists and return a single list with all the elements doubled. For example: ?- double([[1,2],[3]], X). Yes X = [2,4,6] I have a set of clauses called mega_append that return a single list from a list of lists. For example: ?- mega_append([[1,2],[3]], X). Yes X = [1,2,3] Her...

PHP - How to get IP from "http://" or "www"?

Hey, How do I get something in PHP/Curl to grab the IP of the URL for me? It's going to be a simple interface that fetches URL IP's back for me. E.g. Enter "http://mysite.com" then I hit submit then I should get the IP of the mysite.com back. Please show me how its done thanks. ...

Invalid use of class in C++?

hi im trying to pass some values to a class but it wont let me it says invalid use of class 'Figure' im trying to send 3 values x,y,z and thats all but it wont let me heres what im trying to do... here is the main.cpp and the function that calls the class Figure for (j = 0; j < num_elems; j++) { /* grab and element from the file ...

Dependent Classes in Java

For our assignment we need to write code for a neural network. The way I planned to do it was to write a Node class, which is a node within the network; a Layer class, which is a layer of nodes and a NeuralNet class, which is a network of layers. I'm having a lot of trouble understanding the way Java is designed to work for imports. To ...

How to get predecessor of a church numeral

I'm practicing with sml and I'm doing a small assignment where we have to implement church numerals defined as: datatype 'a church = C of ('a -> 'a) * 'a -> 'a example val ZERO = C(fn (f,x) => x) I have already implemented the functions: create: int -> 'a church churchToInt: 'a church -> int and SUC which returns the su...

string concatenation

I have a nested for loop and I need to convert the output I get to a string. How do I do that? e.g. my loop gives hundreds of values of numbers like: 192 168 11 248 192 168 11 249 192 168 11 250 192 168 11 251 192 168 11 252 192 168 11 253 192 168 11 254 192 168 11 255 How do I concatenate each value as 192.168.11.248 and so on. Ba...

How can I prove 1/n is O(1)?

How can I prove mathematically that 1/n is O(1)? I'm confused on where to start. Any help? ...