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

Frankly, I haven't had the chance to look the class over in detail, but my impression is that there is too much being 'baked in' to this one class, and that much of it could be separated out into subclasses. Were I designing this, I would make image an abstract class and use subclasses for most of the actual implementation; an icon subclass would in particular make sense, and move a lot of extraneous code out of the parent class.

David_50's suggestion of caching the images is a sensible one as well. I would use a priority queue (heap) and a Least Recently Used algorithm to track the cache; as new images get added, it would check to see if any images have a priority below some minimum level, and remove those from the heap, while each reference to an image already in the heap would brevet it back up to the top of the heap.

And oh yes, you have too many of you methods - as in all of them - in the class declaration. This is C++, not Java; you will want to move the majority of the implementation code into a separate source file.

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

Ah, a good question, and one I am actually glad to see here. It shows some thought beyond the usual questions here.

However, I should caution you that thater are a lot of ways to approach this issue, and which is going to work for you will depemnd on both your own temperment, your experience, the scope and nature of the project, and who well established the conventional solutions to the problem(s) are. You generally will approach a small project different from a larger one - or rather, you generally want to do as much as you can to break larger ones down into smaller ones, then apply the design principles to the individual parts.

One thing I will say is that your approach will evolve over time, as you become more fluent in the programming languages and techniques. Just as when you arew learning a spoken language, and often have to rely on phrasebooks and dictionaries to get your through until you start to actually grasp the language, so too will you need to work a lot with references and tutorials at first. The difference is that this is a wide-open field, and one that changes rapidly, so chances are there will always be things that will send you looking for reference material no matter how skilled you become.

Not knowing what you're skill level is, let's start with the simplest suggestions first:

  1. Try to get familiar with as many of the common data structures, algorithms, and design patterns …

mike_2000_17 commented: Nice! +14
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Well, the first thing to know is that C++ doesn't have any standard graphics system the way that, say, Java does. So the question of the platform you are working on (e.g., Windows, Linux, MacOS) is relevant. You also need to decide if you want to target just that one system, or several systems; if you have only a single system in mind, you can use the API of the system directly, but if you want portability, you need to use a third-party library such as Qt, GTK+ or wxWindows, which abstract the user interface in a way that does not reference system-specific directly.

Even if you are targetting a single system, such libraries are often a better than the raw system API in any case, as they are usually designed with programmer convenience in mind.

Note that even with a portable UI library, you'll still need to be aware of the differences between systems and their capabilities. Just because the library you are using is portable doesn't automatically make the program work on all the platforms.

The next thing is the question of what you are trying to build. If you are looking for a conventional UI, then the libraries I mentioned are the sort you'll need. On the other hand, if you are looking to do game programming, that would take an entirely different set of libraries, and possibly a full rendering engine, and which one would be most appropriate would depned on the kind of game you …

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

I am fairly certain that Vegaseat was poking fun at the 'Is Lisp a Legacy Language?' thread when he posted this. Or maybe at the whole concept of 'legacy languages' in the first place, especially when questions about new languages like Go also end up getting posted here for lack of a better place to ask. Really, I've always felt that 'Legacy Languages' is a poor name for this section in the first place, as it carries a certain judgement about the languages themselves.

<rant>
I mean, yes, no one is going to argue that languages like COBOL 65, FoxPro, Pilot, or MUMPS are not dated, but if people are still using them - and some are, amazingly enough - how is that 'legacy'? I can see the term 'legacy code', especially when applied to software where the source code, the translator, or the original target system no longer exist, but 'legacy language' really can only refer to one that is directly tied to an obsolete architecture in a way that it can't run on other systems (i.e., it isn't portable).
</rant>

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

The standard Datetime and Calendar classes only work with Gregorian calendar dates; however, after some searching I did find a project on Sourceforge for a multi-calendar utility module for Python, and it does specifically include the Persian calendar. Assuming it works, that may be what you need.

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

@rubberman: It's more like an assembler with a few elements of a high-level language added to it. While there have been several high level assemblers in the past, the one which is currently best known is the one actually called HLA, and used by the book The Art of Assembly, which can be found here. It is intended to make it easier for students to transition from high-level programming to low-level programming, but I am skeptical of this; it sounds like it would confuse students more than help.

OTOH, I'm not one to talk; I'm writing an assembler based on s-expressions and using hygienic macros for extensibility, so I do see the advantages of mixing low-level and high-level code, I just don't think of it in terms of a pedagogical tool.

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

To engage in a bit a thread necromancy, I should mention that Lisp is undergoing one of the periodic revivals it experiences, where people outside of the original Lisp community rediscover the language and try (generally with little success) to make it into something more mainstream. Logo, Dylan and Python came out of previous waves of Lisp interest, and a number of languages have been influenced by things which were pioneered by Lisp but which then went into mainstream use elsewhere, or at least influenced things which did (e.g., garbage collection, lambda functions, lexical macros, higher-order functions, object-oriented programming - in the form of the 'actors model', circa 1966 - functional programming, constraint programming, closures, logic programming, tail call optimization, continuation passing, aspect-oriented programming, etc).

In the mid-1980s, it actually looked to some people like Lisp was set to take over the industry, as Lisp Machines proliferated and interest in AI soared. However, the cost of those machines ($35,000 in 1985 dollars) was astronomical compared to a $10K Unix-based workstation, never mind a PC or a Mac; AI proved to be less useful in the real world than expected (at least in the ways they thought it would be used); and most of all, the performance of microprocessors and semiconductor memories kept climbing until they surpassed the hand-built TTL of the Lisp workstations even for Lisp itself. The whole debacle left the LispM companies in receivership and soured the prospects of Lisp for decades.

There are always a few oddballs …

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

What assembler are you using? Since this looks more like Pascal than assembler, I am guessing HLA, but I am not familiar with it personally so that's at most a guess.

Syntactically, HLA works very differently from your average assembler, and I don't know who if anyone here is going to be familiar with it. Sorry.

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

While I wouldn't actually be Ranma Saotome. I do often wonder how I could find my way to Nyannichuan to take a swim.

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

This post contains several serious (and some not so serious) suggestions that you might want to look into.

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

Imagine knowing from an early age that you are different somehow, but can't understand how - or worse, you do know, but can't get anyone else to believe you. Imagine feeling that something is wrong with you, that the person you seem to be on the outside isn't who you are on the inside, and that everything and everyone around tells you that these feelings are wrong, bad, or worse, just plain ridiculous. Imagine coming to hate the body you feel trapped inside of, a body that you know has to be changed or it will drive you insane. Imagine you aren't sure how you can change it, or if changing it will really help, but still knowing that it is Just Plain Wrong the way it is now.

That apparently reflects the experiences of an awful lot of people in the IT field.

Anecdotally, it has long been said that there seemed to be an unusual number of gender-variant people in the computer industry - whether transgendered, androgyne, genderqueer, gender-fluid, or even just genderless. Several prominent programmers and computer scientists such as Dani Berry, Jamie Fenton, Lynn Conway, Mary Ann Horton, Sophie Wilson and Alexia Masselin are or were transsexual women, far more than one would expect.

There may be more to it than just gossip. A recent survey of the computer field indicates that as many as 2% of all people in the IT industry are gender-variant or gender-dysphoric in some way or another. To put this in …

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

Ah, I see. Well, I can help you out I think. Fortunatel,y functions in Python are dead easy, and once you get the idea of them, you'll probably use them quite a bit.

Using a function is already familiar to you; you used the standard functions len(), print(), and sqrt() already. While len() and print() are part of the Python language itself, sqrt() is actually a part of the math library, and not a part of the core language at all. While the libraries are part of what comes with the language, they are separate from the language itself, which is why you need to use import in order to use them.

Writing your own function is almost as easy, but I should explain a little about why you would want to first. There are three main reasons for writing functions in Python (and most programming languages in general). First, they let you give a name to a particular piece of code. This allows you to ''abstract'' the idea of that piece of code, so you don't have to think about what's inside of it; you can just use the name. Second, it makes it easy to use the same piece of code in more than one place, making the program smaller and reducing the number of places you need to fix if you have to change something. Finally, a function can be ''parameterized'', that is to say, it can let you describe ''part'' of a piece of code, without …

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

OK, you are mostly on the right track, I would say. However, there are things that can be done to improve it. Has your professor covered defining functions yet? If so, I would certainly recommend writing the average as a a function, that way you don't have to repeat the same code in the SD section twice. In fact, I would write all of these as functions, and simply have the main program call them as needed.

Also, while it is useful to have a defined value for the input when testing, don't forget that the actual project assignment calls for getting the input from the user. You should be able to write that as a function, too.

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

We are certainly willing and able to help, but we'd need to know what sort of help you need. What have you done so far, and where are you stuck? Do you know the basics of how to write a function, how to use Python arithmetic, and so forth? Do you know how to calculate the mean, median. etc. by hand, and how you would apply that to writing the program?

Also, what version of Python are you using (2.x or 3.x), and is there a specific environment or IDE you are using for developing the programs?

I will caution you, though: do not expect anyone here to write the programs for you. We will assist you, but we are not a free homework-solving site. Show us that you've made an effort, and we will do what we can to aid you, but we will not and cannot do your work for you.

Gribouillis commented: indeed +14
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Well, first, can you give us some more detali about what it is doing, and where it is failing?

I did note that you are calling the swap routine with a branch, and then explicitly jumping back to processArray. I don't know if this is related to the problem you are having, but it seems an odd way to do this. Has your professor covered the Jump/Branch and Link (jal, jalr, bgezal, and bltzal) and Jump Register (jr) instructions yet? Instead of

slt $t5, $s1, $s2 #$t5 = 1 if $s1 < $s2
beq $t5, $0, swap

I would normally use

sub $t5, $s1, $s2   # $t5 is negative if $s1 < $s2
bltzal $t5, swap

which automagically saves the address after the instruction in $ra, and then use

jr $ra

to return from the call; this makes for a more flexible subroutine that can be call from more than one place.

As for how it is failing, I'm guessing that it isn't getting all of the elements sorted in the desired order, correct? That's because your sorting algorithm is incomplete. What you have hit upon is call bubble sort, and it is the sorting algorithm that almost everyone comes up with if asked to do it on their own. The problem with bubble sort is that it doesn't sort the whole list on the first pass. Let's say you have a list of five items:

6, 3, 5, 7, 2

When …

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

That's correct, except that either the size of the declaration should be resd (32-bit - my mistake in my earlier post) or the size of the operand should be word (16-bit). Which you want depends on the how high the score can go - 16-bit unsigned values go only to 65536, while 32-bit unsigned go over 4 billion. If you expect the scoring to exceed 65536, then use a dword or even a qword (64-bit).

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

That depends on what the label userscore is for. Is it a single dword holding the value as an integer, or is it a byte buffer holding a string? In other words, assuming NASM syntax, is it:

userscore:    resw 1  ; or 'userscore dw ?' in MASM 

or

userscore:    resb 8   ; or some other arbitrary size string

If it is a string, then yes, it would need to be converted first, then added to, then converted again. However, in that case, you may find it more useful to have userscore stored as a dword in integer form and only converted to a string when being displayed.

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

In light of the regular if slow traffic in certain specialized questions - especially regarding operating systems development and compiler development - I would like to suggest that a sticky be added to the Software Development forum giving links to specialized sites such as OSDev.org, where those sorts of questions are more likely to find a ready answer. It should be a mod-access only thread, so that it isn't flooded with questions about the subjects or with links to irrelevant sites, but there should be a suggestion to PM the mods if you have a site to add to the list. Does anyone else think this is a good idea?

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

For which operating system, and for what sort of devices?

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

And Schol-R-LEA I am sorry you don't like my name. I have used it for many years and really just came up with it.

Oh, no worries. I actually like it, but it just seems a bit ominous to me as someone who grew up in the 1970s and 1980s. I don't know if you even know what the MX missile was...

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

I think you'll find that the code you have used in that specific section is not Java, but JavaScript, a completely unrelated language despite its name. Java does not have a function keyword, among other things.

(On an unrelated note, I might add that your screen name is somewhat... unnerving to me. Perhaps I've watched too movies like WarGames and By Dawn's Early Light too many times.)

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

To clarify, the link to the list of forum rules can be found at the bottom of any Daniweb page. The most relevant rule here is:

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

The purpose of the forum is to assist new programmers in learning how to program. It is our collective view that simply providing solutions for homework problems does nothing to further this goal. As a matter of principle and pragmatism (since we don't want incapable programmers graduating with degrees they didn't earn, and then working with us in our companies), we are bound to limit our answers to guidance and hints rather than full solutions.

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

Assuming you aren't being required to write your own trig functions - a daunting task - then the functions you want are in the legacy C library header, <cmath>. That's about as much assistance as we can give, however, until you have demonstrated some effort on your own part.

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

You are required to use Turbo C++, then? Is this a policy of the professor, or of the institution?

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

While SenthilAnand's point is correct, and excellent advice, it is not the source of the compilation error; the compiler is perfectly happy to let you perform an assignment in the conditional, it just usually isn't what you intended and will have unexpected results when run.

The real problem is that you are putting semi-colons after each if() statement's conditional, ending the if statement. Now, once again, this is for the most part accpetable syntax, until you get to the last of the else if() clauses:

    if (sales <= 0 && commission == -1)
        ;
    else if (sales <= 10000 && commission == sales * 0.2)
        ;
    else if (sales <= 40000 && commission == sales * .05 + 2000)
        ;
    else if (sales >= 40000 && commission = sales*.1 + 17000)
        ;
    {
        //calculate and display the output
        sales = sales <= 0 ;
        commission = -1 ;
        sales = sales <= 10000 ;
        commission = sales*0.2 ;
        sales = sales <= 40000 ;
        commission = sales*.05 + 2000 ;
        sales = sales >= 40000 ;
        commission = sales*.1 + 17000 ;
        printf("\nsales %d ", totalsales);
        printf("\ntotalcommissions: %.0f%% \n\n", commission);//zero decimal places
    }
    else

(Note how I have indent the code for readability, and in particular, how I made the empty bodies of the if() statements explicit.)

Now, one thing many starting C programmers aren't aware of is that you can put a block (a section of starting with an open brace and ending with a close …

ddanbe commented: The final touch! +15
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

No, you don't. You want to stay away from gets() entirely, in fact. The function is extremely dangerous, because it is prone to buffer overruns, and no experienced C/C++ programmer still uses it.

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

If you have Windows Vista or later, you won't be able to install Turbo C++, at least not directly. Turbo C++ is simply too old, being a 16-bit MS-DOS program, and is no longer supported by modern versions of Windows. In order to install it, you would need a DOS emulator such as DOSBox, or set up a virtual machine image with an installation of DOS or an older version of Windows in it.

Personally, I would recommend against using Turbo C++ in any case, if you have any choice in the matter. I realize that there are many Universities and even national collegiate systems which have standardized on it, but it is simply outdated and trying to learn modern programming from it is going to be misleading at best. You would be better off downloading Visual Studio Express, Code::Blocks with MinGW GCC, or Pelles C in order to get a decent, modern compiler and IDE combination. This may not be an option for you, but you shold at least be aware of the limitations of Turbo C++ before installing it.

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

That's an extremely broad request, and one that on the face of it we as a forum couldn't really fulfill. We can give assistamce, as best we can, but providing a full course on C++ goes well beyond what we can do here. You really ought to speak to your instructor for further aid.

I can give you some help, certainly. The first thing of note is the structure of the main function, which is important because all other functions you will write follow the same basic design. The main function consists of a return value - which in thish case must always by int - the name of the function, which is main, and the argument list, which can be either an empty list, (), or the two standard command-line parameters, (int argc, char* argv[]). This is followed by a block, which is an open brace, {, the code you want in the program, a return 0; statement, and a close brace, }. Putting it together, it should be

int main()
{
    // your program here
    return 0;
}

Note the way I indented the code inside the body of the function. This is very important for making the function readable. While the language does not require indentation, you should always format the code in some manner to make it easier to read. There are several indent styles one can choose from, each with its own advantages and disadvantages, but the important thing is to …

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

The problem isn't with how you are loading the character into the array, but where the $a0 register is pointing when you go to print it. Remember how you incremented it by one when you went to insert the zero delimiter? Well, it's still pointing at that delimiter. a better solution might be:

.data
time: .space 12

.text
main:
    la $a0, time
    li $t0, 49
    sb $t0, 0($a0)
    addi $t1, $a0, 1
    sb $zero, 0($t1)
    li $v0, 4
    syscall

    li $v0, 10
    syscall

Doing that preserves the value of $a0 for the system call.

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

OK, so your real goal has to do with implementing a property system in C++, then?

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

OK, you have some pseudo-code outlining the basic direction of the program, but you haven't told us what you are having trouble with yet. It isn't clear if the pseudo-code is yours or if it was provided as part of the assignment, though if the latter, it has some definite problems. Can you give us more detail as to where you are having difficulties, please?

I should add that the fact that you are using the conio library is concerning, as it is not a standard library at all, being tied specifically to the old MS-DOS system, and it is used in your pseudo-code just for the purpose of pausing the screen, which shouldn't be necessary with a current IDE (and can be achieved in other fashions in any case). If your instructor directed your to use that, it is a Bad Sign regarding the course.

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

What exactly are you looking for help with? Are you trying to find an algorithms book with examples in C++? A qucik search on Amazon turns up several, and while some are clearly out of date, even the older examples would probably be of use. I would try Algorithms in a Nutshell as a starting point, as it is approachable, inexpensive and available as a Kindle e-book. Another choice, which uses C but mostly can be applied to C++, is Introduction to Algorithms, which is much more extensive but not as easy to follow.

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

Most of these error messages seem to stem from the lack of a declaration for the CvEM class, either directly or indirectly. Are you certain you have all of the headers included that you need?

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

This looks an awful lot like an exam question, which makes me wonder if I should bother, but here goes.

Regarding the loop itself, do you know how to a) set a register's value to zero, b) compare two values for equality, and c) add one to a register and store the result in the same register? This is assuming a naive implementation; there are ways to do this that would be more efficient, but I figure I'll keep this simple.

Inside the loop, you have the bases of the two arrays given to you in the $a0 and $a1 registers. You will need to increment the registers on each pass of the loop, to walk through the arrays. You will also have to add the value in the second array at a given index to $s0, and store it in the offset value of $a0. This should be trivial, if you have done what has already been mentioned.

Oh BTW, does the instructor allow you to use psuedo-instructions such as la and move? That will make things much easier if you can.

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

I don't know ARM assembly from prior experience, but I would start by looking up the Cortex M4 documentation, if you haven't already done so, and get familiarized with the relevant instructions, especially those involving memory access. Assuming you are using characters in the ASCII range, you'll specifically want the LDRB and STRB instructions, or some variants thereof. Also, if you know that it will be exactly two 8-bit unsigned char values (since you don't want to touch the zero-delimiter at the end of the string), the REV16 instruction should do the actual swap with a single operation.

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

Well, then, that's quite a problem. What have you tried so far? Did the instructor provide all of the necessary information for you to compute the voltages? Have you discussed the matter with the instructor?

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

<iostream> and <cmath> are the headers for two different parts of the standard C++ library. The <iostream> library contains the basic input and output classes and objects, including cin and cout. You include it whenever you want to work with I/O streams.

The <cmath> library, as the name implies, contains a variety of mathematical functions and constants, such as fabs() (floating point absolute value) and cos() (cosine). It is an extended version of the library inherited from the C language, hence the 'c' at the beginning of the header name. A full listing of the functions in that library can be found here. You would include it whenever you want to use one of those functions.

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

Well, to answer the question, the usual solution to having a multidimensional ArrayList is to declare an ArrayList of ArrayList of the type being stored:

ArrayList<ArrayList<String> > data = new ArrayList<ArrayList<String> >();

data.add(new ArrayList<String>());
data.add(new ArrayList<String>());
data.get(0).add("Alex");
data.get(0).add("31");
data.get(1).add("Burren");
data.get(1).add("Java");

However, no experienced Java developer would ever do this. The usual solution is to design a class that holds the personal data for the individual - yes, even if it is a one-off - and have the name, age, and ArrayList of pet's names as instance variables of the class:

class Person {
    public String name;
    public int age;
    public ArrayList<String> pets;

    Person(String name, int age, String ... pets) {
        this.name = name;
        this.age = age;
        this.pets = new ArrayList<String>();
        for (String pet: pets) {
            this.pets.add(pet);
        }
    }
}

public class myProgram {
    public static void main(String[] args) {
        Person myPerson = new Person("Alex", 31, "Burren", "Java");
    }
}

I made the fields public for this example to keep it simple, but usually they would be private and give them getters and setters - you wouldn't want uncontrolled access to them, in case someone accidentally changed age to -17, for example.

You'll also note that the c'tor uses a bit of an odd parameter list: the elipsis (the ...) means 'follow this with zero or more arguments of type x before this and put them in an array named y after this'. You don't need to worry too much about it, just know that it will …

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

I think you will find that the problem lies less with your program than it does with the way Notepad renders the codepoints. I don't know all of the details of how Notepad determines how to interpret the characters, but if I read what you are saying correctly, it basically only checks whether the the first few characters are in the ASCII range, and if they are not, it interprets the file as UTF-8; but if the first character is in the ASCII range, it interprets the file as ASCII (or more likely, either LATIN-1 or ISO-8859-1). The stream of bytes you are writing is correct; it is the interpretation of them that Notepad uses that is at fault.

If anyone knows how to force Notepad to interpret a file as UTF-8, please speak up. This video purports to explain how, but it is not a trivial process, and appears to involve registry changes.

In the meawhile, I would instead use an editor that supports multiple encodings such as Notepad++ or TextPad.

However, if the real issue is permitting your user base to edit the file manually, then that is a serious problem with no obvious solution.

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

A few questions and suggestions:

  • Why did you include a null constructor? You generally only want a default c'tor if there is a reasonable default to provide, which in this case there really isn't. A null c'tor is generally a Bad Thing, as it looks like a proper default c'tor but doesn't actually initialize anything.

  • Do you really need to expose the number format? Generally speaking, this isn't something that is going to be changed over the course of the program lifetime. Furthermore, you don't actually use the number formatter to format the number values, so it's hard to see why this is included here at all. Since you are dealing with currency, and presumably the local settings are suitable, you should be applying the number formatter to the currency values when you display them (though see my next comment below).

  • In Java, all classes inherit the toString() method from the root Object class, and the usual solution to displaying an object is to use its toString() method. If you replace your display method with an override of toString(), and pass that string to the print method, you'll have a more flexible solution.

    @Override
    public String toString() {
        // Use the StringBuilder to create the string using the
        // fast append() method, then return the string 
        StringBuilder sb = new StringBuilder();
        String NEW_LINE = System.getProperty("line.separator");
    
        sb.append(Product Number: ");
        sb.append(getItemNumber());
        sb.append(NEW_LINE);
        sb.append("Product name: ");
        sb.append(getProductName();
        sb.append(NEW_LINE);
        sb.append("Number of Units in Stock: ";
        sb.append(getUnitsInStock());
        sb.append(NEW_LINE);
        sb.append("Product Price: $ ");
        sb.append(nf.format(getPriceOfEachUnit());
        sb.append(NEW_LINE); …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, I see a few things you didn't mention, such as a) the particular emulator you are using, and b) whether you are running in realistic mode, with load and branch delays. I also see a major flaw in your algorithm.

As it is now, you are stacking the original return address (and the value of $t0, which is unusual - the normal MIPS calling convention assumes that the temporary registers aren't preserved in calls). You then call your echo function, which has the effect of leaving the return address of line 7 above (or 8, if you have delayed branches on) in $ra. You then do a test that branches to the top of the recursive function if the character value is not an asterisk. The problem with doing this at this juncture is that you are then stacking the return value of the call to echo, not the return to the branch location. You would need to use a branch on equals and jump past a jump and link to the recursive call to get the desired effect.

(The trick you are trying to use does work, but only with tail recursive functions, where you are basically reusing the existing stack.)

So why does it seem to work, except for the asterisk? Well, to be honest, I'm puzzled by that, and I haven't time to work it all out in detail.

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

(most IDE's refer to "intellisense" as "Code Completion", especially for linux)

That's because the term 'Intellisense' is a trademark of Microsoft. Other developers can't use that name. In any case, 'auto-completion' was the term used long before Microsoft introduced their version of it.

As for IDEs, I think both PyCharm and Eric have good auto-completion, but I'm not sure if either one have quite the feature you are looking for.

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

First off, you'll want to use the tab escape sequence, "\t", rather than the tab character itself in your string replace. Second, your are returning the function at the end of the first pass of the loop; you seem confused as to how you want the function to work, whether it should operate on the input directly or take a local argument. I would recommend re-writing it to take a string argument and return the modified string, then call it from a loop that does the actual input and output.

On the subject of input and output, if you are writing a filter, I would recommend a with statement on sys.stdin and a loop on readlines() rather than an explicit input() statement.

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

Change restockfee to double.

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

It looks like you should be setting the restocking fee when you instantiate the object, so change the c'tor for CarsImpl thusly:

CarsImpl(long productID, String productName, long unitsInStock, double unitPrice, String supplier)
{
     super(productID, productName, unitsInStock, unitPrice);

    this.supplier = supplier;
    this.restockfee = (5 * super.getTotalValue()) / 100.00;
}

Then change the return value of the Cars version of getTotalValue() to long. Now you can make the CarsImpl version of getTotalValue() just:

public long getTotalValue()
{
    //added 5% restocking fee
    return Math.round(super.getTotalValue() + restockfee); 
}

This will return the nearest integer value foe the return value of the total value.

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

No, please, don't. That book is a terrible introduction to C++, and does not really cover data structures to any real degree in any case.

Fardous: what do you already know of programming in general, and of C++ in specific? What do you know of data structures in any other languages, if anything? That would help us give you the best advice we can.

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

I'm not sure I'm following you. Are you saying that the reason it returns a float is because of the restocking fee?

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

That is because the getTotalValue() in Cars is a) not public, and b) type int, not float. An overriding method has to be of an access category as restrictive as or more restrictive than the method it is overriding, and cannot change the return type of the method.

BTW, where did you get throwing an UnsupportedOperationException as the body of this method? It looks like you're using an IDE that generated this body, and you never changed it. What should the getTotalValue() in Cars be, and what should type should it return?

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

This was my fault; I copied the c'tor from CarList, rather than Cars. The c'tor should be:

public Cars() {
   this.prodNumber = 0;
   this.prodName = "Ford Probe";
   this.unitsTotal = 1;
   this.unitPrice = 5000;
}

However, the fact that you don't seem to understand the issues at hand is concerning to me. I am wondering if you really understand the idea of constructors in general. You seem to be doing a lot of copy and paste coding without understanding what you are doing.

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

It's very hard to say why it didn't crash, but I'd say mostly you were lucky. What I think may have happened was that you were deleting the elements but not allocating new ones, in which instance it was likely that the freed memory still held the same data it had when it was freed. If you had been alternating deleting and adding nodes, things may have gone differently. The real question to my mind is, why didn't it segfault when you allocated too small a space for the elements in the first place. but the answer to that would depend on the details of the memory allocator. I'm betting, though, if you had entered several nodes in the list, and then gone to look at the earlier entries, you would have found that they were partially overwritten with data from the successive nodes - though again, the details of it depend on how the memory was being allocated.