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

You may find this page at OSdev.org enlightening on the subject. Basically, the main reason Java in its usual form is problematic for systems programming is that it compiles to a bytecode rather than to native code. While this by itself is not a showstopper - it is possible to compile Java natively, or convert the bytecode to native code (this is what the JIT compiler does, in fact) - it makes it less desireable as a systems language.

There are other reasons, though. It is a garbage collected language, which means that the memory management has to be be in place and running before any Java programs can be run. It does not have programmer accessible pointers, which makes accessing memory-mapped hardware problematic at best. It has in-language threading, which means that the process management and scheduling needs to be in place ahead of time as well. Overall, it is a language with a high overhead.

Mind you, even C++ isn't particularly good for systems programming; there are reasons beyond just Linus' dislike of C++ that C remains the predominant systems language. C++ exception handling and other features are overhead that require a lot of systme support as well.

All in all, either Java or C++ can be used for systems programming, but it would require a lot of prep work to get the system ready for either one, work that would have to be done ain assembly or a true systems programming language like C.

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

Unfortunately, the answer depends on information you haven't given us yet, namely, the operating system you are using (Windows, Linux, MacOS, etc), and if it is Windows, if you are using the older DOS mode or not. The specific assembler also is important, as just how you handle some aspects of it depend on the syntax specific to the assembler. If you let us know these things, we should be able to help.

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

nullptr: While I agree that removing using namespace std; and explicitly scoping is a Good Thing, the problem here doesn't seem related to that. Both of the overloads of pow() reside in the std namespace (and in the global namespace as well, in most cases), so that by itself wouldn't affect the resolution issue.

smitsky: Despite what I just said, nullptr's advice is indeed a good idea, and explicit scoping for the standard library functions is a good habit to get into. While it is common and usually convenient to use the standard namespace as a blanket using, especially for new C++ programmers, doing so contains hidden risks. It is better to get into the habit of explicitly scoping functions and objects from std, or at most to scope individual items specifically like so:

using std::cout;

This avoids a whole host of complications.

BTW, what version of Dev-C++ are you using? The older and better known Bloodshed original hasn't been updated in close to a decade, so if you are using that version, I would recommend replacing it with the newer Orwell fork, or switch to Code::Blocks. That will get you up to date with the latest version of GCC.

nullptr commented: ty + +4
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

While it does add an extra wrinkle to the process, I would argue that many of the conceptual problems you are having will be solved if, rather than having a fixed list which you create statically and then populate, you were to dynamically create the second list by allocating new nodes at runtime. It would make the fact that you are creating a whole new copy of the list rather than just copying the data values. It would also, as I stated previously, make the purpose of linked lists as a dynamic, resizable strcture more evident. If you were to take my previous code example, and make the lists at runtime rather than declaring a lot of node variables, you would see this a lot clearer. This would be particularly clear if you allowed the user to enter the data, and let them choose how many data points to have.

(BTW, main() should always be declared as returning an int, as it passes a status value back to the command-line shell; void main() is incorrect for almost all cases.)

list* copylist_sorted(list a)
{
    if (a == 0)
        return 0;

    listrec old = a ->head;
    list* copy = new list();

    while (old != 0)
    {
        insert(copy, old ->value);
        old = old->next;
    }

    return copy;
}

int main()
{
    list* queue[2];
    int temp;
    char yesno;

    queue[0] = new list();

    do
    {
        cout << "Please enter an integer value: ";
        cin >> temp;
        enqueue(queue[0], temp);
        cout << " Continue (Y/N)? ";
        cin …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, that does clarify things a good deal. Basically, you want a list whose elements are themselves list of characters. This is fairly easy to do, fortunately.

I assume that using the STL list<> template is out of the question, so I would start by defining the node structure or class for the inner lists. If you have already covered templates (unlikely), you could design a generic node class and use that; otherwise, you would probably start with something like this:

struct CharNode 
{
    char data;
    CharNode* next;
}

If you want, this can be a simple POD (plain old data) structure, as shown above, since it doesn't really have any behavior of its own. However, it may make sense to have it as a class, just for uniformity if nothing else. The other node class would be very similar:

struct QueueNode 
{
    CharNode* queue;
    QueueNode* next;
}

As you can see, these are still only singly-linked lists, they are just nested one inside the other.

The real meat of the project is in the list classes, which are just a head pointer to the first node of the list, and the methods which insert, display and delete the elements of the list(s).

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

Are you talking about a queue of queues, or perhaps a tree of some kind (which from some points of view can be seen as a list of lists)? Please try to be as clear as possible about what you need. If this is an assignment, please post the assignment description, so we can see what it is you are trying to accomplish.

Mind you, as I said earlier, we aren't going to just give you the program whole cloth; we can advise you, but we won't do the work for you. We will need a clear understanding of your project if we are to help you, however.

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

No, some functions have no return. These functions are declared as having a void type, to indicate that they don't.

void foo(int bar)
{
    cout << bar << endl;    
}

As for the value of the return and how it is used, that depends greatly on the function in question. For example, the math function pow() returns a double, which is the result of the function's computation (it computes the value of the first argument raised to the second argument). The old C-style input function scanf() returns the number of characters read in. Th character function toupper() returns the upper-case form of it's input, if the character is a letter. It all depends on the function and what it is meant to do.

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

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

Ouch. I should have guessed that would be the case.

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

NameError: global name 'Stack' is not defined – How do i fix this error?

Do you have a class named Stack somewhere in another file? If not, you'll need to define one. Either way, you would also need to import the class into the module you are writing, something like:

from stack import Stack

You would need this in your code before your first use of the Stack class.

If you don't already have a Stack class, the easiest way to implement one is to use a list as the underlying data structure.

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

This is all getting very repetitive, in this thread and others. Can someone make a sticky FAQ with project suggestions?

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

This post may prove helpful. It covers heap memory in detail, while giving an overview of local memory with links to how it is implemented on the stack.

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

Actually, it is not that minor a mistake: you never allocate any listrec nodes for the new list. What is surprising is that this doesn't cause a segfault, as you are writing to an area of memory you shouldn't have permissions for.

There also seems to be a conceptual disconnect on the idea of a linked list at work. Right now, you are creating local variables in main() for the list nodes; this defeats the purpose of a linked list, which is meant to be a dynamic data structure. While it is possible to have a linked list the way you've done it, it limits the size to what you have declared already. Instead, what usually would be done is to allocate the nodes at runtime, and free them after they are finished with:

node = new listrec();

// add the node to the list and use it

// then after you are done, free it
delete node;

I would recommend breaking your main() function up into two new functions: one for allocating a node and adding it to the list, and one for printing the list. I would also add a function for freeing the lists.

struct list
{
   listrec* head;
   listrec* tail;
}

listrec* makenode(int value)
{
    listrec* node = new listrec();

    if (node == 0)
    {
        throw "out of memory error";
    }
    else
    {
        node ->value = value;
        node ->next = 0;
    }
    return node;
}

// add the new value to the head …
catastrophe2 commented: thanks for the explanation and code emphasis scholarlea, however, my professor taught us what i have in my original code and as one who is still not mastered at c++, i have no way to know other methods or better things. i am just going along with what i h +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Since this is a question about C, rather than C++, you should have posted it in te C forum. The two languages are distinct, despite their close relationship. I expect one of the moderators will move it for you.

The first error is simple: whenever you use #if, #ifdef, or #ifndef, you need to follow it with an #endif at some point later in the file to close the conditional. Since this appears to be a header #include guard, you would presumably put it at the end of the source code.

As for the second error my question to you would be, what compiler are you using? The __attribute__ syntax is specific to the GCC compiler, so if you are using a different one, the code would need to be altered to match the compiler you are using.

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

I have long argued that 'Computer Science' is a poor term for what most people study in college, as it generally has very little to with science in even the broadest sense. Most CS classes are either the sort of hybrid curriculum Mike mentions, or else (more often than not) a pure trade-oriented curriculum with no real theoretical content at all.

The term 'Software Engineering' isn't much better, but at least it reflect the prgamatism inherent in working software development. Software engineering as it currently exists has little to do with the rigor of modern physical engineering, however; even achitecture, the 'softest' of the engineering fields, is far and away more rigorous. Software engineering may exist someday, but it is generations - human generations - away from being realized. We are at the mud hut level of software architecture; the Pyramids are at least a lifetime off, and Roman aqueducts and Gothic cathedrals far beyond the horizon, never mind skyscrapers and hydroelectric dams.

I have long advocated a separation of 'computer science' into distinct fields of study, with the main field, Software Management, falling under the rubric of the Psychology or Sociology departments rather than either Engineering or (especially) Mathematics. Why? Because the real fundamental work in software development is social interactions, and the main thing being 'engineered' are the programmers' understand of the clients' needs. Practical IT is more about social psychology and cognitive science (perception of need vs. actual need) than about coding.

The Second field would be …

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

Can you please post the code you are using to call each of the three functions, and especially the section where the error is arising?

Also, who originally wrote this code? It involves some moderately sophisticated techniques, and look it over, I would expect that anyone who knows enough Python (and programming in general) t write these functions would already know the answer to you question.

Anyway... while there is no way to use a local variable that is in one function inside another directly, there are a few different options for sharing variables, or at least values. The first, and least advisable, is to use global functions rather than local ones:

my_global = []

def my_func():
   global my_global
    # ... and so on

This would allow the functions free access to the variables, but it is poor design, as it binds the different functions too closely, and would allow any function access to the variables.

The second solution is to pass the values to result() as function arguments; this would be the most obvious solution, as the other two functions are in fact returning the values you want.

def result(feature_matrix_ip, feature_matrix_db):
    # the rest of the function

ip, rszlist = messageWindow()
db = OPEN()
results(ip, db)

However, that is only an option if you can change the function's signature this way. Finally, you change them from free functions to methods in a class, though you'd have to know more about classes than you seem to …

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

How well do you know C? How well do you know MIPS assembly? In order to understand how to convert from one language to another, you would need to understand, at least to some degree, both languages in question.

As for the two functions, they are not the same, and the first is the simpler of the two, but it is still a little more complex than it may seem at first, because each of the individual lines of code are doing more than one thing, such that they would take at least thwo or more lines of assembly code. To show this, I'll put the C code into an idiom closer to that used by the assembly language:

int  f (int a, int b, int c, int d) {
    int x, y;   
    x = a + b;
    y = c + d;
    if (x > y)
        return x;
    else    
        return y;
}

What isn't evident from this is that returning a value in assembly language is itself a process of more than one step. The returned value has to be stored somewhere where the caller can retrieve it. In MIPS, the convention is to put the return value in the $v0 and $v1 registers (usually, just the $v0 value is used, unless the value is larger than 32 bits). Similar,y the first four arguments of the function are passed in the $a0, $a1, $a2, and $a3 registers. So, in MIPS, the code above would come out as …

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

Oh, I would add that, with regards to GUI programming, you'll usually have better luck with C++ than with C, simply because graphical user interfaces lend themselves to object-oriented design. The complexity of the data structures and the event handling make procedural programming for GUIs rough slogging. It can be done, of course, but it is a lot easier in an OOP language; indeed, it is likely that the main reason OOP caught on was the spread of GUIs. While OOP is not in any way shape or form a panacea for coding, it is uniquely well suited to graphical user interfaces, which involve a lot of large, repeatable, discrete, and composable data structures.

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

Oh, of course you can use C to write a GUI program for a Linux desktop environment; most of the ones you are likely to use under Linux are in C or C++.

However, the "windows.h" header has nothing to do with that. That header isn't for graphical user interface programming (at least not in the general sense); it is, rather, the Microsoft Windows operating system API header, a massive catch-all for Windows-specific system calls including not just GUI calls, but also scheduling, file handling, and Internet sockets. It is a huge collection of Windows functions, but it has nothing to do with Linux, which is a completely unrelated operating system.

There is no single equivalent to "windows.h" under Linux. Partly, this is because the Linux (and Unix) API is divided into many smaller parts; but in the case of GUI programming, the main reason is because Linux itself does not have any Graphical User Interface as part of the operating system. Indeed, one could argue that Linux has no user inteface built into it, as the user shell (whether text or graphics) is a user-side program, not part of the OS. The Linux Desktop Environments are not part of Linux; they can be interchanged and even in some cases run side-by-side at the same time on a single system.

This means that when writing a GUI program in Linux, you need to know what desktop you are using. Common ones include GNOME, Unity (the one which comes with Ubuntu …

JasonHippy commented: Good, clear and detailed answer! +9
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

To address the question directly, I would want to know, how long are you setting sleep(). usleep(), and nanosleep() for, repsectively? While sleep() takes an argument in seconds, usleep() takes one in microseconds, and nanosleep() (as the name implies) takes a structure that has both seconds and nanoseconds. if you are using sleep() with an argument more than 60, then it would indeed seem as if the program has frozen; OTOH, an argument of 99999 for usleep() (just under 1/10 of a second) would be barely noticable, as would any nonoseconds argument less than 99999999 (again, just under 1/10 of a second) for nanosleep().

To get the resolution you want, you may need to make multiple calls to nanosleep(), though that will still give you variable results as it does not guarantee a specific amount of time slept, only a minimum time.

You might also consider using timer_create() instead.

That having been said, what is the real purpose here? Why do you need to slow down the output, and what kind of output is it? Is this a delay for a video game or animation of some kind (in which case you may find a more suitable function in the graphics package you are using)?

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

You won't be able to compile anything with the "windows.h" header in it (or the related "stdafx.h" header) for Linux with any compiler, as that is a Windows-specific header.

If you need to run a Windows program under Linux, you'll need to use WINE and a Windows compiler, and run both the compiler and the compiled program using WINE. Alternately, you can set up a full Windows system as a guest OS using a virtualizer such as VirtualBox.

OTOH, if you want to write GUI programs for Linux, you'll have to specify the desktop manager you want to write for (usually either Gnome, KDE, or Unity) else use a portable library such as GTK+ or Qt.

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

If the goal is to get the number of times a method is called, then the best solution is to apply a profiler, such as jprof or jvmmonitor. There is even one which comes with Java called hprof which will fit your needs, though of them all JVMMonitor seems best. Using one of these would be a lot more flexible and useful than the function you describe.

That having been said, way to write what you want is to have a class variable such as a counter that increments whenever the function in question is called:

class Date {
    private static int fooCounter = 0;

    public Date(int year,int month,int day) {
    }

    public Date foo() {
        fooCounter++;
        // the rest of the function ...
    }

    public int getFooCallCount() {
        return fooCounter;
    }
}

However, if you want to see what the last call return was, you'd change it like so:

class Date {
    private static Date lastFoo = null;

    public Date(int year,int month,int day) {
    }

    public Date foo() {
        Date retval;
        // the rest of the function ...
        lastFoo = retval;

        return retval;
    }

    public Date getFooLastCall() {
        return lastFoo;
    }
}

That having been said, the real solution probably is to use the profiler tools already at hand.

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

There are literally thousands of models of stepper motors, solenoids, and touch screens on the market, so that isn't sufficient information for us to help you with. You'll need to check the documentation on the devices in question, or at the very least tell us the make and model of each. It may also help to let us know how you are connecting to the devices (e.g., USB, RS-232 serial, eSATA, HDMI, a proprietary adapter of some kind, etc.).

I doubt anyone here is going to be familiar with the specific hardware, but I may be wrong; if you give us the details we may be able to steer you in the right direction.

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

The other thing I will recommend is that you consider using a dict (dictionary, or hash table) to look up the translation values that will be sent to the device:

braille_map = {
    'A': [...],
    'B': [...],
    'C': [...],
    # and so on...
    'Z': [...]
}

Where [...] is whatever encoding you need to make.

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

It is certainly possible, though without the details of the hardware we probably can't help you beyond a certain point.

What have you done so far? We cannot and will not do the work for you, though we will try to answer direct questions and give advice towards fixing problems. You need to show that you have made a good faith effort to solve the problem yourself.

We would also need to know what version of Python you are using, as Python 2.x is quite different from Python 3.x and the answers we give may depend on the version at hand.

What I can do is suggest that you start with a with statement, which is the conventional way to open and manage a file in modern Python:

with open("file.txt") as f:
    data = f.readlines()   # get the whole file as a list of strs

This is just one simple example; needless to say, it can be a good deal more elaborate than this.

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

First off, do not hijack an existing thread with an unrlated question. I know that the OP gave this thread an unfortunately generic title, but that isn't an invitation to discuss all aspects of C++ in it.

Second, the question is rather generic itself, and an easy answer is difficult to give, especailly since the fist question is invalid - Bubble Sort is an algorithm (that is to say, a description of how to perform a task), not a data structure (a grouping of data values in a particular manner). The main idea - one simple enough that most people find it themselves on their first try at sorting - is to repeatedly pass over the array in order, and compare each value to the one following it; if the second value is lower, you then swap the two values, and proceed. The result is that the higher values 'bubble up' to the top over successive passes.

There are many pages on the Web which explain Bubble Sort, and sorting in general, and a trivial search should find several such as this one.

A stack or LIFO queue is a data structure, but one which is used in a particular manner - it is ordered in such a way that the last item placed in it is the first one to be removed. The usual solution to making a stack is to have an array and an index …

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

The question doesn't seem to make musch sense. One cannot 'run' a class in Python - a class is a collection of methods and instance variables, and cannot be exectued per se.

I suppose if you are coming from a Java perspective, one could see executing the main() function as 'running' the class, but Python has no equivalent to that - unlike in Java, is is possible (necessary, in fact) to have code outside of a class and run it separately.

The other possible interpretation of your question is, 'how can you have a class method and call it without instantiating the class as an object?', in which case the answer is simple. Class methods are indicate with the @classmethod decorator, like so:

class Foo:
    __count = 0

    @classmethod
    def bar(cls):
        Foo.__count += 1

    @classmethod
    def getCount(cls):
        return Foo.__count   

if __name__ == '__main__':
    Foo.bar()
    print(Foo.getCount())

Which should print 1.

Do either of these answer your question? If not, please clarify what you want.

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

C doesn't allow overloaded functions. Are certain you don't mean C++?

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

First off, you have to recall that assembly language is not the same as the machine code; rather, it is a human-readable representation of the machine code, which is actually a series of electrical impulses inside the CPU. Assembly language is almost a one to one analog to the machine code, but still isn't an exact representation (especially on the x86 processors, as the Intel assembly instruction set often maps a single mnemonic to more than one machine instruction). The assembler converts the instructions into a series of numeric representations of the machine codes, which when loaded into memory make up the executable program (actually, even this isn't quite true, as the 'executable' file is usually in a format that is patched by the loader with the specific memory locations it is loaded to and other details of the binary executable, but for now this is close enough).

Just how it works is going to depend on the details of the hardware implementation inside the chip. I don't know if the current generation of x86 processors uses microcode or not, but most likely they do, in which case some of the machine codes are themselves broken down into a series of simpler steps. In general, though, the operations are performed directly by the hardware, in the form of a series of circuits that alter one set of register and memory valuues to another.

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

When you say you want to clear the character, do you mean you want to insert a space character (' '), ASCII 0x20), or a null character (ASCII 0x00)? These are two different things with different consequences. If you insert a space,

operand[0] = '\0x20';

the string will be " bc", and the string length will still be 3, and the size of the array will still be 4 (you have to count the null delimiter).

Whereas if you insert a NULL,

operand[0] = '\0x0';

you will get "" (an empty string). The array will still have the same size, but the string it holds would be size zero.

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

Given that the querent dropped off of Daniweb over a year ago, I doubt you will get an answer.

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

We all would be happy to help, once you've shown some work on your own part. We are willing to give advice, answer specific questions, and even show how to find and fix bugs. But we will not do the work for you.

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 …

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

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 …

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

OK, that was a somewhat careless mistake on my part; it should have been

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

without the parentheses (which is the whole point of using a property, after all). Sorry.

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

OK, so write the program, and when you have a question, come back here and ask for some help.

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

From the description you give, what you are talking about is a diff tool. There are many such programs around, but I am assuming this is an assignment, rather than simply the need to diff the two files. The three most common algorithms for the problem (in order of increasing effectiveness) are:

You will probably find it helpful to read them in order, because each builds on the previous work.

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

rajii93: I think you missed a few salient points about rubberman's response. First off, he was not seriously proposing that you pay him to do the work (though AFAIK that is indeed his going rate for such projects). The offer was sarcastic; what he was really saying is, if this is an assignment you are doing, you need to do the work yourself rather than trying to get someone else to do it for you.

While we are indeed here to help, that does not equate to us doing your work for you for free. You need to show some effort in the project before we will be willing to assist you.

If you are really determined to hire out the project, try freelancer.com, otherwise, do your own damn work. If you come to a problem you can't solve, ask a question here in an intelligible manner, then we might be able to do something.

In any case, you haven't provided anywhere near the necessary information needed to proceed, so we would not be able to do the work even if we were willing to, simply because there are too many things we don't know about the hardware in question, and about the development tools being used.