homework

Implement the strcmp(str1, str2) function in c#

There are many ways one can implement the strcmp() function. Note that strcmp(str1,str2) returns a negative number if str1 is alphabetically above str2, 0 if both are equal and postiveve if str2 is alphabetically above str1. I want to implement it in c# without using any built in methods of .NET In it can be implemented in C as follo...

Speed of C program execution

Hi all, I got one problem at my exam for subject Principal of Programming Language. I thought for long time but i still did not understand the problem Problem: Below is a program C, that is executed in MSVC++ 6.0 environment on a PC with configuration ~ CPU Intel 1.8GHz, Ram 512MB #define M 10000 #define N 5000 int a[M][N]; void main(...

Python for loop question

exepath = os.path.join(file location here) exepath = '"' + os.path.normpath(exepath) + '"' results = [] for e in ('90','52.62263','26.5651','10.8123'): if e == '90': z = ('0',) elif e == '52.62263': z = ('0', '72', '144', '216', '288') elif e == '26.5651': z = (' 324', ' 36', ' 108', ' 180', ' 252') else: z = (' 288', '...

Class issue, adding a day

I'm trying to make the add_day function work, but I'm having some trouble. Note that I can't make any changes to the struct(it's very simplistic) because the point of the exercise is to make the program work with what's given. The code is #include "std_lib_facilities.h" struct Date{ int y, m, d; Date(int y, int m, int d);...

Circuit that counts the number of set bits in 15-bit input

How to build an area-efficient circuit that counts the number of set bits in 15-bit input using 4-input LUTs (look-up tables). The output is obviously 4-bit (counts 0-15). Some claim that it's possible to do using 9 LUTs. ...

C++ Reverse Array

In C++, I need to read in a string from user input and place it into a char array [done] Then, I need to pass that array to a function [done] That function is supposed to reverse the order of characters [problem!] Then after, back in the main(), it displays that original array with the newly reversed characters. I'm having trouble cr...

Explanation of how this code works (C#)

Hi all, Can anyone explain me the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing; namespace web.frmcolor { public class FormEx : Form { /// <summary> /// Set the default color for the designer /// </summary> stat...

recursion: cut array of integers in two parts of equal sum - in a single pass

Using recursion, find an index that cuts an array in two parts so that both parts have equal sum. Cut means to cut like with a knife. All the cells with index <= to the result must be equal in their sum to the all the cells with index > to the result. No cells can be left off or be part of both sides. The arrays contains arbitrary inte...

Problems implementing a quicksort

Got it working, final code: Pushes back data and sorts both in synchronization #include "std_lib_facilities.h" struct Name_pairs { vector<string>names; vector<double>ages; void quicksort(vector<string>& num, vector<double>& num2, int top, int bottom); int divide(vector<string>& array, vector<double>& array2,...

Assembly 8086 Program - Assembling Error

If this Question duplicates I'm sorry but I think I did it the wrong way the 1st time. Well I have sum assembly homework to do... its supposed to be the snake game. I managed to make a program using parts of others ones, since Im lazy.. anyhow I got the program almost ready but I get only 1 error when assembling: **Fatal** C:\TASM\emu8...

Print a simply linked list backwards with no recursion, in two passes at most, using constant extra memory, leaving it intact

You must print a simply linked list backwards: Without recursion With constant extra memory In linear time Leaving the list intact Added Later Two passes at most ...

С++: memory leaks

Sorry for my English. The question: At what value of variable n the following code will cause memory leaks? That's the code: int* Bar(int n) { if (n == 1) throw "exception"; return new int[n]; } void Foo(int n) { int *a = Bar(n); if (n <= 2) return; delete[] a; } It's clear that if n is 2 there will be memory le...

Inline functions vs Preprocessor macros

How does an inline function differ from a preprocessor macro? ...

Computer Science and Psychology

First off, my apologies for asking this fairly off-topic question. But in my experience, there are a lot of highly intelligent people on SO so I figured I might give it a shot. Please don't be too triggerhappy with the 'close'-button :-) Besides, I think there's some chance that this may be of general interest. I'm a Computer Science ma...

MYSQL MAX and Min query

Hi could someone help me with this problem for my college assignment cars Make MadeIn Sales GM 2005 100 GM 2006 1200 GM 2007 600 What I have to do is work out the greatest increase in Sales between 2005 and 2007 and display this value and the Make I think I have the answer to the inc...

Runtime error, possible input problem?

I have a book class that takes title, author, copyright, ISBN number, and checkout for a book object. However, I'm getting a runtime error when the program runs. After the user inputs the title and presses enter, the program skips down, showing the rest of the outputs, and then terminates the program giving a runtime error. I tried to ...

Add timer to a Windows Forms application

I want to add a timer rather than a countdown which automatically starts when the form loads. Starting time should be 45 minutes and once it ends, i.e. on reaching 0 minutes, the form should terminate with a message displayed. How can I do this? Language: preferably C#. ...

Graph connectedness problem

Does anyone know an algorithm for the following problem: Given a undirected connected graph find the number of ways in which 2 distinct edges can be cut such that the graph becomes disconnected. I think a part of the problem (which i know an algorithm for) is calculating the number of ways in which 1 line can be cut so that it becomes ...

c# mileage counter

A mileage counter is used to measure mileage in an automobile. A mileage counter looks something like this 0 5 9 9 8 The above mileage counter says that the car has travelled 5,998 miles. Each mile travelled by the automobile increments the mileage counter. Here is how the above mileage counter changes over a 3 mile drive. After the ...

Tower of Hanoi

I have no idea about tower of hanoi. I want to write a program on this using recursion. ...