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

The interpreter cannot find those properties because you didn't define them; I assume this was simply an oversight. Happens all the time, no big worry there. Just add the following methods to the class:

    @property
    def numerator(self):
        return self.num

    @property
    def denominator(self):
        return self.den     

BTW, your string formatting should read:

print ("third: {0}/{1}".format(third.numerator(), third.denominator()))

HTH.

kxjakkk commented: thank you! +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

sigh I must have been tired, or else had an attack of the dumba-- this morning. You can replace

    for choice in option_list:
        if choice == option:
            option_list[choice]()

with just

    option_list[option]()

There's no need to loop on it at all. My bad.

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

iamthwee: jQuery is JavaScript, or rather, a library for JavaScript. You cannot hope to understand jQuery if you don't know the underlying JavaScript that it is based on. As for Sublime, I am not familiar with it, but given that one of the demonstrations on the home page uses Python - and the fact that the it is written in Python! - indicates that it should handle it well.

Siberian: While Sublime does appear to quite good, it is also not a free program; if you are willing to buy it, fine. However, there are a wide number of free editors and IDEs available for both languages, starting with the venerable Emacs and going to such choices as SciTE, Komodo Edit, and (for Windows only) NotePad++. There are also many language specific IDEs, such as Eric and DrPython for Python. Being rather old-school, I use Emacs for most purposes, because it is far and away the most flexible and easily extended of them all, but the learning curve is high.

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

Edward_3: I think you missed the point. The OP needs a C program, and cannot use the C++ version, for whatever reason s/he has.

shadowplayer28: Just what are you trying to accomplish by re-writing the program in C? Why do you need it to be in C, and not in C++? Is this your original code, or something you found on the net, and if the latter, are you certain it is really what you need? Do you know both languages, and do you understand the ways they differ and why?

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

It's not entirely clear what you want, and I doubt anyone would have an example quite like that on hand in any case. It sounds as if you want to know who to provide a menu, is that more or less correct? If so, a general model for what you want would be something like this:

menu = '''Please choose from the following options:
   1. option 1
   2. option 2
   3. option 3
   4. option 4'''

option = input(menu)

while option not in ['1', '2', '3', '4']:
    print('sorry, that is not a valid option, please choose again.\n')
    option = input(menu)

if option == '1':
    # perform the first option
elsif option == '2':
    # perform the second option
elsif option == '3':
    # perform the third option
else:
    # perform the fourth option

This is just a general sketch of a menu; you should be able to fill in the details yourself.If the number of options is very large, you might want to do this instead:

def option_one():
   # do option one code

def option_two():
   # do option two code

def option_three():
   # do option three code

def option_four():
   # do option four code

# and so on...

if __name__ == '__main__':
    ## do the part that read in the option as before...

    # make a dictionary mapping options to functions
    option_list = {
        '1': option_one, '2': option_two, '3': option_three, 
        '4': option_four, '5':option_five, 
        # and so on... 
        'n': option_n
    }

    for choice in option_list:
        if choice == …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

mridul.ahuja: What language is this again? Because that certainly isn't C++ declaration syntax. I think you're thinking of VB.Net, except that cin and the input operator aren't in VB....

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

As for the segfault, it appears to be occurring when you are trying to read from the b.filename file, if the file ins't actually there.

On an unrelated note, you cannot write a struct out to a file directly and expect it to be usable; you need to write out the individual members of the structure separately, a process called serialization. Here's a simple function to serialize your A struct values:

void write_command(struct A* cmd, FILE* fp)
{
    fprintf(fp, "%s,%s,%s,%f\n", cmd->command, 
        cmd->name, cmd->filename, cmd->amount); 
}
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

What lunatic taught you to use goto like that? Or at all, for that matter? If your professor is teaching to write code like that - hell, if you professor even mentioned goto in the first place - you should walk away from that course.

Here's a piece of advice: forget that the keyword goto exists. You should never, ever use it for ordinary flow control. It is far too difficult to debug code that uses it. While goto does have its place in C programming, someone just learning the language shouldn't touch it.

ddanbe commented: Could not agree more! +15
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

I assume that the real issue here is that you cannot ensure that Arial (or any other given font you may choose) will be installed on the host system, correct? Unlike, say, Windows, or MacOS, there are no 'standard' fonts for Linux, which is what the real issue is IIUC.

Different distros have different base font sets, and no one set is to be found in all possible cases. Indeed, you cannot be certain that there are any software fonts at all - it is possible, though rare today, for a Linux system to run entirely in console mode with the firmware fonts. The best you can expect is that if the system has an X server, it will have the X11 core Type 1 fonts.

Fortunately, there are a few options. One is to check the system the application is running on, and use one of the default fonts that you can be certain are on the system. This presents a problem, though, as the default fonts are almost never acceptable quality, especially the X11 fonts. The next is to have a list of commonly used fonts which the application can choose from; however, a list that is comprehensive across different distros is likely to be prohibitively long. Next is to allow the user to choose the font they want it to be rendered with, but this opens up a huge can of worms. You can be draconian and force the user to install the font in question in …

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

As 2teez says, the policy at Daniweb is that you must give demonstrate that you have made a good faith effort to solve your problem yourself, and that respondents are expected to only provide support and assistance, not provide full solutions. Show us what you have tried so far, or at least explain what you need help with, and we will do what we can to help, but we cannot and will not simply write your program for you.

I know that this is probably not what you meant, but it is what it came across as. If nothing else, you need to be more deliberate and specific with your questions in the future.

Having said that, I noticed one thing about the assignment as decribed: the order in which you are to do things seems off. Are you certain that you are to write the unsorted names to the files, then read them in, and finally sort them after they have been written? It seems to make more sense to have the names sorted before writing them out.

Have you covered how to read and write files in class already? The general approach is something like this:

#include <stdio.h>

#define BUFSIZE 1023

int main()
{
    char buffer[BUFSIZE + 1];
    FILE in_file, out_file;

    in_file = fopen("my_file.txt", "r");  /* open file to read it */ 
    fgets(buffer, BUFSIZE, in_file); /* read in one line */
    fclose(in_file);

    my_sort(buffer);    / sort the string elements */

    out_file = fopen("out_file.txt", "w"); /* open file to …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Have you consider any other languages such as Python or Ruby? The eBook Think Python is quite well regarded, and has a chapter on using the TKinter GUI system.

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

The <iostream> library header is a header that defines several of the standard stream I/O classes and objects, including cin and cout. It is mainly used to include those two objects, and the classes they belond to (istream and ostream, respectively) in a source file.

This post explains in detail the role of header files in general, if you are unfamiliar with them.

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

Let's dig a bit deeper with our questions, perhaps. What is your project meant for? Do you need to use C++, or would another language be suitable? Do you already know C++ programming in general? What other languages do you know, and have you done GUI programming with any of them? What compiler do you intend to develop with?

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

Did you read AD's reponse earlier? Even if you had explained the project to us in a comprehensible manner - which you didn't - we don't do homework for people here. Do your work, and when you have a problem, as a question and give us enough information to answer it and we will do what we can to help, but giving you a solution by fiat is not helping you..

In any case, you don't give us enough information to base a solution on. What is 'four bar linkage' etc, and what sort analysis do you need to do? Where is the code for this mystery program you mention? We can't write a program when we don't understand the goals of the project.

As for Turbo C, if your professor is requiring you to use it, walk out of the course and don't look back. Anyone still using a twenty-five year old compiler that was not standards compliant even in its own time is incompetent and should not be teaching anyone anything.

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.

We take this issue seriously here. Very seriously. Asking us to do homework for you is a grave breach of academic ethics on your part, and actually doing so would be an even bigger breach on …

rubberman commented: What more can be said? :-) +12
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

As it happens, there are many answers to the question 'how do I learn how to program?', and which one is most effective to you will depend on how you think and what you want to do.

What is constant in all of them is that you will need to actually write programs, and read programs other have written. Beyond that, though, there is no one size fits all answer.

My personal recommendation is to consider the language you want to learn carefully. Different languages appeal to different people, and some are simply hader to learn than others. C and C++ are both rather advanced, industrial-strength languages with a lot of rough edges and few safeties (from the perspective of a newcomer, at least); while many people start off with them, I would recommend a simpler, more forgiving language as your starting place. Python is a good choice, IMO; my real preference is for Scheme, but that is a bit too unusual for most people, and likely to confuse.

A good book, preferably an eBook so as to be as up to date as possible, is useful, as are online tutorials. The online version of Think Python is as good a place as any to being, I would say. Others will suggest others, and I can't say for sure that this one will work for you, but I would try it first.

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

The general answer is, you can't, at least not meaningfully.

The longer answer is, it is very dependent on the hardware and software in question, both the firmware of the drive and the drivers of the operating system. Even if you were dealing with an isolated case - a single drive running on a dedicated real-time system - the results would depend more on the caching algorithm of the drive controller than the drive's own performance.

In practice, very few operating systems ensure real-time performance or measurement (keeping in mind that 'real-time' means bounded time, not necessarily minimum time). In a general-purpose system such as Windows or the Unices, the use of virtual memory essentially makes predictability impossible.

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

As Rubberman says, you need to do the actual work; we can only advise you and help you fix problems. That having been said, I will give you this advice:

A Queue is a specialized for of collection in which the order that items are added is the same as the order they get removed. It is also called a FIFO (first in, first out) list. They can be easily implemented as either an array (for a fixed-size queue) or a list. The assignment probably assumes a list implementation, but if there is a limit to the size, you would be better off using an array.

Basically, the Queue is a list with both a pointer to the first item and a pointer to the last item. When you add an item, you add it to the head; when you remove an item, you remove it from the tail. You need to make sure that the tail pointer is updated when an item is removed, but other than that, it is a very easy data structure to implement if you already know how to write a linked list.

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

Considering that the last person involved in this thread hasn't been around for half a year, I think you may be a bit late to the party.

In other words, don't resurrect lond-dead threads. We have enough zombies on Daniweb already :)

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

This program is clearly intended to test the function, but it would be helpful to know the overall goal, that is, what the program this test is intended to prepare for is supposed to do. Is this a parsing project for a compiler course, by any chance? It has the feel of the 'convert infix to prefix and compute on the stack' project typically given around week two or three in such courses.

Two questions come to mind: one, is there a reason you are testing a whole string against single characters, and two, is there a reason you cannot use the C++ string class rather than C-strings?

If my guess about the purpose of this is correct, I would advise against testing for the operator as a string and instead tokenize the string character-by-character instead. Trying to read the source string in as a whole and comparing it to the operators will fail for a number of kinds of legitimate input, such as:

"2*6"    // no separation between the tokens

"1   * 6"  // extra whitespace in the token

What you would want to do is read the characters one at a time, and if the character is a number (you can use isdigit() for that), you collect the characters until you find one that isn't a number. You can do similarly for variable names, if you are supporting them in your calculator; use isalpha() to tes tthe first character, then if it is an identifier, collect …

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

While that would indeed play the file, I'm not sure that this accomplishes quite what the OP had in mind. It sounds as if he intended to actually play the file within the program itself, not shell out to a different program to run it. Also, I didn't want to assume he was running Windows.

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

The issue is that bgcolor() is a free function inside the turtle module, not a class method of Turtle. Try the following changes and you should be able to run it (is worked when I tried it):

from turtle import Shape, Turtle, mainloop, Vec2D as Vec, bgcolor
from time import sleep

bgcolor("black")
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Though, i can't make use of any psuedo code.
By that, I assume you mean pseudo-instructions or macro instructions (pseudo-code being something completely different)? I was afraid of that when I saw you were loading an absolute address into $a0. It is an unreasonable requirement, as it forces you to do things the assembler should be doing, but I know that a lot of instructors seem to think it is a good idea for some reason.

<rant>
The problem with that is that it makes loading the address of an assembler label impossible, as you would need to be able to access information internal to the assembler in order to do it. This forces you to use absolute addresses, which is ludicrous. No sane programmer uses fixed addresses unless absolutely necessary, even in assembly language. Labels have been a part of assembly language from the start, and not being able to use them for a reasonable purpose is simply unacceptable. A professor who imposes such meaningless and arbitrary demands on their students should be dismissed from teaching.
</rant>

As for how to tell whether the final value is right, the easiest way is to use syscall 1 to print out the result:

    .data
array: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 0

    .text

main:       
    lui $a0, 0x1001000   #load the address of the array into register $a0
    jal increment        #call the procedure
    add $a0, $0, $v0     # shift the return value …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You are in fact opening the file correctly, but that won't do you much good unless you have a codec to decode the data with, I am afraid. We'd have to know what kind of system you are using (e.g., Windows, Linux, MacOS, FreeBSD, etc.) and what kind of libraries you have, in order to be able to even begin giving you any suggestions.

BTW, MP3 is not an open format, and while most systems have some form of MP3 codec to use, it might be easier if you could use files that are in an open format such as Vorbis or FLAC. I know you may not have a choice in the matter, but if you do, try using Ogg Vorbis.

Mohammed_9 commented: thanks i'll try it. +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The first thing I'll recommend is indenting the code by four spaces, except for the labels; this should make it easier to read. However, I can't tell if you did that or not already, because you didn't paste the code in using the CODE button, and the forum software does not by default retain formatting. So, what you want to do when you post some code is, click on where it says 'Code' at the top of the editing window and paste the code sample into the code window that pops up (if you have a pop-up blocker, you may have to disable it).

The next thing I'll ask is, what emulator or simulator are you using? There are several around for MIPS processor, the most common being SPIM and MARS. While they are mostly the similar, they are some differences in the exact code each takes. If you can tell us which you are using, it would help us figure out what to suggest.

Next, I would suggest using a label for the array, rather than trying to use an absolute memory location. Pretty much any asembler will accept data labels, and most (including SPIM and MARS) let you have more than one piece of data on a line of code.

I would also put a call to system call 10 (exit) at the end of the main function.

Also, by default, the register $ra holds the return address for the function, so the instruction jr should almost always …

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

The ld program is the linker used by GCC (the default compiler used by the Dev-C++ IDE) when building executables. The permissions issue is most likely a factor of where your program is being compiled. Can you give the PATH of the source file, as well as to executable file being created? They should be in a project folder, with the executable most likely being in the /Debug folder of the project. I would check the read-write permissions on the files as well - in Windows, you can right-click on the file in question and go to Properties, and it should show the attributes as checkboxes.

BTW, the Bloodshed version of Dev-C++ you are using is very, very old and out of date; I would replace it with a copy from the Orwell fork, found here. The original Dev-C++ project stopped in 2005, and hasn't been updated since. Orwell Dev-C++ is an update of the original using a current version of the GCC compiler suite. Alternately, you can use Code::Blocks, which is very similar and a bit more flexible.

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

I am afraid you're posting in the wrong forum; you want the JavaScript forum, under Web Development. Despite the names, Java and JavaScript are completely unrelated.

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

I don't think you understand how things work at DaniWeb. This isn't a free homework solution site. We don't do your prject for you; you have to do the work yourself. We may advise you on how to finish a project, and in some cases help you fix a piece of code that isn't working, but you have to show that you've made a good faith effort to solve the problem yourself first.

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

I probably shouldn't do this but, I've gone through the code and removed all the extraneous system calls (which were the source of the duplicate lines) and fixed a number of issues in the code as well. I even simplified the print functions, coalecing them into just two functions of two arguments each.

.data
.align 4
S1: .asciiz "I "
S2: .asciiz "love "
S3: .asciiz "assembly"
string1: .asciiz "The first string is:\n"
string2: .asciiz "\nThe second string is:\n"
string3: .asciiz "\nThe third string is:\n"
string4: .space 16
string5: .space 9
string6: .space 16
S4: .asciiz "\nThe three strings combined are: "
S5: .asciiz "\nWhen string 3 is copied into string 5, string 5 is: "
S6: .asciiz "\nWhen string 4 is copied into string 6, string 6 is: "
L1: .asciiz "\nThe length of the first string is: "
L2: .asciiz "\nThe length of string 4 is: "
.text
main:
    #display all three strings first
    li $v0, 4
    la $a0, string1
    syscall
    la $a0, S1
    syscall
    la $a0, string2
    syscall
    la $a0, S2
    syscall
    la $a0, string3
    syscall
    la $a0, S3
    syscall

    #display the three string when concatenated, as well as copied into S6, and their length
    la $a0, string4
    la $a1, S1
    jal strcat
    move $a0, $v0
    la $a1, S2
    jal strcat
    move $a0, $v0
    la $a1, S3
    jal strcat
    la $a0, S4
    move $a1, $v0
    jal printmessage

    la $a0, string6
    la $a1, string4
    jal strcpy
    la $a0, S6
    move $a1, $v0
    jal printmessage

    la $a0, string4 …
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

Part of the problem you are having is that you aren't concatenating S2 and S3 to S1 in string4; instead, you are overwriting the copy of S1 with S2, then overwriting that with S3. Basically, you are losing track of what registers you are using for what purpose. In strcatSecond and strcatThird (which I still say should be successive calls to a single function!), you should continue using $s0 as the destination pointer (actually, you should be using $a0, but we've gone over that already) in the successive sub-functions:

strcatFirst:
    lb $t0, ($a1)
    beqz $t0, strcatSecond
    sb $t0, ($a0)
    addi $a1, $a1, 1
    addi $a0, $a0, 1
    j strcatFirst

strcatSecond:
    lb $t0,($a2)
    beqz $t0, strcatThird
    sb $t0, ($a0)
    addi $a2, $a2, 1
    addi $a0, $a0, 1
    j strcatSecond

strcatThird:
    lb $t0, ($a3)
    beqz $t0, endStrcat
    sb $t0, ($a0)
    addi $a3, $a3, 1
    addi $a0, $a0, 1
    j strcatThird

endStrcat:      
    sb $zero, 0($a0)       # ensure that the string is zero-delimited
    jr $ra

The other problem, that of why it prints a duplicate 'y', is more puzzling to me: for some reason, in your main function, you are calling system call 11 on the the last character of S4, then doing the same with S5 and S6 later on. These syscalls are completely unneeded and detrimental to the goal.

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

One thing I noticed is that I made a mistake in the stack saves, when I first showed you about them, and all the function which use them have duplicated the error. instead of

sw $ra, 0($fp)

you should use

sw $ra, 4($fp)

You would make the same change to the load statements for the $ra register.

Also, in many cases, I figured out a way to avoid using the $s0 register as swap space, but it does mean an extra load cycle. Instead of saving the $s0 and copying $a0 to $s0, you can simply save $a0 to the stack directly and load it back when you need it:

print4:
    addi $sp, $sp, -12
    sw $fp, 0($sp)
    move $fp, $sp 
    sw $ra, 4($fp)
    sw $a0, 8($fp)

    li $v0, 4
    la $a0, L1
    syscall
    li $v0, 1
    lw $a0, 8($fp) # retrieve the argument from the stack
    syscall

    lw $ra, 4($fp)
    lw $fp, 0($sp)
    addi $sp, $sp, 12
    jr $ra

I doubt it will have a significant impact on the problem you're having but it might.

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

Just what are you comparing for? The equality operator only tells you if they are equal; it won't give you which is the larger of the two. If you mean to determine which of two numbers is larger, you would use the inequality operators such as < (less than) or > (greater than).

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

Which are you more familiar with, and do you have a C++ library for the database engine? Java has standard library support for database work in general (the standard C++ library doesn't have any), but still often needs driver for the specific DBMS. In most cases, the differences in support are negligible. Thus, it becomes (as usual) a matter of 'which do you like better?' and 'what does The Mgt want you to use?'

OTOH, if I could choose, I ditch both in favor of Python.

Oh, all right, what I'd really want to use is some Lisp dialect like Clojure. But what company would allow that? Maybe I'll actually get somewhere once I finish implementing Thelema, but I'm not going to hold my breath.

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

NO.

Don't go hijacking other people's threads. Don't go dropping your homework on us without any context. And most of all, don't go demanding code for a project you are supposed to be doing.

We are a patient and, for the most part, helpful group here. Helping you fix problems with your code is what we are here for. So is helping you improve your programming skills. Helping you cheat isn't part of the deal.

With the attitude you are giving in just this one post, I doubt anyone here will ever respond to you unless you make some contrite apologies right away.

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

The first question I will ask is, how are you representing the matrices? The most common matrix representions in Python would be as a list of lists, or (for constant matrices) a tuple of tuples. However, if you intend more elaborate operations, it may make sense to wrap that in a class. How are you representing them, and why?

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

First off, you should understand that a Python function is not a function in the mathematical sense of a relationship between a set of values n<sub>x</sub> in a domain and a value m in a co-domain. Rather, it is a series of expressions that perform a computation, and may or may not return a value. This can be confusing, if you are coming from a mathematical background.

Also, there is a keyword del in Python that has nothing to do with the three functions variously given that name. You'll want to define your own curl(), gradient() or divergence() function to compute the value in question.

Are the two values x and y actually the vector <x,y>? If so, you would do well to define a vector class, if you know how to. If not, you can use lists to pass the vectors around as a unit. Thus, you would actually define your function as taking three parameters, something like this:

def a(vec, i, j):
    vec[0] = grad(i, x)
    vec[1] = grad(j, y)
    return vec

As I say, though, a class would actually be preferable:

class Vector(Object):
    def __init__(self, x, y):
        self.__x = x
        self.__y = y

    def __str__(self):
        return '<{x},{y}>'.format(x=self.__x, y=self.__y)

    def a(self, i, j):
        x = grad(i, self.__x)
        y = grad(j, self.__y)
        return Vector(x, y)  # return a new vector

    def b(self, i, j):
        # put your function definition here


if __name__ == "__main__":
    vec = Vector(2.0, 7.5)
    new_vec = vec.a(3.3, 4.5)

Of course, this …

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

Oops, I dropped a line. That should have read:

addi $sp, $sp, -12    # set aside 12 bytes of stack space
sw $fp, 0($sp)        # save the previous frame pointer
move $fp, $sp         # <--- set the frame pointer to the stack pointer
sw $ra, 4($fp)        # save the return value
sw $a0, 8($fp)        # save the first argument

More typically, you would add the number of bytes needed by the save registers tp the stack pointer and put that in the new frame pointer; but in this case, we don't have any save registers being used, so we just want the top of the stack.

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

Guidance, certainly; but source code, no, at least not without you showing the effort you've put into it yourself. Post your design ideas and any code you've written, and we'll advise you as best we can.

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

sankubha: I think what stultuske means is, is this going to be embedded software inside the printer (i.e., you are writing it for the manufacturer of the printer), or is this an application running on the printer's host? In other words, where is the program running, and how is it going to monitor the printer?

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

OK, to begin with, why are you using the Save ($sN) registers to pass arguments, instead of the Arg ($aN) registers? I know it may seem like a trivial distinction, but it isn't; the conventions for whay you use the registers for exist so that different programmers and compilers can work together, and while that may not be an issue here, it is simply bad practice to deviate from the standards without a compelling reason.

In case your professor never went over this, the conventions are:

$t0 - $t7 - temporary registers: a function can use them without saving them for the caller

$s0 - $s7 - save registers: functions should always save these before using them, and restore them afterwards

$a0 - $a3 - argument registers: used for passing the first four parameters of a function (if a function needs more than 4 arguments, then they are passed on the stack)

$v0 - $v1 - value registers: used to pass back the return value of a function. $v1 is usually only used when passing a 64-bit value split between voth registers.

$at       - $assembler temporary register: *exclusively* for use by the assembler, should never be used by programmers

$k0 - $k3 - Kernel register: *exclusively* for use by the operating system, should never be used by application programmers

$sp       - stack pointer: holds the top value on the stack

$fp       - frame pointer: used to track the relativ positions of stack arguments

$ra       - return address: holds the …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I think you'll have an easier time of it - and a better grade - if you write a general strcat() function and call it three times.

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

I think what the OP is asking for is how to log printed documents and the IP addresses of the originating computers... but I am not sure.

What that has to do with Java isn't very clear, even if I am right.