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

The test code is:

(define-field-pattern foo (width 3)
  ((bar => 2)))

(display foo)
(newline)

This should have printed the line shown above; the actual result was the following error message:

error: attempt to reference unbound identifier bar
  >  (bar => 2)

This seems to imply that it isn't recognizing the pattern at all, but I may be misinterpreting it. Oh, if I add a (syntax) clause after ?name, it does run, but it gives the following:

(#<syntax append> (#<syntax list> (#<syntax cons> (#<syntax quote>
#<syntax width>) 3)) (#<syntax let> #<syntax loop> ((#<syntax pattern>
(#<syntax bar> #<syntax =>> 2)) (#<syntax later-patterns> ()))
(#<syntax expand-pattern> (#<syntax syntax> 3) #<syntax pattern>)
(#<syntax if> (#<syntax null?> #<syntax later-patterns>) (#<syntax
quote> ()) (#<syntax loop> (#<syntax car> #<syntax later-patterns>)
(#<syntax cdr> #<syntax later-patterns>)))))

Which clearly isn't what I am looking for.

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

note: This was also posted to the comp.lang.scheme earlier today. I normally wouldn't cross-post, but after I noticed the extremely low traffic on the newsgroup, I decided to try a more active, if less specialized, forum.

As part of a larger project, I am writing a macro that defines a variable and binds it to a list of pairs, where most of the pairs map a pattern and a value. Each pattern is a list, which may have a combination of symbols and strings.

I am something of a novice with (define-syntax), and have struggled to get this to where I want it to go; while I have learned a fair amount in the process, I apparently don't have a clear enough understanding yet. The current version of the macro, which I've based partly on macro designs from The Scheme Programming Language, 3rd ed. and other sources, is built of three sub-procedures: a fender predicate, a syntax-case which recognizes the individual pattern/value pairs, and the main syntax-case for the overall macro. Given that it is not that complicated a set of patterns it recognizes, I am fairly certain it could be a lot simpler, but this is the best I have managed so far. The code is for R6RS, and I am testing it in Ypsilon 0.9.6-update3.

 (define-syntax define-field-pattern
   (lambda (x)
     (let*
         ((value-fender?
           (lambda (w v)
             (and (integer? v)
                  (> (expt 2 w) v))))
          (expand-pattern
           (lambda (width elements)
             (syntax-case elements (default =>)
               ((default => ?value)
                (value-fender? width …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Put a while() loop around it.

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

I would be amazed if anything written in this millenium that wasn't specifically written in Turbo C would be compatible with TC. It is an MS-DOS compiler that is more than 25 years old, and is not compatible with anything, including the last three versions of Windows. It would be a terrible mistake to write any new programs in Turbo C.

Glade, on the other hand, is specifically a Rapid Application Development toolkit for Gnome, though it does work with most other Linux window managers. While it does have a Windows port, it certainly won't work under DOS.

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

I doubt that MFC would be a wise choice. For better or for worse, it has largely been abandoned by Microsoft in favor of .NET, and while it is unlikely to be phased out entirely, it is not generally used in new applications.

Was there a specific reason you were looking into MFC as a specialty?

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

boxes2: 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.

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

While I would not say you need to know C++ to be a successful programmer, you will not regret learning it, if only because it would give you a better idea of what the Java JVM and similar interpreters are actually doing for you. It is indeed a powerful language, and one worth knowing.

I would highly recommend learning both C and C++, separately. While C++ is mostly a super-set of C, they are radically different in how you approach working in them, paradigmatically speaking. Which you would want to learn first is up to you, some would get more from learning C first, others would be confused by it. I would, however, recommend learning an assembly language as well, more for the detailed understanding you can get from it than for its applicability.

I would also recommend learning a good scripting language like Python or Ruby, as well as a functional language (I favor the Lisp family personally, but that's a distinctly minority opinion) for higher-level abstractions. In general, the more languages you know, and the more diverse the languages you study, the better you will be as a programmer in general.

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

A lot of the answer to this is a matter of perspective, to be honest. In the end, all programs come down to machine code, and assembly language is a direct analog to machine code (mostly). However, that's not far different from saying that all matter comes down to electrons, protons and neutrons - it is true, and understanding it important, but for most purposes it is too low-level to be relevent.

The main places where assembly is directly relevant today is in the implementation of compilers, in the writing of system software such as device drivers, and - this is the important one - in debugging natively compiled code. The ability to debug at the assembly level is actually quite useful, and is too often overlooked these days. It shows you exactly what is happening inside the movement of data, which can save a great deal of effort if you know how to do it.

I would argue that assembly language is less important for its immediate applications than it is for the insight it gives to the way languages actually work - sort of like learning Latin in order to get a better grip on the Romance languages. I do recommend it, as it will make you a better programmer if you learn at least enough to read a program listing, but it is not for everyone, and it is by no means a necessity for the overwhelming majority of applications programmers.

I would add that I would …

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

At the risk of some minor thread necromancy, I would also mention that one of principles of RISC is that all (or almost all) of the instructions be simple enough to implement in hardware in a straight-forward manner, obviating the need for microcode entirely or nearly so. While this isn't terribly relevant to the dominant x86 processors, it is very relevant to CPUs in wide use for mobile and embedded systems, such as the ARM and MIPS architectures. While desktops may be almost exclusively built on the x86 processors, the installed base for ARM in particular is now far larger than any other current 32-bit or 64-bit design - nearly every smartphone uses an ARM-derived processor, as do a significant number of tablets including both the iPad and the Galaxy TAB.

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

what is micro in c programming.

I believe the term you are going for is macro, not micro. A macro is a piece of code that gets replaced by another piece of code at compile time, before the compilation process proper begins. This is called macro expansion, and in C is mostly used as a way of getting the effect of a function without as much overhead. In C and C++, a macro is defined by a pre-processor statement, #define, which indicates that the macro name and parameter list immediately following the #define should be expanded to the . For example, the simple macro:

#define PI 3.1415

... in the following code

area = PI * r * r;

is textually expanded to

area = 3.1415 * r * r;

Note that this is an exact replacement of the string 'PI' with the string '3.1415' in the code itself; the compiler doesn't see the actual PI, just the 3.1415. This is important because there is no type checking or other protection in macros; if you had a macro:

#define SQUARE(x) x * x

and applied it to a sum,

area = PI * SQUARE(2 + 12);

you would get

area = 3.1415 * 2 + 12 * 2 + 12;

which almost certainly isn't what you intended.

For the macro you showed, things get a little more complicated, because it uses the dtringifying operator, #. What …

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

I doubt anyone here is laughing but you. What Rubberman said was serious - deadly serious. No one here is going to do your homework for you, and asking for someone to do so in the way you have is very likely to come to your professor's attention. We have no problem answering a direct question, or helping you to fix a bug, but we won't help you cheat on homework.

This isn't just a matter of scrupulous honesty. If too many people make this site a place where cheaters can come get answers for free, DaniWeb is likely to get shut down. Even if that never happens, we have to face the reality that there are too many fakes, flakes and bottom-feeders in this industry already, and that helping another one get a passing grade is all too likely to end up coming back on us when they end up as our co-workers. We owe it to our own future sanity not to help cheaters get a passing grade.

Now then: do you have an actual question, or should the mods mark this thread as closed?

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

As an aside, assuming you are using ASCII character encoding (or something else with digits in order, such as UTF-8), you can simplify the section in lines 265-282 as:

if (isdigit(k[1]) && k[1] != '0')
    num = k[1] - '1';

It isn't a huge improvement, but it should make it more readable. You'll need to #include <cctype> at the start of the source file. If you actually do want it to set it when zero, simply remove the second part of the conditional cluase.

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

ivan.rodriguezsoria.7: Please check the dates on the thread you are posting to before posting. This thread is over three years old.

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

That sounds like either it got corrupted in the download, or else you are opening the tarball without extracting it. What is the name of the exact file you are opening? The main source file should be in the subdirectory 'src/' and be named 'ekiga.cpp'.

If that is the file you are trying to open, what extractor are you using to open the tarball (the file named 'ekiga-4.0.0.tar.xz') with, and are you extracting it from both the gzip compression and the tar(1) archiving?

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

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

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

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

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

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

Iamthwee is correct, we don't. If you post whatever code you have written yourself, and ask a meaningful question about how to complete the project, we should be able to help, but we will not do your work for you.

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

Are you certain you don't mean to write an HTTP server? TCP is a transfer layer protocol used to send the packets peer-to-peer, and while World Wide Web (HTTP) messages are most often sent across TCP/IP metworks (e.g., the Internet), they are separate things. The server you describe would almost certainly be an HTTP server.

I would look into the http.server library, as that has built-in support for preciesly what you are looking for.

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

The scoping operator (::) is a standard part of C++, not anything specific to MFC. It has three main uses:

  • It indicates the membership of a method to its class, when the function is implemented outside of the class body (which is the usual case). For example, you could have a header with the following:

     class Foo
     {
     private:
         int quux;
    
     public:
         void bar(int x);
         static void baz(Foo neg);
     };
    

    The function implementations would then go in a separate source file.

     void Foo::bar(int x)
     {
         quux *= x; // set quux to quux * x
     }    
    
     static void Foo:baz(Foo neg)
     {
         neg.quux = - neg.quux;
     }
    

    The main purpose of this is to allow the separation of declaration and implementation. Since putting the implementation of any substantial function in a header is a Bad Thing, this is quite important.

  • It is used to indicate class membership for static functions and variables. For example, given the case above, you would call baz() like so:

    Foo::baz(f);
    
  • Finally, it is used to indicate that the function, class, or variable is inside of a namespace. For example,

    std::cout << "Hello, World!" << std::endl;
    

    or

    using std::cout;
    

    This is used to resolve namespace conflicts.

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

I believe what you actually want is to create an isolateral matrix k rows by k columns, where k is a value entered by the user, correct? Tha would be

    int k,sum;
    cout << "Enter the Graph vertex number: ";
    cin >> k;
    int i, j, *a, b[100];
    a = new *int[k];    // create the rows

    // create the columns by row
    for (int i = 0; i < k; i++) 
    {
        a[i] = new int[k];
    }

Note that I used an array of int pointers, which I then populated with int arrays. This is because, unlike with a locally defined multi-dimensional array, the compiler has no way of determining at compile time the number of the rows, which it would need in order to compute the offsets for the columns. By using an array of arrays instead of a multi-dimensional array, you avoid the need to do a lot of extra pointer artihmetic.

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

OK, that clarifies quite a bit. I think what you need is to define the struct type as I explained, and declare a single pointer to that type; then, once you have the number of entries, you would use calloc() to allocate the array of structures dynamically:

struct SCORE_T
{
    char *FirstName;
    char *LastName;
    int  Score; 
}

int name_size;
char *buffer;
struct SCORE_T *scores;

buffer = malloc(21); /* allocate buffer of 20 chars + delimiter */

/* later ... */

scores = calloc(sizeof(SCORE_T), num_scores);

Don't forget to free() everything you allocate at the end.

Now, you may be wondering what this buffer variable is about. That is to hold the input for the names. You would read in the name to the buffer, then get the size of the string with strlen(). Then you would allocate the actual space for the string, like so:

scanf("%20s", buffer);
buffer[20] = '\0';     /* ensure that it is delimited */
name_size = strlen(buffer);
score[i].FirstName = malloc(name_size + 1);
strcpy(buffer, score[i].FirstName);

You would do the same for LastName.

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

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

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

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

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

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

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

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

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

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

Oh, I think that there's a definite issue with the code as written, then. First off, the code is wrong syntactically; if it compiles, I would be surprised. You are declaring all of the structures incorrectly. The correct syntax would be like this:

struct the_struct
{
    char *FirstName;
    char *LastName;
    int  *Score; 
};

struct the_struct *my_struct1, *mystruct2, *mystruct3, *mystruct4;

However, there is a much more serious misunderstanding of the assignment itself. The real purpose is to use dynamic memory allocation, rather than creating several structures locally.

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

i and j does not have the value of theri own. they are just counters.

I believe that this was Moschops' point. You are using them as the sizes in the new expression before they are initialized, with the result that the sizes of the rows and columns are effectively random and most likely zero.

Now, where did you intend to get the array sizes from?

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

Can you explain a little more about your intended design, please? This looks a like a control block for a file handle, but just what you mean to do with it isn't clear.

If it needs to be sorted all the time, then a priority_queue<> as described in the other thread may still be the right approach; either way, you would need to define a comparison function or operator.

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

I suspect the real problem is an old issue which comes up from time to time in C: the fact that the standard C I/O functions are all buffered, stream oriented functions, and that there is no standard way of getting unbuffered ('raw') console input. What this means is that you can't read from the keyboard character by character as it is typed in - you have to wait for the user to hit enter, and get the whole line of input at once (though you can read the buffer character by character once it is entered).

Since you are already using a Windows specific function (namely, scanf_s()), it is safe to say you are free to use the Windows console functions, correct? They are a lot more work, but they will do what you want.

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

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

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

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

Since you don't mention what architecture and assembler you are writing it for, it is hard to judge whether it is correct or not. I am assuming it is for the M68000 processor, correct?

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

Ah, I think I see the problem: the function is a method of the clas, but you did not scope the function as being part of the class in the implementation. When you define a method for a class, and do not implement it inline (which is how most method should be the done - inlining should only be used for one or two line functions), the corresponding implementation has to have the name of the class and the scope operator (::) before the function name. In this case, it should be:

bool DynIntStack::balancedparantheses(string exp) // etc.

You would do the same with bracketname() as well.

I would actually recommend having these two functions in a third file, as the implementation file, and link the file with the program file when you compile it. If you are using an IDE such as Visual Studio or Code::Blocks, it should be sufficient to simply have the implementation file in the project file (under Solution Explorer, in Visual Studio). This lets you treat the class like any other library.

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

Please, don't dig up old threads by posting unrelated questions in them - start a new thread with a title appropriate to you question. Also, you're 'explanation' of the problem is opaque at best.

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.