homework

How does return of pointer work in strcat()

Hey guys I'm trying to figure how pointers are returned by strcat(), so I tried implementing my own strcat() to see how it works. The following is my code for mystrcat(), which works like the real strcat(): char *mystrcat(char *destination, char *source) { char *str = destination; while (*str != '\0') { str++; }...

Solve the problem with O(nlogn) time

Let A[1]<=A[2]<=....<=A[n]. Let X be an arbitrary number. Give an algorithm find all pairs of A[i] and A[j] such that A[j] - A[i] >= X. All numbers are positive integers. If you want to see the original problem. Here it is: Let P = {p1; p2; ; pn} be a set of n points in a 2-dimensional space, where pi = (xi; yi) for each i. Let D =...

Is there a way to find sum of digits of 100! ?

Hey guys , i know there is a way of finding the sum of digits of 100!(or any other big number's factorial) using Python . But i find it really tough when it comes to c++ as the the size of even LONG LONG is not enough. EDIT: i just want to know if there is some other way , i am not aware of which can do the needful. thanks see guys i ge...

How to use assert to test for string

I'm currently trying to test a strcat() function that I wrote myself. Instead of printing the outputs and checking them line by line manually, I've decided to use assert from assert.h. The problem is that assert is showing errors even though the outputs look totally fine. The following is my code: void mystrcat_test() { char str[BUF...

How can I check if a point is below a line or not ?

How can I check if a point is below a line or not ? I've the following data: Line [ {x1,y1}, {x2,y2} ] Points {xA,yA}, {xB,yB} ... I need to write a small algorithm in python to detect points on one side and the other side of the line. thanks ...

How can I check if 2 segments intersect ?

How can I check if 2 segments intersect ? I've the following data: Segment1 [ {x1,y1}, {x2,y2} ] Segment2 [ {x1,y1}, {x2,y2} ] I need to write a small algorithm in python to detect if the 2 lines are intersecting. thanks Update: ...

please let me know the result of this c# program

Class A { virtual m1() { console.writeline("m1() in A"); } } Class B { override m1() { console.Writeline("m2() in B"); } } class C:B { override m1() { console.Writeline("m2() in c"); } } class D { main() { A a=new A(); a.m1(); ///m2() in B B b=new B(); b.m1(); ///m2() in B C c=new ...

Counting duplicate numbers in a list.

Hi, I need help with answering the following question..I have an list: int list = { 1,1,2,3,4,4,5,7,7,7,10}; Now i need to make a program which calculates the double numbers. A number is double when the number before it is the same..I hope you understand..:P So 1 is double, 4 is doubles and we got 2 double in 7,7,7. I hope you can h...

What is the output of the following code ?

int main() { int x=5,y=10,z=15; printf("%d %d %d"); return 0; } Output: 15 10 5 //In Turbo C 4.5 3 Garbage values in gcc compiler My teacher told me when we define the variables like int x=5,y=10,z=15; they are by default taken as auto type and stored in stack.When you try print 3 integer values without using their names ...

Assigning values to pointers in C++

This is a snippet of code I use: void Move::AddToMovesList(Location* &list, int row, int col) { // If the list is empty, create the first item if (list == NULL) list = new Location(row, col); // List exists, so append else list->Add(row, col); } If list is NULL, a new Location should be created and the ...

Recursive MergeSort and counting comparisons

I have written a program that contains 4 sorting methods, selection sort, insertion sort, merge sort, and recursive merge sort. The insertion and selection sort methods run fine and return to me a sorted list and the right amount of comparisons. My merge sort method returns me a sorted list, but my comparisons = 1. My recursive merge sor...

Help with a Color Calculator in Java

I want to know how to paint the background based on the color of the hex value inputed by the user. I have this: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class SimpleColorCalc extends JFrame implements Runnable { ColorPanel cp; JButton show; JTextField hexCode; public SimpleColorCalc() { ...

Computing the longest common subsequence length of two strings in Scheme

I am trying to write a function which computes the length of the longest common subsequence of the two input strings str1 and str2. For example (LCS "scheme" "aheme") would return 4. I need some help getting started. Any ideas how to compute this? I am also limited to the following built in function: (read) (cond) (string-length ...

Reversing elements of an array-Java

Given an array a and two other int variables, k and temp , write a loop that reverses the elements of the array. for(k=0;k<a.length-1;k++){ temp=a[k]; a[k]=a[a.length-1-k]; a[a.length-1-k]=temp; } This is not working. Any idea why? ...

stack and queue with a link list

I have an assignment where i need to implement a stack and a queue with a link list. How would i go about implementing it? would i use a circular link list and i can add to the head and tail? I wasnt looking for any code handouts and i dont think its fair that i got minus two points for asking a generalized question. This is how i think ...

array question - what does this line do?

package javaapplication1; import java.io.*; public class Main { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { NotSimple[] objArray; BufferedReader stdin = new BufferedReader( ...

I'm stuck on my assignment, can I get some feedback? java

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication1; import java.io.*; /** * * @author simon */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { No...

Make unique id of just numbers?

In a program, I am trying to make unique id numbers. I used this way: AtomicInteger count = new AtomicInteger(0); count.incrementAndGet(); int pid = count.get(); System.out.println("pid: " + pid); But my professor said this: Another problem is the pid generation. All you are doing is getting the next integer starting from 0. What ...

C Program..help

c:\users\yan\desktop\glossary_demo.h(2) : error C2236: unexpected 'class' 'defined' c:\users\yan\desktop\glossary_demo.h(2) : error C2144: syntax error : missing ';' before type 'defined' c:\users\yan\desktop\glossary_demo.h(2) : error C2501: 'abstract' : missing storage-class or type specifiers c:\users\yan\desktop\...

Super simple java swing jlist question that I just can't figure out!

Ok, so I am working on a homework assignment, and I am using SWING to make a GUI for a Java project, and I am running into troubles with JList. I have a customer object that I have made and set attributes to, and I want to add the object into a TreeMap. I want to hook up the Treemap so that any and all objects that are in the map will p...