n1337 29 Junior Poster in Training

In general, matrices do not need to be square in order to compute their product... rather in computing A*B, the number of columns in matrix A must be equal to the number of rows in matrix B. Regardless...

We can think of each matrix as being composed of row and column vectors. Then, each entry [i,j] in the product matrix is the result of a dot product of a certain combination of these row/column vectors. We can denote the row vectors in matrix A as row[1] ... row[n] and the column vectors in matrix B as col[1] ... col[n].

Then, element [i,j] in the resultant product matrix would in fact be the result of the dot product <row, col[j]> , for 1<= i,j <= n

So the question is... how do you extract the column and row vectors using your particular representation of a matrix?

n1337 29 Junior Poster in Training

Let me try to understand here... The function needs to return a that represents a binary integer? Or the actual bits of the returned value need to be the correct binary representation of the decimal value?

n1337 29 Junior Poster in Training

But it is not working. I get an error when I run the procedure, which says this: "string-append: expects type <string> as 2nd argument, given: #<void>; other arguments were: """

What am I doing wrong here?

The issue is that your char_toupper function actually returns void... In fact, the display function (display <>) has no return value. That is, (void? (display "a")) returns #t...

But you are using your char_toupper function as though it were returning an upper case character. If you want to use it like this, then you should modify it so that it actually returns the uppercase character to be used in string-append. Alternatively, you could modify your string_toupper function so that it does not require a result from char_toupper. That is, simply output the uppercase characters one character at a time (as your char_toupper currently does), and do not construct an entirely new string of uppercase characters... This would actually be faster since you would not require string-append, which takes O(n) time (although may not be the purpose of the assignment... it depends on whether or not your string_toupper need return a value...)

Hope that makes sense!

n1337 29 Junior Poster in Training

Just so you know, if you write *crafty* recursive code, a.k.a. tail recursive functions, your compiler should optimize for recursion and use less stack space (i.e. reuse stack space)...the equivalent of using a for or while loop. (At least, GCC optimizes for tail recursion...I would hope that *some* c++ compilers do so as well)

That is, if the function call is the last operation (and the calculations are done as parameters), then memory can be reused --> no intermediate build up of operations becuase in order to call the function, the function parameters will be evaluated first.

EDIT: I took out the examples because after posting this I got curious and started playing around in VC++...turns out my example was kind of useless (hard to see the distinction), and seems like VC++ doesn't optimize for recursion at all...moved over to GCC and was able to pump out way more recursive calls, but again I didn't see the optimization between the tail recursion and structurual recursion...Now I'll have to think about this...

Maybe worrying about optimized recursion is best left in Scheme. haha

n1337 29 Junior Poster in Training

edit: how to delete a multiple post...

n1337 29 Junior Poster in Training

i tried to think it through but cant seem to figure it out..i was using the if to test some parts of it..sorry

Sorry I didn't realize this hadn't been solved. I don't have time atm (I'll be out and about all day...), but I will sit down later tonight and help you out, unless someone else has fixed up your problem by then.

n1337 29 Junior Poster in Training

Right, well, I'm not sure I understand what you are asking...

Which shapes do you need to learn how to draw? Just a square/triangle? That would be where I would start...

Assuming your exam is a written exam, I suspect your instructor wants to examine your ability to trace through the iterations of a loop...try to understand how the variables change after each iteration and how that affects your output (when outputting to the console).

As for math calculations...that could really mean anything. For example, if you were given the side length of a square, you could classify a calculation as determining the dimensions of the square, and consequently how to construct an appropriate loop to render it onto the screen/console.

Math calculations could mean extending a sequence of numbers (for example, the triangular numbers 1, 3, 6, 10, 15, ...) to construct a triangle.

Moreover, math calculations could also pertain to rendering shapes on a (cartesian) coordinate system.

So what do you mean by math calculations?

n1337 29 Junior Poster in Training

Or else you do a few math calculations, then set up a function to draw individual shapes....

For example, you could create a "square" function:

void draw_square(int sideLength);

which basically loops and outputs a square (of the specified size, using a loop) to the screen...

Advantage: you can create reusable shape-builders...to make more shapes...haha

EDIT: niek_e is right, what specifically do you need help with, rather than us just posting code...

n1337 29 Junior Poster in Training

I tend to think with pointers because I started with C...and pointers are commonplace in C...and thats how I learned...lol. But my thoughts were this: the elements in a stack may in fact be objects themselves (i.e. their own stack structures), so I thought it would be easier to manipulate if you were pointing to the element instead.

I'm sure it can be done without pointers, but that I shall leave as an exercise instead for you.

Besides, pointers are a wonderful and powerful (or scary..) part of the language...if you aren't going to use them, switch to Java (or C# if you are a Windows-only programmer ;) ). lol (just kidding) :)

n1337 29 Junior Poster in Training

I have a potential solution...though you may not like it (and I haven't fully implemented it, so there could be some leaks):

1) In your stack class, in the private field, in the node struct, change T element to be a pointer (i.e. T *element)

2) In the public field of the stack class, change your prototype for push to take T* as a parameter, and change the pop prototype to return T*.

3) In the push implementation, change the function header to accept T *ele as a parameter.

4) In the pop implementation, return type should be T*, change T popped to T* popped.

5) In the view implementation, dereference temp->element (i.e. *temp->element).

6) In main, you can set up your stacks as follows:

stack <int> *subs = new stack<int>;
stack <stack<int>> *mains = new stack<stack<int>>;

To push elements to the subs stack:

int a = 5;
int b = 10;

subs->push(&a);
subs->push(&b);

To push elements to the main stack:

mains->push(subs);

However, I didn't know how you wanted view to behave for main...To view the top stack in main you can do this:

mains->pop()->view();

Anyway, I didn't check all the implementations, so some things might need to be changed...and this may not be what you were looking for...and you might have to write a few extra things...dunno

n1337 29 Junior Poster in Training

Pass by reference works much the same as passing an array in Java. In fact, when you supply an array as an argument in Java, you don't actually copy the array, you just pass the address (believe it or not). It's just you don't explicitly manage the pointer aspect in Java; Java does all that for you behind the scenes (an array is just a pointer to a block of memory).

Having started with C, I don't quite like/use the C++ pass-by-reference style...I much prefer passing an address and dereferencing (I also tend to do a lot of things in an "archaic", C-fashion...haha).

Either way, I found a few articles that you might find helpful/interesting:

http://www-cs-students.stanford.edu/~sjac/c-to-cpp-info/references
http://www.horstmann.com/ccj2/ccjapp3.html
http://www-ali.cs.umass.edu/~mckinley/377/labs/c++_for_java_programmers.html

n1337 29 Junior Poster in Training
while(current->name!=name)
{
	previous=current;
                current=current->link;
}
current=current->link;
previous=previous->link;
delete previous;
}

Can I see your list struct?

I think you are losing a pointer in your code though. Before you delete the specified node (the one you want to delete), you need to make sure that the previous node links to the node after the specified node. That is, you need to grab the specified node, then set previous->link equal to the node after the current (specified) node. Then you can delete the specified node...Make sure you don't have any pointers to it though.

Also, in your while loop, what if you never find the name of the node? (errors...) You should account for if this happens (i.e. check if your list becomes NULL and then exit)

Also, I don't think your if statement makes sense...In fact, I don't think you need it...

n1337 29 Junior Poster in Training

How do you increment playerposn by the dice value?

playerposn += dice_value;

I assume I’ll have to somehow associate every random number generated to a specific variable, which I’ll then add to player position, right?

Everytime you generate a random number, you should store it in your dice_value variable. Then you just use this value to increment the player position. If you have multiple players, you will need to keep track of who's turn it is, and increment the appropriate player position. That is, if it is player 1's turn, increment playerposn1, if player 2, then increment playerposn2, etc (or you could make an array of playerposns to keep things nice and neat). In any case, get one user working before you make multiple ones...

Also, how do I get it to recognise “press space to continue, any other key to exit”. I mean, what stands for space bar in syntax?

A keypress is an event that you will need to fire. There are likely several threads already on this forumn about this topic. If you can't find any, then search for kewords C++, Win32, and Keycode/Keypress/Keydown/Keyup on google.

However, due to the fact that you are fairly new to programming, I would instead suggest you just read in from the console, and have something like "Type c to continue, e to exit". Then just read in the value, do a simple error check, if it is a c, continue, if it …

n1337 29 Junior Poster in Training

Hi, this is my first time posting to this forum so please let me know if I'm doing anything wrong.

I'm fairly new here also, so I can't tell ya...But as a general rule, I think it is best if you try to search for things on your own before posting...

a. Write the internal representation of “17” in ASCII using two binary numbers

I'm not totally sure what you mean by this, but you can get the ASCII character codes by using the following code:

cout << (int)'1' << endl;
cout << (int)'7' << endl;

In fact, you can find out any character code by replacing the 1 or 7 with whatever character you like. Anyway, the above code will give you 49 and 55, respectively. So I suppose you need to write these numbers in binary...As for doing that, there are several algorithms (to do it by hand), which you can mimic using code (if you need to). I'm sure there is also probably some function written in some library in C++ that will auto convert for you, or you could write one yourself (do a search if you desire). Anyway, the following link explains a few "by hand" algorithms for converting decimal to binary:

http://www.wikihow.com/Convert-from-Decimal-to-Binary

b. Write 17 and -17 in two’s complement notation. Use 8 bits for each

Again, quick google search will reveal how two's complement works. Here you go:

http://en.wikipedia.org/wiki/Two's_complement

c. Write 0100101111112 in …

n1337 29 Junior Poster in Training

I need to be able to initialize player_position for at least 2 players, have them roll the dice, move the players to a new location and determine whether there’s a snake or ladder there, then move them to a new location.

int board[101];
    int snake;
    int ladder;
    snake = board[5],[15],[25],[30],[45],[53],[62],[78],[81],[93],[96];
    ladder = board[7],[12],[28],[35],[40],[59],[65],[73],[88]

i'm sure you can see from here that i'm trying to set positions for snakes and ladders on the board so that whatever random number pops up from the dice, locations will already by marked.
Thanks.

What you have done here isn't all that bad. You initialized an integer array with 101 elements, called board. Good. What you could do then is define a "snake" square to be 1, a "ladder" square to be 2, and a regular square to be 0 (or whatever integers you so desire). Clarification:

#define snake 1 //put this at the top of your project, with the includes

board[5] = snake;     //body of your program

Then, there are a couple things you could do to keep track of the players. One idea would be to associate the player with his/her respective board element. That is, create a "playerposn" variable. For example, player 1 starts at 0 (i.e. board[0]). So playerposn = 0. If they role a six, you increment playerposn by 6...now player 1 is at position 6 (i.e. board[6]). Then on each role you simply check if they are on a ladder/snake/regular square, and move them accordingly. To do this …