Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Assuming you are taking the approach you have started with, I would recommend defining a functiont that seeks for the last example of a substring in a string:

def findLast(s, target):
    prev = 0
    pos = s.find(target, prev)
    while pos > -1:
        prev = pos
        pos = s.find(target, prev + len(target))
    return prev

However, as it happens, Python has a set of standard libraries for parsing XML-based markup, which SVG certainly is. While this may be more than you need right now, if you expect to be doing a lot more of this sort of thing, you might want to look into xml.etree.ElementTree or xml.parse.expat.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

This is the best I've been able to come up with; unfortunately, it does not exit correctly.

from graphics import *
import tkinter as tk
import threading
import random

class App():
    def __init__(self):
        self.win = GraphWin('Demo2', 400, 300) # give title and dimensions
        self.th = threading.Thread(target=self.FlashThread, daemon=False)

    def FlashThread(self):
        while not self.win.isClosed():
            count = random.randint(0, 8)
            t = threading.Timer(2.0, self.flash, [count])
            t.start()
            t.join()

    def flash(self, count):
        try:
            diameter = 25
            centers = ((50,30),  (110,30), (170,30),  (50,90), (110,90), 
                       (170,90), (50,150), (110,150), (170,150))

            circles = list()
            for point in centers:
                c = Circle(Point(point[0], point[1]), diameter)
                circles.append(c)
                c.setFill("blue")
                c.draw(self.win)

            circles[count].setFill("yellow")
            mouseClick = self.win.getMouse()
            leftX  = centers[count][0] - diameter
            rightX = centers[count][0] + diameter
            upperY = centers[count][1] - diameter
            lowerY = centers[count][1] + diameter
            if (upperY < mouseClick.y < lowerY) and (leftX < mouseClick.x < rightX):
                 print("Correct")
            else:
                 print("Incorrect")
        except:
            self.win.exit(0)


if __name__ == "__main__":
    try:
        app = App()
        app.th.start()
        app.win.mainloop()
        app.th.join()
    finally:
        app.th.close()
        app.close()
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I wasn't able to test your code at all, actually, as I don't know where the graphics package was from. I was able to find it eventually, but I haven't tested it with that, no.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Getting back to the main question, the problem is that a Timer runs exactly once, then exits when the runnable function has finished. What you actually seem to want is a Thread that loops on a time.sleep() call.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Setting aside the timing issue, I would recommend storing the Circle data in a tuple, which should simplify the logic of the program significantly:

    def flash(self,count):
        diameter = 25
        centers = ((50,30),  (110,30),  (170,30),  (50,90), (110,90), 
                   (170,90),  (50,150), (110,150), (170,150))

        circles = list()
        for point in centers:
            c = Circle(Point(point), diameter)
            circles.append(c)
            c.setFill("blue")
            c.draw(self.win)

        circles[count].setFill("yellow")
        mouseClick = self.win.getMouse()
        leftX  = centers[count][0] - diameter
        rightX = centers[count][0] + diameter
        upperY = centers[count][1] - diameter
        lowerY = centers[count][1] + diameter
        if (upperY < mouseClick.y < lowerY) and (leftX < mouseClick.x < rightX):
             print("Correct")
        else:
             print("Incorrect")

I know this doesn't directly help your problem, but it should simplify the code overall.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

A few questions and comments, not directly relevant to your problem but possibly important:

  • What version of Dev-C++ are you using? The older Bloodshed edition is now ten years old, andif you are using that, you should switch to the newer Orwell fork, which is in current development and supports the newest version of GCC.

  • The C-style headers should all be changed to the modern C++ form, for example, <stdio.h> should be <cstdio>, <ctype.h> should be <cctype>, etc.

  • I see that you are using C=strings rather than C++ string objects. Is there a particular reason for this? I would expect C++ strings to be much easier to work with for these purposes.

  • The <conio.h> header and the console functions associated with it are not standard C++, and modern libraries generally don't support it. It is not recommended that it be used in any new programs.

  • It is best to avoid using the using namespace std; in large programs, as it leads to namespace conflicts. It is recommended that you either explicitly scope all references (e.g., std::cout), or if necessary, scope specific items (e.g., using std::cout;), rather than importing the entire namespace.

  • Using bare C-strings for tokens is inadvisable, as you will need to analyze the token for its classification repeatedly. The usual approach is to have a structure type or even a class for tokens, consisting of both the token string and a type tag.This makes checking the token type a simple matter of checking the tag, once …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

What graphics package are you using? The one that comes standard with Python is TkInter, so I would assume that one, but if you are using a different one the answer will be different. Also, the version of Python you are using would help as well.

Assuming TkInter and Python 3.x, a simple answer can be found in the first reply here. This should be easy to adapt to Python 2.x, as well.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The Intel 8088 was, among other things, the CPU of the original IBM PC, and the modern Core ix processors are the distant descendants of that model. Thus, there are a great number of pages and tutorials covering 8088 assembly programming and the instruction set, and several different assemblers for it. The Intel documentation for the original 8088 can be found with a simple Google search.

However, knowing the processor alone isn't sufficient; you need to know about the overall platform, and the operating system (if any). While the most likely case is that of MS-DOS on the PC (or, more likely these days, an emulator, as the current versions of Windows no longer support 16-bit DOS software), there are embedded and single-board computer systems that use the 8088 as well. Furthermore, each assembler has its own dialect of the assembly language, so we would need to know which assembler you are using, as well.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Unfortunately, that approach won't work; there is no append operator for plain character arrays, and strcat(), the append function for C-style strings (which aren't quite the same thing) doesn't work on single characters.

To add a character to a char buffer like you describe, you would need an index that tracks the current position in the array, and when you reach the end of the buffer (for example, when a newline has been entered), in order to use it as a C-string, you would have to delimit the string with a NUL character ('\00'). It's something of a pain to do manually:

#include <iostream>
#include <conio.h>
using namespace std;

int main(){
    char command[1024];
    char newchar;
    int index;

    cout << "Command Line Interface Test with Intellisense" << endl;
    cout << endl;

    while (true) {
        // display a prompt
        cout << "> ";

        index = 0;
        while (true) {
            newchar = _getch();
            if (newchar == '\n') {
                command[index] = '\00';
                break;
            }
            else {
                command[index] = newchar;
            }
            index++;
        }
        // perform command here
    }
    return 0;
}

Fortunatly, there is an alternative: the C++ string class, which does indeed have an append operator, and handles a lot of the details for you.

#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

int main(){
    string command;
    char newchar;

    cout << "Command Line Interface Test with Intellisense" << endl;
    cout << endl;

    while (true) {
        // display a prompt
        cout << "> ";

        while (true) {
            newchar = _getch();
            if …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

While it is hard to give general advice on this matter - different languages appeal to different programmers - as a rule I recommend learning some HTML markup first, before going into an actual programming language. This will give you some sense of the general structure of a program, but is conceptually simpler - it is a static layout, rather than a dynamic set of operations.

My next suggestion is to pick a relatively dynamic, but low-ceremony language like Python, Ruby or (my personal preference, though a bit obscure) Scheme for your first actual programming language. You will want a good online book or site for your information on the language you choose, and to read and try to understand as many existing programs as you can. For Scheme, I would recommend Structure and Interpretation of Programming Languages and the Abelson-Sussman Lectures; for Python, try Think Python; and for Ruby, The Ruby Way. Which of these will work for you is something you'll need to try out for yourself, though I would argue that Scheme is the fastest one to learn, after which learning the others will be easier.

Which brings us to the third step: learn one of the other two languages from the one you picked. Most people find that once they have learned one language, leanring others becomes easier, and the more you learn the easier learning more becomes. I would say that …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You dropped a comma between the values for 'site_id' and 'user_id'. Easy mistake to make, hard to find once it has been made - I've done it myself a number of times and spent a lot of time trying to make sense of the error messages.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Can you post the full traceback, please? It is hard to determine what ther error is without seeing the error messages.

On a guess, though, it is that you need to put the name of the source file and the list in quotations.

data = {'source': 'FACTS Daily Import', 'site_id': xxxxx, 'user_id': xxxxx, 'key': xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, 'format': csv, 'action': add, 'listname': 'TEST List For API Inegration'}
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The built-in Boolean data type in C++, bool, is quite simple: it is a data type which can hold one of two values, true or false. It can be used to hold a truth value for comparisons:

bool overflow = false;

while (!overflow)
{
    //  ... do some things 

    overflow = (foo > bar);

    // ... do some more things
}

In this case, it is used becausse there are actions both before and after the place where the value is checked, so it cannot be in just the conditional of the while() loop.

It is most often used as the return value for a function that returns a true or false result based on some test.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

For what it is worth, you can find a copy of the reference guide at Scribd.com; a quick look at it indicates that the answer you want is (I think) 'Crtl-K H'.

If you don't mind me asking, how is it you are using this particular compiler? It is so old it won't run on most modern systems without an emulator, and I am guessing is older than you are. There are several good C and C++ compiler/IDE combinations available for free, such as Pelles C or Code::Blocks with MinGW GCC. Why Turbo?

(Mind you, a simple 'I happen to like it' is adequate. But if you are using it because you didn't know of a more modern C compiler, I would recommend switching. There are also implementations of the Borland graphics and console libraries which can be used to support older code with up-to-date systems, so it isn't strictly necessary for maintaining some ancient programs, which is another possibility that occurred to me.)

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

What version of Python are you using? If it is a Python 2, then you'll want to add this to the beginning of the file:

from __future__ import print_function

In Python 2.x, the print statement has it's own syntax, whereas this was removed in Python 3.x and replaced with a print function. Adding this import brings in a version of the print function for the 2.x version of the language.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Which is exactly what you wrote in the str() method:

    def __str__(self):
        if self._d == 1:
            return str(self._n)
        else:
            return "%d/%d" % (self._n, self._d)
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Yes, that's the right spot; that sets the default value for the denominator to one. If you pass just the numerator value, you should get the right result.

whole_number_rat = Rational(3)

Should result in whole_number_rat referring to the object Rational(3, 1).

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Oh, you simply make the number the numerator and set the denominator to 1.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Without the parentheses, it becomes a reference to the method itself, not a method call.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Here you have the opposite problem from what you had before: because these are methods rather that properties, you need the parenthese after them in order to call the methods.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Hmmn, tricky. While it is possible to do that, it is more dofficult that you probably expect, and almost certainly not what you actually want anyway.

I expect that the real goal here is to save the user's information - say, their name and a high score - so that it will automagically appear next time the program is run, right? Well, I suppose you could indeed use self-modifying code for it the way you propose, doing so is fraught with peril; you are all too likely to wreck the code that way, ending up with an unusable program or worse one that seems to work at first but has subtle bugs in it.

The more typical solution is to store the user information in a separate data file, which you could then check for at the start of the program and, if it is there, load the data from into the variables. You would do something like this:

from os.path import exists

dataFilePath = "foo.csv"

userInfo = dict()

if exists(dataFilePath):
    with open(dataFilePath, 'r') as infile:
        for data in infile.readlines():
            key, value = data.split(';')
            userInfo[key] = value

    for key in userInfo.keys():
        print('{0}: {1}'.format(key, userInfo[key]))

else:
    userInfo['name'] = input("Enter your name: ")
    userInfo['birth date'] =  input("Enter your data of birth (mm/dd/yyyy): ")
    userInfo['home city'] = input('Enter the city you live in: ')
    with open(dataFilePath, 'w') as outfile:
        for key in userInfo.keys():
            print('{0};{1}'.format(key, userInfo[key]), file=outfile)

THis is a simple example, but should do what you want.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

In the SortedList::ComparedTo() method, you are comparing length (the size of the SortedList) to x.getLength(), where x is an ItemType (which is a typedef of float). Since float isn't a class type, it doesn't have a getLength() method. Are you sure you didn't mean to compare x to a specific element of the list?

    RelationType ComparedTo(int pos, ItemType x) 
    {
        double value = values[pos];

        if (x < value)
            return LESS;
        else if (x > value)
            return GREATER;
        else
            return EQUAL;
    }

This may not be what you had in mind, so I'm speculating here. This is also ignoring the issues involved in exact comparisons between float values, so it may not work even now.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

First off, you may very well already have that version of Python installed. Python is widely used in many Linux distributions, and since Python 3.4 is the current stable version, it is safe to say that if you've kept up with your package updates, you may already have that version. Open a shell and type python --version and see what it says.

What Linux distribution are you using? Most distros have a package manager which allows you to download and install most software from within Linux itself. For Ubuntu, the package manager is Synaptics (actually, it's apt-get, but Synaptic is a graphical front-end for it); in Gentoo, it is Portage; in Red Hat, RPM; and so on. How you would use it depends on the package manager in question.

If you distro's package manager doesn't have a package for Python 3.4 yet, then you'll want to download and install the source distribution. The reason there is no pne-click installer for Linux is because Linux programs are usually distributed as source code; the groups that make the Linux distros create the packages from that. If you go back to the Python website, you'll find the source distribution packages. DOwnload that and follow the instructions for untarring and configuring it.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Oh, I see what I did wrong, sorry about that. Remove the parens after data and it should work. The mistake was because I had made Node a separate class in my version, and used an accessor method to get the data from the nodes. I changed the code to reflect your version, but by force of habit added a pair of parens, thus making it look like a method call.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You need to alter the InsertItem() function so that, instead of always putting the item at the end of the list, it checks to see if the item is less than the next item in the list.

    void InsertItem(ItemType x) // insert x into the list
    {
        bool moreToSearch; moreToSearch = (location != 0);
        nodeptr z = new  Node;
        z->next = NULL;
        z->data = x;

        if (head != NULL)
        {
            location = head;
            while (location->next != NULL && x > location->data())
            {
                location = location->next;
            }
            z->next = location->next;
            location->next = z; 
            length++;
        }
        else
        {
            head = z;
            length = 1;
        }
    };  

This should work well; after all, it does in the version I wrote while trying to figure out what to recommend, though admittedly I changed an awful lot of your code in doing so. :-)

catastrophe2 commented: thnx, but i got this error when i replaced the function with yours: picture attached in reply +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

A few recommendations:

  • The first thing I would do with this sort of project is separate the class declaration and implementation from the program using them. If you put the class declaration in a header file, and the functions (those which are more than, say, three lines long) into a separate source file, it would improve the modularity of your code.

  • The immediate problem you are having with RetrieveItem() is because you are attempting to pass a literal as a reference value. As I will explain shortly, this function probably should be redefined anyway.

  • It would make more sense to define Node separate from the SortedList class, as there are some functions (as explained below) where it would make more sense to pass a Node as the return type.

  • RetrieveItem() currently takes two reference values as its arguments, one of which it uses to pass back a return value. It would make more sense to pass the comparison number as a value, as you don't change it, and give the Boolean value as the return type. However, I would instead recommend eliminating the bool outright, and returning the Node pointer instead.

  • Why do you set a limit of 10 items on the list? The entire purpose of using a linked list is flexibility in the size of the list; otherwise, an array wouls make more sense. In any case, you have a function to check the size of the list, but you don't actually restrict the list's size anywhere.

  • Given …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

we are supposed to read a list from a file, (named float.txt, or can be IN visual studio which i forgot how to to do, and searched the internet for an hour and nothing good comes up)

If memory serves, what you have to do for that is right click on Solution Explorer->Resource Files and select Add->Existing Items and browse to the file in question.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The short answer is, rand() and srand() (which you should call at the beginning of the program before calling rand() for the time) are in <stdlib.h>, so you need to #include that header in order to get the function prototypes for them.

That having been said, I will add that you don't use any functions from either <conio.h> (which you shouldn't be using anyway) or <process.h> (which is specific to Unix-like systems anyway). Oh, and main() should always be declared int, not void.

On a guess, I figure you are using Turbo C++ 1.01, right? DON'T. It is a twenty-five year old MS-DOS compiler that won't run on modern Windows systems without an emulator such as DosBox, and pre-dates the current C and C++ standards. If your professor is requiring you to use it, walk away from the class and don't look back, because you are being taught things that are going to make it harder for you to learn the right ways to program in the modern world. Try to get as many other students to walk out with you - the only way to get them to change their absurd and outdated policies is to throw them back in their faces. If you have to, learn programming on your own - chances are, you'll do better that way than you would trying to make that class work out for you.

Ancient Dragon commented: nice info about Turbo C +14
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Haven't we been here before? Oh, yeah, we have. In that case, let me repeat what I said last time:

First off, don't hijack other people's threads with unrelated questions; if you have a new question not related to the thread, create a new thread.

Second, didn't you read what I said to the OP? We don't do other people's homework for them like that. If you want help, show us what you've already done, otherwise, we can't help you and won't even respond to you. If you want the work done for you, hie your lazy self to freelancer.com and pay someone to do it, just don't cry to us when you get caught cheating.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I'm going to recommend two things: first, that you change the return type to string and second, that you declare a char ch. If you then take the return value, and append x to it:

string copy()
{
    cin >> ch; 

    if(ch != '\n')
    {
        return ("" + ch + copy());
    }
    else
    {
        return "";
    }
}   

then it should fall into place.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Let's see if you can determine the problems with these two lines:

void copy()

and

    return (x +1);

then figure out what it implies for

            copy()

(Bonus points if you can see the syntax error in that last line.)

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

in the inner loop, you are incrementing i instead of j. This leads to you walking off of the end of the array A, but I would expect it to give a segfault, not a stack overflow. How odd.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I would recommend using the new operator rather than the C-style memory allocation, but that is what it sounds like you're expected to use, yes.

From the sounds of it, the intention is for you to create the first array in main() (or whatever function you are calling prefixAverages() from), then pass it to prefixAverages() as an argument along with the size of the array. You would then use new to allocate the second array.

int *A = new int[n];

Then, after filling A with the computed values, you would return it as an int pointer.

 int* y = prefixAverages(x, SIZE);

Oh, but don't forget to use delete before the end of the program to free the allocated array:

delete[] y;

EDIT: I forgot the square brackets on the delete.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Has the instructor covered dynamic memory allocation (new and delete) yet?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

mike_2000_17: While that is indeed a solution to the problem as given, I'm not sure it is the answer Labdabeta needs. This has the smell of a shoe or bottle problem to me; I think Labdabeta should possibly reconsider the direction he's taking, if he finds himself needing such an unusual solution. I may be wrong; there certainly are places where a stream might have to serve multiple purposes like this. I am just not certain this is one of them, and would like a broader picture of the problem.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

If output alone were your goal, I would say to use an ostream for the variable class and ofstream for the output file. However, you are then using the file for input, which does indeed lead to the problem you describe.

Wait, what is the goal, here? Why would you need to be able to use a single stream serve for multiple purposes like that?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

In C/C++, command-line arguments (AKA shell arguments) are passed through optional parameters to the main() function. These parameters, by convention named argc and argv, are an integer count of the arguments passed to it, and a pointer to an array of char arrays, which hold the string values of the arguments themselves. Under most (but for some reason, not all) systems, argv[0] is the name of the program itself.

For example, you can write a program that echoes its arguments simply by looping on argc:

#include <iostream>

int main(int argc, char *argv[])
{
    for (int i = 1; i < argc; i++)
    {
        std::cout << argv[i] << std::endl;
    }
    return 0;
}

The downside to using shell arguments is that there is no checking for the type or number of arguments passed; thus, you need to check argc to make sure that it is a legitimate number of arguments, then parse the arguments for their values.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

First off, we don't do other people's homework for them. Second, we don't do other people's homework for them. And third, we don't do other people's homework for them. Sensing a pattern here yet?

No one here will simply hand you a solution on a silver platter. If you show us what you've done, what you've tried to do, and what problems you've had with it, then we'll be happy to help. If you have specific questions, we can answer them, or at least point you in the right direction. If you have a program with a bug you can't swat on your own, we'll be glad to assist, so long as you pay attention to the forum rules and post sensible questions in an intelligent manner that we have some reasonable hope of answering.

But just cutting and pasting an assignment into a message, without even prefacing it with something like, "I have this homework problem that I can't solve...", is likely to get you booted from the message boards here and elsewhere - if you're lucky. What happens to you if you are unlucky is... well... let's just say that this guy probably won't be trying that again, on that forum or this one.

And if you think you won't get caught by your professor... think again.

We take this issue seriously here. Very seriously. Asking us to do homework for you is a grave breach of academic …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I do recommend that you go over the new code carefully, and familiarize yourself with what I did and how it works. If you have any questions, especially regarding the activation record, feel free to ask.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, I'm going to break the usual rules regarding how much we can do, but I have a reason for doing so. I worked out a solution for the problem, but the code I wrote involes using some techniques you are almost certainly unaware of at this time. The main things I have done are A) moved the function(s) past the end of the main code, so that they ae no longer embedded in the program; B) re-written the print function as two functions, one of which, print_array, calls the second, print_array_line; C) used parameter passing in the functions to make them more general and modular; and D) applied stack discipline to hold an activation record for the print_array function. I have also used a few features of SPIM which are not supported by MARS, but changing the code to work in MARS is simply a matter of replacing the symbolic constants with the equivalent literals. The SPIM=specific version should be a good deal easier to read, but the MARS version should work in both emulators.

    .data

#stack offsets
fp.ra = 4
fp.a0 = 8
fp.a1 = 12
fp.a2 = 16
fp.a3 = 20
fp.s0 = -4
fp.s1 = -8
fp.s2 = -12
fp.s3 = -16
fp.s4 = -20
fp.s5 = -24
fp.s6 = -28
fp.s7 = -32
################################################################################
#System calls
print_int   = 01 #$a0  = integer
print_float = 02 #$f12 = float
print_double= 03 #$f12 = double
print_string= 04 #$a0  = string
read_int    = 05 #returns integer …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Could you please tell us what system or emulator you are using? There are small but sometimes important differences in the way different emulators (e.g., SPIM, MARS) work, especially in terms of the assembly directives they accept, and it may be relevant. For now, I'll assume you are using SPIM, but if you are using a different one such as MARS or MIPSym, or an actual hardware MIPS system such as a Playstation 2, please let us know.

As for how to print exactly five values per line, there are two simple solutions: first you can have an inner loop with a counter variable, which would repeat five times. The psuedo-code for this would be something like:

a = your array
p = pointer to a
x = 10
while x != 0
    y = 5
    while y != 0
        print 0(p)
        p += 4
        y--
    end while

    print newline
    x--
end while

The other solution is to simply unroll the loop, and have one loop which hs five print operations:

a = your array
p = pointer to a
x = 2
while x != 0
    print 0(p)
    p += 4
    print 0(p)
    p += 4
    print 0(p)
    p += 4
    print 0(p)
    p += 4
    print 0(p)
    p += 4
    print newline
    x--
end while    

On a guess, the first is what you instructor is looking for.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

How so? Saying it isn't helpful doesn't tell us what would be helpful. Please give us more to go on, if we are to help you.

As I said, the first step here would be to write a function that returns accpets the Celsius value and returns the Fahrenheit value. Before we can do that, though, we need to work out just how to convert a Celsius value to Fahrenheit. As it happens, this part was already given to you:

f = 9 / 5 * c + 32

So, taking this one step at a time, let's see how this works. If you open up the Python interpreter, and enter

c = 0

then enter the formula above, followed by

f

you should get back the value 32.0. OK, then! Now what you need to do is make the function, which would simply be

def celsius2fahr(c):
    return 9 / 5 * c + 32

basically, all we've done is give the formula above a name, celsius2fahr(). To test it, try entering

celsius2fahr(100)

this should give you 212.0 as the result. you now have a way of repeatedly getting a Fahrenheit value from a Celsius value.

I've got to go now, but this should at least move you in the right direction.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

What, if anything, do you have already?

I would recommend starting with a simple function that takes a Celsius value and returns the Fahrenheit equivalent. If you don't know how to write a function, let us know and we'll explain it for you.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

What is happening here is that you are actually calling the input() operation separately each time you are testing for it, which means that if the value of the first entry is not '1' (and note that it is the string '1', not the numeric literal 1), then the value is discarded - you never save it anywhere. Then, when you get to the first elif clause, you call input() a second time, reading a new value in and testing that. Likewise, the second elif clause reads for a third time, and tests the third value entered.

To avoid this, you want to call input() only once, and save the value in a variable, which you would then test for the three values:

        selection = input()
        if selection == '1':#This is fine.
            print('Okay, you\'re heading to {}\'s tavern.'.format(self.name))  

        elif selection == '2':#This has to be typed in twice.
            print('Okay, you\'re heading to {}\'s inn.'.format(self.name))     

        elif selection == '3':#This has to be typed in three times.
            print('Okay, you\'re heading to {}\'s city hall.'.format(self.name))          

        else:#Four times.
            self.cityMenu()

This should solve the problem nicely.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

First off, could you give more detail as to what you need? As I understand it, Kirchhoff's First Law is an equation regarding electrical flow across circuit intersections; Wikipedia gives the informal form of it as:

At any node (junction) in an electrical circuit, the sum of currents flowing into that node is equal to the sum of currents flowing out of that node, or: The algebraic sum of currents in a network of conductors meeting at a point is zero.

When you say you need the program to 'illustrate' Kirchhoff's First Law, do you mean it should calculate the values coming into and out of the node, from and to the given circuits; or that you need to simulate the circuits visually, as a circuit diagram (which would require the former computations, as well as the graphics handling)? Do you need to simulate a specific circuit that can be hard-coded into the program, or (more likely) does it need to be able to take a set of circuit definitions and translate those into the combined circuit?

Also, could you show us what work you've already done on the project? One of the rules of DaniWeb is that you need to show your effort on the project, in part so that we know where you are in it and don't duplicate work you've alrady done, and partly so we can tell that you have put a good-faith effort into the project yourself before asking for help. What code …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

What sort of problem are you having, or trying to solve? We will need more information before we can give a sensible answer.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

No, I mean that the real target of the crack is the part which is always vunlerable: the human being invloved in entering and using the data.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Actually, what crackers 'hack' is mostly other people's impatience, ignorance and willingness to go along with percieved 'experts' and 'authority figures'. It's called Social Engineering and it is the majority of how crackers circumvent both software and systems. Even software cracks such as program security exploits mostly depends on being able to identify and exploit the weaknesses of the programmers and users, rather than of the code itself.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The line between 'helping you finish a project' and 'helping you cheat' is a fine one, at times. However, in this case the Daniweb rules are pretty straightforward:

Do provide evidence of having done some work yourself if posting questions from school or work assignments

So: Show us what you have done so far, and tell us what you are having difficulty with, and we will assist you. We will not, and cannot, provide you a solution without you showing some effort on your part.

BTW, you should know that the Travelling Salesman Problem is a classic one, with many variations, and is provably NP-complete (meaning that all the known general solutions require non-deterministic polynomial time; any solution in less than exponential time would effectively be a proof that NP = P, which is an open question to date and thought by many to be undecidable). Just so you know.

aroshkhan commented: haha great (Y) +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The strcmp() function compares the ASCII values of the characters one by one. If all the characters match, it returns zero; otherwise, if the first differing character in the first string has a lower ASCII encoding than the compared character in the second string, it returns a negative, wheras if the first string's character is higher, it returns positive.

Mind you, it's important to keep the difference between C-strings and string objects in mind, as they are quite different things. The fact is that C-strings are something of a second-class type in C, which carries over to C++; they are as much a convention as they are an actual type, because it is up to the functions which operate on them to do things like check the size of the string, ensure that there is a zero-delimiter at the end of the string, and so forth. The C++ string class and objects are quite different, being fully qualified objects in the language with a large amount of functionality built into them. They are more opaque than C-strings, but more flexible, and for most purposes, easier to work with. While it is farily easy to convert C-strings to strings (using the string c'tor) and back (using the .c_str() method), they are not at all the same thing.