homework

OpenGL, problems with GL_MODELVIEW GL_PROJECTION...

Guys, I'm trying to finish up my homework but I'm having some problems here on these models on openGL... any Idea why is my draw not happening? One thing that strange is that if I change to gluPerspective it works.. #include <GL/glut.h> #include <stdlib.h> #include <stdio.h> static int shoulder = 0; static int elbow = 0; void init(voi...

adding nodes to a binary search tree randomly deletes nodes

Hi, stack. I've got a binary tree of type TYPE (TYPE is a typedef of data*) that can add and remove elements. However for some reason certain values added will overwrite previous elements. Here's my code with examples of it inserting without overwriting elements and it not overwriting elements. the data I'm storing: struct data { int n...

HttpURLConnection timeout question

I want to return false if the URL takes more then 5 seconds to connect - how is this possible using java? Here is the code I am using to check if the URL is valid HttpURLConnection.setFollowRedirects(false); HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setRequestMethod("HEAD"); return (con.g...

Correct answer will not output

I made a program that returns the sum of all primes under 2 million. I really have no idea what's going on with this one, I get 142891895587 as my answer when the correct answer is 142913828922. It seems like its missing a few primes in there. I'm pretty sure the getPrime function works as it is supposed to. I used it a couple times befo...

Bitwise Operations -- Arithmetic Operations..

Can you please explain the below lines, with some good examples. A left arithmetic shift by n is equivalent to multiplying by 2n (provided the value does not overflow). And: A right arithmetic shift by n of a two's complement value is equivalent to dividing by 2n and rounding toward negative infinity. If the bina...

Sorting Arrays in Java

How do i sort array elements into ascending order? ...

How to create initializeDB() method for java database

I am working on a Java project for class and have not worked much with incorporating databases into Java. I can't find much on the initializeDB() method, but if I could get some help I would really appreciate it. Below is the code being used for the intializeDB() method: private void initializeDB() { try { // Load the JDB...

Using pipes in Linux with C

Hi, I'm doing a course in Operating Systems and we're supposed to learn how to use pipes to transfer data between processes. We were given this simple piece of code which demonstrates how to use pipes,but I'm having difficulty understanding it. #include <stdio.h> #include <stdlib.h> #include <unistd.h> main() { int pipefd [2],...

linked list problem (with insert)

The problem appears with the insert function that I wrote. 3 conditions must work, I tested b/w 1 and 2, b/w 2 and 3 and as last element, they worked. EDIT; It was my own problem. I did not realize I put MAXINPUT = 3 (instead of 4). I do appreciate all the efforts to help me becoming a better programmer, using more advance and more ...

Having issues with initializing character array

Ok, this is for homework about hashtables, but this is the simple stuff I thought I was able to do from earlier classes, and I'm tearing my hair out. The professor is not being responsive enough, so I thought I'd try here. We have a hashtable of stock objects.The stock objects are created like so: stock("IBM", "International Business M...

Writing a blackjack console program in Java

Hello, I have an assignment of making a blackjack like program in a class. My first problem I am dealing with is creating an array of the cards. The professor wants an array setup with a txt file with the following format. 2 of hearts 2 of diamonds 2 of spades 2 of clubs 3 of hearts 3 of diamonds 3 of spades This goes on till face ca...

what is the code for the following?

a difficult one.. using classes of primitive types in java, like Integer, Float, Long, etc, write a code fragment using a method to double the value of a variable passed as an argument ...

from loop to Nested loops ?

I have this program that returns a factorial of N. For example, when entering 4,,, it will give 1! , 2! , 3! How could I convert this to use nested loops? public class OneForLoop { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a number : "); ...

C++ Boolean problem (comparison between two arrays)

Hello! I have a problem to do. I already did some part of it, however I stuck and don't know exactly what to do next. The question: " You are given two arrays of ints, named A and B. One contains AMAXELEMENTS and the other contains BMAXELEMENTS. Write a Boolean-valued function that returns true if there is at least one point in A that i...

C++ vector of strings, pointers to functions, and the resulting frustration.

So I am a first year computer science student, for on of my final projects, I need to write a program that takes a vector of strings, and applies various functions to these. Unfortunately, I am really confused on how to use pointer to pass the vector from function to function. Below is some sample code to give an idea of what I am talk...

How do you classify languages into regular, context free, and phrase-structure?

If you're given a language, how do you figure out if it's regular, CF but not regular, or phrase-structure but not CF? Is there a good way to attack this problem? I could randomly try to make FAs or PDAs, but I feel like there's a better way to do it. Classic example: L = { a^n b^n c^n | n >= 0 } Where would one start? Thanks. ...

String Vector program exits before input

So, I have a project that must add, delete, and print the contents of a vector... the problem is that, when run the program exits before I can type in the string to add to the vector. I commented the function that that portion is in. Thanks! #include <iostream> #include <cstdlib> #include <vector> #include <string> using namespace std...

Help with Btree homework

I need to do a preorder traversal of a Btree, and among other things, print the following information for each page (which is the same thing as a node): The B-Tree page number The value of each B-Tree page pointer (e.g., address, byte offset, RRN). My questions are: 1. How do you figure out the byte offset? What is it offset from? 2....

basics of c++ encapsulation

I have a task to create class Encapsulation, with fields in available encapsulation sections. Then I must create an application showing all allowed and forbidden methods of fields access. What are the encapsulations sections in c++ ? And what methods apart from object.field or *object->field are there anyway ? ...

C++ Why isn't call by reference needed for strcpy()

I have a homework assignment with a number of questions. One is asking why the strcpy() function doesn't need the call by reference operator for CStrings. I've looked through the book numerous times and I can't, for the life of me, find the answer. Can anyone help explain this to me? It is an array of sorts so I would think you would...