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

Well, technically, every data type is bit data, though not in any useful sense; I think you are confusing the terms 'bit' and 'byte'. No, what I mean is, BIT is the name of the data type in the tables.

How are you building the tables? Are you writing SQL CREATE commands directly, or using a tool for table generation? I'll show you how to create tables in SQL, but if you are generating them automatically, it may not be quite the same. I would recommend generating the tables programmatically anyway, as it gives you better control of the database, but I know it is a lot of work as well.

Clif40RD commented: Helloooo anybody there??????!!!!!! +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I see. That's an unfortunately common problem, and frankly, the best solution is to walk out of the course, making sure the instructor knows why you are getting out. You aren't going to learn anything useful in it if the professor insists on using obsolete technology. However, it is disgusting common for IT departments (and in the cases of India and Pakistan, entire national university systems) to standardize on that particular antique software, so you may not have to option.

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

BTW, what textbook are you using? It might help us understand why you are having so much trouble with it, and if it is as bad as you say, we'll know to steer others away from it.

new2code commented: forgot to mention, i am using VS 2010. which doesnt help me at all +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

That code will in fact work, but it isn't typical C idiom, and isn't quite what you seem to have in mind. Basically, what you are doing with this is evaluating a boolean value and assigning the result to the variable letter. It does not assign the code to the variable, just the value of the result. This isn't what you seem to have in mind.

What you are really asking for, in effect, is how to write a function in C. You have the right idea, sort of, but lack the syntax for how to do it.

In C, a function consists of a declaration, and a body. The declaration and body look like this:

<type> <name> (<parameters>)
{
    <body>
}

where <type> is the function's return type, <parameters> is a list of zero or more variable declarations, separated by commas, and <body> is the actual code. Note the curly braces around the code; that is the basic C syntax for a block of code, and is used in if() statements, for() loops, and while() loops as well. For example,

double sum_of_squares(double x, double y)
{
    double a, b;

    a = x * x;
    b = y * y;
    return a + b;
}

declares a function that takes two double values and retusn another double. For functions that don't return a value, there is a special type, void, which indicates that there is no return value.

So, for the case above, you would probably …

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

Just to clarify to point: you have an existing source file, which contains a complete program (e.g., it has a main() function and can be compiled and run without any additional files), and you want to use a single function out of that file in another program? That explains a good deal about the confusion you are experiencing, then.

The solution is to separate the functions you want to share into a third file, with only the functions, and then create a fourth file, a header file (with the .h extension) which would contain the class declarations and function prototypes. You would then include the header - not the source file - into both the original program (sans the shared code) and the new program, as well as seeing to it that the shared file is in both builds.

So, if you had the following program:

#include <iostream>
using namespace std;

class Foo 
{
private:
    int bar;

public:
    friend ostream& operator<<(ostream& os, Foo f); 

    int baz()
    {
      // do something and return an int
    }
}    

ostream& operator<<(ostream& os, Foo f)
{
     // implement the output operator for class Foo    
}

int main() 
{
    Foo quux;

    quux.baz();
    cout << quux;

    return 0;
}    

and you wanted to use the class Foo in another program, you would remove Foo from the original program (which you really should have done in the first place for modularity's sake), and create both a header and an implementation file:

Foo.h

// this …
mike_2000_17 commented: nice +14
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Unfortunately, yes, it is. This post should help explain why.

The solution is to compile the source files in such a way that they can be linked into a single program. How you would do this is going to depend on the compiler and linker (or in many cases, the IDE) you are using. In most IDEs, including Visual Studio, Code::Blocks, and Eclipse, it can be as simple as making sure that the file is in the same project with the main program source file. If you are using a command-line compiler, you can usually list multiple source and object files in the build command. For example, with gcc you can compile the file foo.cpp to a separate object file,

 g++ -Wall foo.cpp -o foo.o

(...the -o switch says to use foo.o as the output file name, while -Wall means, 'display all the warnings that come up when compiling'...)

then you can combine it with the files bar.cpp and main.cpp like so:

 g++ -Wall foo.o bar.cpp main.cpp -o program

the GCC driver program, which for C++ is g++, will automagically call the linker for you.

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

OK, then. I assume by TASM you mean Turbo Assembler (there's more than one TASM around), probably the DOS version, correct? What version of Windows (I'm assuming it is Windows, but that's hardly going out on a ledge) are you running, and do you know if the assembler even runs (if it is Windows Vista or later, is probably won't)? Are you using something like DOSBox to run it? Are you meaning to write DOS programs, or Windows programs?

Do you need to use Turbo for the project, or can you use a modern assembler such as NASM?

Also, what have you managed to do so far yourself? Do you have any code you can show us so far? What is the final goal of the program?

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

First off, no one here is going to download a ZIP file off of an unfamiliar site, sight unseen. Even if you didn't put a virus in the archive, there are too many ways one could have gotten into it. Please post your code here, using the CODE button, or else put it in someplace visible like Pastebin or a GitHub repo.

Actually, using GitHub would probably be a good idea anyway, as I am guessing you haven't been using revision control up until now. I highly recommend it - it is free (for public repos), it is easy to use, and it has loads of advantages for handling changes in your code. You'll need to download and install the client, and learn how to use it, but it isn't all that difficult.

Second, this is not a free 'do my project for me' forum. We are willing to help you, but we won't do the work for you. Show us your code in a manner acceptable to us, and we will give you what advice we can, but you will still need to carry your weight.

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 …

mike_2000_17 commented: wow, just wow... +14
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

With the help of godek at comp.lanf.scheme (which wasn't so dead as it seemed), I was able to get a working and vastly simpler macro written. For the record, the final version is:

 (define-syntax define-field-pattern
  (lambda (x)
    (syntax-case x (width default =>)
      ((_ name (width w) ((p-0 ... => value) ... (default => value-n)))
       #'(define name `((width . w) (((p-0 ...) . value) ...
                     (default . value-n)))))
      ((_ name (width w) ((p-0 ... => value) ...))
       #'(define name `((width . w) (((p-0 ...) . value) ...))))
      )))

Thanks for everyone who tried working on this for me.

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

boxes2: You should be made aware that this message board doesn't not work like IM, IRC, or Twitter. Repeatedly posting the same message over and over again is counter-productive, as there is often a lag of a day or two before you get a response. Also, messages are not limited in size (or at least not significantly so for most purposes), so posting additional information and/or code samples is both allowable and desireable. Please give as much information as is needed to solve your problem, as clearly as possible, with no IM-style abbreviations and other incoherent text.

Finally, as I said elsewhere, please read the Forum Rules and follow the required rules; in particular, be aware that we are not going to do your work for you, and that if you are going to ask for help, you need to demonstrate that you've made a good-faith effort to solve the issue yourself.

johnkru commented: good comment +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

In OOP terminology, polymorphism is the ability for sub-classes to extend or even change the behavior they inherit from their parent classes. For example, if you have a class Animal, which has an abstract method named speak():

public abstract class Animal {
    public abstract void speak();
}

Then you can instantiate the behavior in the sub-classes Dog and Cat thusly:

public class Dog: Animal {
    public override void speak() {
        Console.WriteLine('Woof');
    }
}

public class Cat: Animal {
    public override void speak() {
        Console.WriteLine(Meow');
    }
}

If you then create an Animal variable, and assign it a Dog() object, the object will respond to the speak() method with "Woof".

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

You should be able to overload the function such that it will use one with a constant function and another with a non-const function. First, let's simplify the existing functions a bit and make them more modern:

// these two utility functions should be private and inline, 
// but I'll write them like this for now.

int BitVector::byte_index(int index)
{
    return index >> 3;
}

uint8_t BitVector::isolate(int index)
{
    assert(index >= 0 || index < size);
    return vector[byte_index(index)];
}

// Returns the bit at the specified index.
uint8_t BitVector::at(int index) 
{
    return static_cast<uint8_t>((isolate(index) >> (7 - (index & 0x7))) & 1);
}

// Replaces the bit at index with that specified by value.
void BitVector::set(int index, uint8_t value)
{
    assert(value == 0 || value == 1);
    uint8_t byteValue = static_cast<uint8_t>(isolate(index) | (1 << (7 - (index & 0x7))));

    vector[byte_index(index)] = byteValue & 0xff;
}

uint8_t& BitVector::operator[](int index) const
{
    uint8_t rtn_value = at(index);
    return static_cast<uint8_t&>(rtn_value);
}

BvHelper BitVector::operator[](int index)
{
    return BvHelper(this, index);
}

Now add a class BvHelper that handles the getter and setter cases, as described here:

class BvHelper 
{
private:
    BitVector& vec;
    int index;

public:
    BvHelper(BitVector& bv, int idx): vec(bv), index(idx)
    {}

    uint8_t& operator int () const
    {
        return vec.at(index);
    }

    uint8_t& operator = (int value)
    {
        return vec.set(index, value);
    }
}

You may need to tinker with this a bit.

ddanbe commented: deep knowledge +15
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 …

slate commented: true +8
iamthwee commented: Excellent and got a chuckle +14
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I wouldn't assume so, no. There's nothing in the standard specifying atomicity, for that or (AFAIK) anything else in C. Even if it is an atomic operation on a specific processor and with a specific compiler, it is not certain to be on others. To the best of my knowledge, there is no portable way to write any form of mutual exclusion entirely in C, or any other language for that matter (while some languages have built-in support or library support for mutex primitives, that sort of thing relies on low-level access to the processor by the language translator and/or the library writer).

In any case, the likelihood of it being implemented in an atomic fashion is very low. In the scenario you describe, it would (on any processors I know of) in the general case take at least three steps to perform: a pointer dereference, a bit set operation (probably AND), and a store back to the dereferenced memory location.

While the x86 architecture has some instructions that are guaranteed to be atomic (with the LOCK modifier), there is no (portable and reliable) way to ensure that the compiler will use them.

The practical upshot of this is, no, that isn't going to be atomic without blocking, and on a modern multicore/multiprocessor system, without memory bus locking as well.

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

If you are asking about RESTful APIs in general, that rather a larger question. To start with, an API is an Application Programmer Interface: basically, a set of hooks into a system, whether an operating system, an application, a webservice - anby large software system, more or less - that allows for programmatic manipulation of aspects of that system. The classic example of an API is an operating system's set of system calls, which allow the application programmer to access, in a controlled fashion, hardware and software managed by the OS.

REST (REpresentational State Transfer) is a particular means of communicating to a web-based service, using the standard HTTP GET, PUT, POST and DELETE operations. A given webservice that applies REST is called a RESTful service.

Thus, a RESTful API is an API that uses a RESTful protocol to communicate with the services it provides.

A more detailed expalantion can be found here.

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

so i don't have to wrire it and i've tried this way many times with different prog and there is no wrong with it ..

Only because you are using an outdated and non-compliant compiler. A modern compiler that follows the standard wouldn't allow it. It isn't the cause of the problem you are experiencing, that's true; but it will trip you up eventually if you don't follow the standard.

but when i tried this prog .. it doesn't give me true results .. so i wonder what is wrong ?? and how can i make it right ?

The problem is in where you have the output, and more subtly, with some minor flaws in both the code and the algorithm. The primary problem is that you need to have an output statement for the case where the while() loop exits out.

(As it happens, there is a much faster and simpler algorithm around anyway. But that's another issue entirely.)

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

firstly main() is C++

Actually, no, it isn't, at least not without the return type. In C++, you cannot define a function without explicitly defining it's return type. Since the standard is for main() to return an int value to the operating system shell, the correct forms are either int main() or int main(int argc, char* argv[]). Since you aren't taking any command line argumwents, you should use int main().

So, let's re-cast the program in modern C++, shall we?

#include <iostream>
using namespace std;

int main()
{
    double n,end,start=0,mid;

    cin>>n;
    end=n/2;

    while(start<end)
    {
        mid=(start+end)/2;

        if ((n-(mid*mid)<=0.001) && (n-(mid*mid)>=0))
        {
            cout<<mid;break;
        }

        if(n>mid*mid)
        {
            start=mid+0.001;
            end=end;
        }

        if(n<mid*mid)
        {
            end=mid-0.001;
            start=start;
        }
    }

    return 0;
}

Now that we can actually read and make sense of it, what problems are you having with it?

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

Assumiong that this is the exact code you are running, the error is that you are omitting the colons following the if: and elif: conditionals.

zahra97 commented: I just tried that, still doesn't work :s +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Actually, Richard, I suspect that that would not be the correct solution to the problem. Indeed, I have a pretty good idea of where this is going.

DkgMarine: Could you please post the whole problem statement? If I don't miss my guess, what your real assignment is is to work with linked lists.

richard.luft.12 commented: yes, after seeing the actual problem, I see that I mis-understood the direction entirely! +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

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

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

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

Mind you, despite the name, a priority queue is nothing like a FIFO queue in its behavior; it rather is a heap which keeps the objects it contains in a particular order. If the class being contained does not have an implicit ordering, this may be the cause of the problem, in which case you would need to define both the underlying container type, and a comparator function, like so:

std::vector <std::priority_queue<PCB, std::vector<PCB>, PcbComparator> > DiskTest[DiskDevices];

...where PcbComparator() is a bool function that compares the values of two PCB objects and returns true if they are in the specified order and false if not. If this isn't the behavior you want, then a priority queue isn't the right container type.

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

Could you post the full error message you are getting, please? (The compiler and OS you are using would help as well.)

If you could also give more information about your goals, it would help greatly in assessing your real needs. When you say that an array of queues doesn't work, can you explain why it doesn't? Why do you think you want an array of priority queues instead? What does the PCB class represent? Is DiskDevices constant? If not, could you use a vector or other type of container of the priority_queues, like so:

std::vector <std::priority_queue<PCB> > DiskTest[DiskDevices];

(Note that I used explicit scoping on the STL types; I recommend doing that rather than using namespace std;, as it gives better control over the namespace. Since it doesn't seem to have had any impact on using std::queue<>, I doubt it is the cause of the problem, but it certainly couldn't hurt anythin except your fingers.)

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

This is something of a difficult question to give a fixed answer for, as the efficiency of 'register painting' (as it is called by compiler writers) depends largely on the context of the program. One thing I will mention is that MIPS makes it a lot easier in general, simply because of the number of general registers (32, though some are reserved for the assembler and the kernel). With only 12 general registers even in long mode (rax, rbx, rcx, rdx, and r8-r15) and several register-specific operations even with those, the register space on the x86-64 is still quite cramped compared to most other modern architectures. It is virtually impossible to write a significant function in x86 assembly without 'spilling' some data into memory.

While this won't answer your question, you might want to read this post, as it may help put the issue into perspective. One important point from that to repeat is that RISC systems were designed to make compiled code more efficient; ironically, this also made writing assembly code easier for novices. The x86, a CISC design, is actually much harder to program effectively in general, both in assembly language and in high-level languages.

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 …

ddanbe commented: remedial basketweaving! +15
Assembly Guy commented: Preach it. +5
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Probably the simplest way is to use the standard function max():

skill = max(0, skill - change)

I notcied that you aren't using any functions for this so far. I know that it is stilla relatively short game, but I can promise you that dividing the program into functions (and classes) is going to be neccessary as things progress, and it is best to start planning how to organize the program sooner rather than later.

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

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

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

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

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

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

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

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

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, 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

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

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.