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

I would like to propose a link thread for posting listings of sites on CS topics not tied to a specific language. Two that come to mind as being relevant to some of the more common questions would be the OS Dev Wiki, and the similarly themed but less established Compiler Dev Wiki. Rosetta Code would also be relevant, for comparisons between languages and paradigms. A few others to start with might be:

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

So much for the Socratic approach, I will be a bit more direct this time: there are issues with your code design above and beyond the error message you've posted. First off, you only posted part of the code for the second class, which makes it harder for us to judge where the problem is occurring; we can't tell which class Trapezoid inherits from. It looks as if it inherits from Point, which would be incorrect: a subclass should always be a specific case of the parent class, whereas a Trapezoid is not a single Point but a collection of Points which define a type of quadrilateral. Properly speaking, it is Quadrilateral that Trapezoid should be inheriting from, but you seem to be going in the opposite direction, making Trapezoid the parent of Quadrilateral.

The other point is that you are passing just two doubles - which define one Point - to the c'tor of Trapezoid, which isn't sufficient information to define a Trapezoid. In fact, given that a Trapezoid has two sized of matching length and two of differing length, it is safe to say that two Points would not be enough to define a Trapezoid, either; you could define a Rectangle with that much information, if you assume that one of the Points is the upper left and the other the lower right (for example), but that depends on the regularity of the Rectangle's sides. With less regular quadrilaterals, you would be better off defining an origin point, …

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

OK, before you go on with this, cosider for a moment: is a Quadrilateral an example or special case of a Point, or does it have points as its properties? If the latter, how many Points do you need to represent the Quadrilateral, and how many double values are you passing to the Quadrilateral constructor?

Looking at the getArea() method, what is the formula for computing the area of a Quadrilateral, and do derive the necessary line segment sizes from a pair of Points?

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

Off the top of my head, the two other approaches which come to mind - using the enumerate() operator, and using a list comprehension - would both involve things which you probably haven't used before, either. There may be others here who can think of still other approaches, I guess.

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

You need to step through the matrix, just as you are now, but at the same time you need to generate a new matrix and assign the multiplied values to its elements.

def scalar_mult(matrix, scalar): 
    matrix_prime = list()
    for i in m: 
        vector = list()
        for j in i: 
            vector.append(j * scalar)
        matrix_prime.append(vector)
    return matrix_prime
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

This posting may help explain why it is (generally speaking) a mistake to include functions in a header, and what headers are mainly used for in the first place.

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

Sure. Got ten years or so to spare?

More seriously, this question is far too broad to be easily addressed. If I were giving advice, I would start with something like the MIT Open Courseware Intro to Computer Science and Programming, which gives a good starting point in Python (a language well suited for teaching for most new programmers).

(Actually, I would prefer to recommend the older version of this course, which was based on a language called Scheme, but that course is probably a bit too out of the mainstream for most people. The older one is harder, but more complete and insightful IMAO.)

If you are willing to go a bit further, I would point out the [[ORA Python Certificate Program courses]], which are expensive but thorough.

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

The best recommendation I have is to download the Lazarus IDE,

http://www.lazarus.freepascal.org/

It includes Free Pascal as part of the installation.

In light of the fact that the instructor provided the compiler and development tools, I can't promise that getting the current version of either Free Pascal or Delphi would help; if the instructor is requiring the the older Turbo Pascal, then you are pretty much stuck, as the graphics systems have been redesigned since then. I would check with the professor about this before commiting to using the newer version.

If you end up having to use the older compiler and graphics, this page may prove helpful.

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

Knowing assembly is also useful in debugging programs; being able to walk through the generated code with a debugger is a underrated but important skill.

Compiler development also (usually) requires assembly language knowledge, for generating the target code.

Aside from this, understanding assembly language gives significant insights to the actual behavior of the computer system, especially how things like function calls actually work in the system.

That having been said, not many programmers today actually ever need to write assembly code. It is a valuable skill, but more for its side results, rather than for actual use as a programming language.

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

I ran the code, and while it didn't print in the manner you probably would like, it does indeed multiply the matrix by a scalar. What problem are you experiencing with it?

First off, the name matrix() for this isn't really appropriate; it's matrix multiplication, whereas the name matrix() makes it sound like a class c'tor.

On that note, I would say that writing a Matrix class would be a good idea, given that you'll almost certainly want to do more than just multiply by a scalar and print out the results.

I would recommend separating the process of printing the matrix from that of multiplying it; this will, among other things, allow you to keep a copy of the new value, rather than simply display it.

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

Start by declaring a class named Rectangle. Write a constructor (an __init__() method) that accepts arguments self, length and width, and assign the latter two to self.length and self.width inside the constructor.

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

Because the goal of DaniWeb is to help you become a better programmer, not to give you a passing grade you don't deserve. As the DaniWeb Community Rules state:

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

By posting here, you've agreed to follow community standards, remember. Show us what you've managed to do so far, and we'll give you as much help as we can. However, no one here will do your work for you; we will advise, assist, help debug, all of that, but we won't simply hand you the code as if it were yor right. Just as there is no royal road to geometry, there are no shortcuts in learning to program.

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

OK, I'll admit that the assignment is not well written at all. Still, it is not that difficult to work out the intended design, I think. Let's go over what you need to do:

  • Declare and initialize an array of Strings;
  • Open the file for reading;
  • Read in the lines of text into the String variables in the array;
  • Close the file;
  • Display the data in a ListBox;
  • write the data out in pipe-spearated values.

Is there any specific part of this that you are having trouble with, or anything you aren't sure how to do?

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

Setting aside the age of the compiler, can you tell us what you are having trouble with in particular? You will probably have to post at least part of your existing code in order to make it clear where the problem lies. I cannot promise that anyone will know enough about the older graphics libraries to help you, but if you show your effort, we will do what we can.

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

Oh, my. Considering that I was first taught Pascal in 1986 using version 3.0, it is safe to say that this is not current software. That this version is still in use today by anyone boggles the mind. Of course, I suppose that it could be Turbo Pascal for Windows 1.5, which is not quite so ancient, but even then it would date back to the Windows 3.1 days at latest. Why would anyone use 20-year-old software when modern equivalents are available for free?

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

To start with, what version of Turbo Pascal are you using, and is it an old (DOS console) version of something at least from the Windows era? THe name 'Turbo Pascal' was superceded by 'Delphi' (a Pascal compiler and IDE for Rapid Application Development) in the mid-1990s, hence the question. If it is a DOS compiler, how do you intend to run it (since Windows after XP no longer supports the DOS 16-bit code)?

I would recommend replacing Turbo Pascal (if feasible) with either a recent version of Delphi XE (a commercial package) or a compatible free package such as Free Pascal. The Lazarus IDE is a good way to use Free Pascal in a simple RAD environment, and closely compatible with Delphi. Using a DOS-based compiler is going to present an increasing problem as Windows moves away from the DOS box.

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

What have you tried so far? Please show us the existing code, if any.

Note that, chances are, you are going to have to rad the whole file into memory (or at least the part from where you are editing it onwards) and write it back to the file. You may want to use an intermediate file, and then delete or rename the original file and change the name of the intermediate file to that of the original. Something like this:

read the lines in from 'original' up to the mark where you are changing it
write that first section out to 'intermediate'
write your changed text to 'intermediate'
read in the part of 'original' following the changed text
write that out to 'intermediate'
rename 'original' as 'original.old' or something similar
rename the 'intermediate' to 'original'

You would, of course, use the appropriate names for the files, rather than 'original' and 'intermediate'. You would want to look up the os.rename() method to get the details of renaming files.

I would add that the issue of file handling is completely independent of the windowing library, and it would probably be wise to keep the code for the text file change separate from the user interface. Write the function for edtining the file as if you didn't know where the text to change came from; pass the data as an argument to it, rather than getting it from the user directly. You'll find it easier both to write …

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

At this stage, you might want to take this to a new thread, as it is going well out of the original topic; for that matter, private mail may be a better choice in general for this discussion.

Cambalinho: at this stage, I think you are no longer looking at something that could reasonably done as a DSEL, but are talking of a full language. You may want to look into how languages are designed and implemented in greater detail before proceeding. You'll also want to consider what 'features' you need in your core language, and which ones would be better implemented in the language libraries.

Finally, please look at some other existing languages to get a wider view of what already exists - there are literally thousands of languages already designed, and it is likely that something already out there will prove inspiring to you. I think that both Python and Dark Basic might be of interest to you, even if neither quite fit what you are looking for. Take a look at some of the more esoteric languages as well, such Scheme, Haskell, and Erlang, to broaden your view of what programming can be; you'll find that rewarding, I think, even if you never use any of them. You may even find, as I did, that one of them has a perverse appeal to you (hence my own language design work being mostly in …

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

First off, you should be made aware that the forum software does not by default maintain the formatting of code; in order to get the code to stay formatted, you need to enter it using the 'CODE' button at the top of the editing window, else manually indent it by an additional four spaces.

f = open("program0.4.txt", "w")
done = input('Enter done for last name when finished')
Last_Name = input("Enter Last Name: ")
while Last_Name != 'done':

    First_Name = input("Enter First Name: ")
    Hrs_Wrkd =int(input("Enter Hours Worked: "))
    Hrly_Wge = int(input("Enter Hourly Wage: "))
    f.write('Last Name' + ' ' + 'First Name' + ' ' + 'Salary' + "\n")
    Last_Name = input('Enter Last Name: ')

f.close()

f = open("program0.4.txt", "r")
line = f.read()
for line in f:

    info = f.split()

Salary = Hrs_Wrkd * Hrly_Wge
print(line)

    print(Last_Name, " ", First_Name, " ", Salary)

f.close()

Second, while it is certainly helpful for you to post your code, we also need to know what the problem you are having with it is. Could you give us some details about the project, and where it is failing?

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

Setting aside the questionable wisdom of this design approach, the question becomes, what have you done with it so far? As stated in the DaniWeb community rules, we will only help you if you first demonstrate some effort on your own part. Post some code, or a specific question, and we can do something for you, but we cannot and will not solve the assignment outright.

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

Aside from the formatting issues (which I resolved automagically using the GNU Emacs' Pascal Mode auto-indent), I see some definite show-stopping problems with this code. Given your current approach to laying out the board on the screen, you would need something on the order of 350000 'screen shots' to display all the possible outcomes of a game. You are going to have to find some way of generating the screens programmatically. I would start by simplfying the issue, using a simpler display matrix rather than the multi-column approach you are now using, something like this:

   | o | 
---+---+---
 o | x | x
---+---+---
   |   |

This would be much easier to write a generating code for, as you would be able to write an 'x' or an 'o' with a single character. All you'd actually need to store is a cross-bar (---+---+---) a vertical bar (|), and a 3x3 array holding the positions of the already marked values.

program TICTACTOE;
{$APPTYPE CONSOLE}
uses
SysUtils;

const
   crossbar = '---+---+---';
   verticalbar = '|';

type
   Mark = (EMPTY, CROSS, NOUGHT);

var
   Board: array[1..3, 1..3] of Mark;

   procedure initBoard;
   var
      i, j: integer;
   begin
      for i := 1 to 3 do
      begin
         for j := 1 to 3 do
         begin
            board[i,j] := EMPTY;
         end;
      end;
   end;

   procedure drawMarks(lineNumber: Integer);
   var
      i: integer;
   begin
      for i := 1 to 3 do
      begin
         write(' ');
         case (board[lineNumber, i]) of
            EMPTY:  write(' ');
            CROSS:  write('x');
            NOUGHT: write('o');
         end;
         write(' ');
         if i < …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I would start by adopting more consistent indentation practices; as it is, you're all over the place with your indentation. I'll try to get the code indented suitably for you so we can see where things actually lie.

program TICTACTOE;
{$APPTYPE CONSOLE}
uses
SysUtils;

var
   Win,SaveMove,MoveTaken:   Boolean;
   Board:    Array [1..3,1..3] of integer;
   Choice,ComputerChoice,FinalChoice:   Integer;

begin
   {Austin Schroeder}
   Randomize   ;
   Win :=  False;
   while Win  =  False do
   begin
      MoveTaken :=  True;

      While MoveTaken = True do
      begin
         if Choice = 0 then
         begin
            writeln('   |   |   ');
            writeln('   |   |   ');
            writeln('   |   |   ');
            writeln('---|---|---');
            writeln('   |   |   ');
            writeln('   |   |   ');
            writeln('   |   |   ');
            writeln('---|---|---');
            writeln('   |   |   ');
            writeln('   |   |   ');
            writeln('   |   |   ');
         end;
         writeln('Select Placement (Top Left = 1, Top Middle = 2, and so on)');
         Readln(Choice);
         If Board[1][1] = 0 Then
         begin
            If Choice = 1 Then
            begin
               Board[1][1] :=  3;
               writeln('\ /|   |   ');
               writeln(' \ |   |   ');
               writeln('/ \|   |   ');
               writeln('---|---|---');
               writeln('   |   |   ');
               writeln('   |   |   ');
               writeln('   |   |   ');
               writeln('---|---|---');
               writeln('   |   |   ');
               writeln('   |   |   ');
               writeln('   |   |   ');
            end;
         end;

         If Board[1][2] = 0 Then
         begin
            if Choice = 2 Then
            begin
               Board[1][2] := 3;
               writeln('   |\ /|   ');
               writeln('   | \ |   ');
               writeln('   |/ \|   ');
               writeln('---|---|---');
               writeln('   |   |   ');
               writeln('   |   |   ');
               writeln('   |   |   ');
               writeln('---|---|---');
               writeln('   |   |   ');
               writeln('   |   |   ');
               writeln('   |   |   ');
            end;
         end;

         If Board[1][3] …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Would you mind explaining why you need to avoid template arguments in this? I would think templates would be the preferred approach for this, in C++.

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

First, please do not post new questions in existing threads someone else started, unless they are directly relevant to the discussion in the thread. Starting a new thread is much beter. Second, be careful not to double post when you submit your messages. Third, please try to be as clear in your writing as possible, using proper grammar and punctuation as best to your ability.

To address the question you seem to be asking, I'll start by asking, did you use an import ctypes directive before trying to access that library? You always have to import all libraries you are trying to use before using them. Also, user32 is itself a sub-library; you would want to call a specific function from that library such as MessageBoxW() in order to get anything done with it.

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

The problem you are having is three-fold. First, you are using the same names (student_name, School, and Majors) for both classes, and for the parameters to the to Student_Track.__init__(). Second, you are using the names of the classes in your print statement, rather than names of the instance variables (which always bgine with self., remember). Thirs, you are attempting to print the objects directly, without defining a __str__() method for them.

While I have not tested this, I think tha the following will fix the problem:

class Student_Name:
    def __init__(self, student):
        self.student = student
    def __str__(self):
        return 'Student Name: {name}'.format(name=self.student)

class Majors:
    def __init__(self, major, minor):
        self.major = major
        self.minor = minor
    def __str__(self):
        return 'Majors: {0}, {1}'.format(self.major, self.minor)

class School:
    def __init__(self,school):
        self.school = school
    def __str__(self):
        return 'School Name: {0}'.format(self.school)
class Student_Track:
    def __init__(self, school, student,  majors):
        self.school = school
        self.student = student
        self.majors = majors
    def __str__(self):
        return '{school},\n{student}\n{majors}\n'.format(
                                                         school=self.school,
                                                         student=self.student,
                                                         majors=self.majors)

ob1 = Student_Name('bob')
print(ob1)
ob2 = Majors('l','l')
print(ob2)
ob3 = School('o')
print(ob3)
ob4 = Student_Track(ob3,ob1,ob2)
print(ob4)
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I've tested your code (with GCC running under Code::Blocks) and found it to work, which indicates to me that the menu.txt file isn't in the same directory executable. Add the following test to you code right after the open() call:

    if(inData.fail())
    {
        cout << "Could not open menu file. Stopping.";
        exit(-1);
    }

(And add #include <cstdlib> to the start of the program.) This should tell you if it is reading the menu file at all.

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

So basically I need to know for the gcc compiler, how did they manually set the ones and zeros in accordance to the execution environment when you need to know how the execution envirment executes binary.

Just as a matter of note: strictly speaking, the GCC C compiler doesn't manually set the opcodes. GCC itself is just a driver program that parses the shell arguments and directs the subprograms it uses to do the actual work. Compiling a C program as done by GCC is actually a multistage process. While I am not certain about all of the details, as I understand it, the sequence is something like this:

1) The pre-processor, which handles all the directives and emits the compilable source code;
2) The compiler front-end, which generates a system-independent (and language-independent) intermediate form;
3) The inner optimizer, which performs tasks such as constant folding;
4) The compiler back-end, which generates assembly source for the target processor;
5) The peephole optimizer, which optimizes the assembly source for the given processor type;
6) The assembler, gas, which converts the assembly source to object code; and
7) The linker, which produces the program file.

Strictly speaking, there is still one more step as well: the loader, which converts the executable file into the actual executable image at load time.

This multi-step approach is not universal, but most compilers do something like this internally, and the use of a stand-alone assembler is not at …

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

Believe you misunderstood Ddanbe's point, I am afraid. The issue he was pointing out was not the use of the switch() statement; that was fine. The problem is that the variable you are testing, symbol, is never getting set to a usable value. You need to read in symbol after reading in the op1 (not res, as yo currently have it, BTW). So, going back to your original code, it would look like this:

    while(!in.eof())
    {
        op1.ReadMixedExp(in); 
        in >> symbol;

        switch(symbol)
        { //.. etc.
Begginnerdev commented: Yep +9
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Oops, in that last part, repetitions should be an int, not a double.

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

OK, the error you are getting is that flydistance is not declared in the method GetDistance(), correct? And if you look, you'll that this is indeed the case. However, what I suspect really has happened is that part of the code for Fly() was transposed to GetDistance() by mistake, possibly while editing the code. I think what you intended was more along these lines:

     public double Fly(int distance)
     {
         int flydistance;
         flydistance = input.nextInt();
         distance += flydistance;
         batterylife -= (.003 * flydistance);
         // note the use of the 'add-accumulate' and 'subtract-accumulate'
         // operators, they can prove quite useful.

         if (batterylife <= 0)
         {
            System.out.println("The plane has crashed due to low battery life");
         }
         return batterylife;
     }

     public void GetDistance()
     {
         System.out.print("Total Distance:  " + distance);
     }

Note that I also removed the line

         distance = 0;

from GetDistance(); you will want to move it to the beginning of the constructor. As it is now, not only are you resetting distance each time you poll it, before you have displayed it, you never initialize it in the first place, so the values between when you call the c'tor and when you call GetDistance() will be invalid.

I'd like to make a few suggestions, as well. First, you might find it helpful to put the amounts of charge used by the given maneuvers into named constants; this should make it more readable and easier to change later if need be, and is a good habit to …

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

Can you tell us what you are having difficulty with, please?

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

What is happening is that you aren't defining a valid constructor; you have a method static void RCPLANE1(double initialbatterylife), but this only looks like a c'tor. First off, the name is misspelled, with a '1' after the class name. Second, c'tors do not have a return type, not even void.

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

Please do not post offers of this sort here, especially in threads more than four years old.

If you really feel an overwhelming need to help people cheat on homework, fine, that's your problem, not ours. If you want Freelancer.com, you know where to find it.

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

Being the evil little Schemer that I am, I would like to mention a bit of a diversion in the form of a lecture on Netwon's Method as written in a completely different language, using methods which would be difficult (though perhaps not impossible) in C++. You can find the part on Newton's Method at minute 43.30 of the lecture video; howver, you would probably need to back up a bit in the lecture series to make sense out of it, as the description depends on the previous description of the square root method (which is a specific case of Newton's Method), and specifically on the computation of fixed points.

To make a long story short, their version of Newton's Method, written in Scheme (the language in question), comes out to be:

(define tolerance 0.0001)

(define (fixed-point f first-guess)
   (define (close-enough? v1 v2)
     (< (abs (- v1 v2)) tolerance))
  (define (try guess)
    (let ((next (f guess)))
      (if (close-enough? guess next)
          next
          (try next))))
  (try first-guess))

(define dx 0.00001)

(define (deriv g)
 (lambda (x)
    (/ (- (g (+ x dx)) (g x)) dx)))

(define (newton-transform g)
  (lambda (x)
     (- x (/ (g x) ((deriv g) x)))))

(define (newtons-method g guess)
   (fixed-point (newton-transform g) guess))

(This specific approach won't work in C++, as it relies on the ability to generate new functions programmatically. However, it, combined with the pseudo-code in the Wikipedia article linked earlier, should shed some light on how Newton's Method works.)

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

OK, the description is a bit intimidating, but it's also very detailed. You just need to follow the instructions and it should be fine. Given that, can you tell us what you are having trouble with? It would also help if you could post your existing code, so we can see how far along you have gotten.

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

Well, the instructor's hint at the bottom definitely seems to be the place to start, really. I would pick the Individual class first, as it is the simpler of the two; it's really little more than POD, with no methods other than maybe getters and setters.

The Factory class is a bit more involved, as the Factory objects have to be able to mananage their product lines. How you represent the product lines is something of an open question; the easiest solution is to have a simple Product class, consisting of the properties given in the instructions, and have an array or vector<> of Products to hold the given product lines.

The last class you want to define will be for the DistributionCenter itself. This will mostly consist of two arrays - one for the Factory objects and the other for the Individual customers. You will also want methods to add, modify, and remove the elements of these arrays.

ddanbe commented: Good hints for the OP! +14
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Displaying color is something which is system-dependent; there are no standard C++ libraries which have any concept of colors. What operating system (e.g., Windows, Linux, MacOS) is this running under? Which compiler are you using? Are you using the system routines (if any) or a platform-independent third-party library such as Qt or GTK+? Is this to be in a console application, or a windowed GUI application? Just what do you mean by 'display an equivalent color': do you want to show a box or swatch filled with the color, or do you want the text changed to that color, or something else? Is this a simple example program, or part of a larger project?

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

First off, don't forget to delete all memory allocated using new.

Second, if your intent is to print out the table, then you don't actually need the array at all, as Array[x] will always equal x + 1 anyway.

Third, as things are now, you are printing a single entry on each line; it would make a lot more sense, and take up much less space, to write it as a table or matrix.

Fourth, given that you are displaying the results of multiplying by successive integers, you can save a little time at the price of a trivial amount of memory, by using an accumulator variable and adding by x each time:

    for (int n = 1; n <= size; n++) {
        cout << setw(4) << n << ' ';
    }

    cout << endl;

    for (int dash = 0; dash < size; dash++) {
        cout << "-----";
    }

    cout << endl;

    int acc = 0;

    for (int y = 1; y <= size; y++) {
        for (int x = 1; x <= size; x++) {
           acc += y;
           cout << acc;
        }
        acc = 0;
        cout << endl;
    }

Finally, if you wanted to actually have a table in memory of the results, as a two-dmensional array, You would want to declare the table as something like:

    int** matrix = int[size];

    for (int i = 0; i < size; i++) {
        matrix[i] = new int[size];
    }

You could then print out the table …

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

Perhaps we should start by asking:

  1. do you know how to compare two numbers, so that you can get the larger of the two?
  2. Do you know what an array is, how to declare an array in VB.Net, and how to get an element from an array?
  3. Do you know how to get and set the contents of a TextBox?
  4. Do you know how to convert a String to an Integer?
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Can you show us what you have done on this project yourself so far? While we are happy to help you solve your problems, we will not simply hand you an answer without some effort on your part. To quote the DaniWeb community rules:

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

So, can you show us your existing code?

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

If it is at all an option, I would recommend replacing Dev-C++ with Code::Blocks, a more up to date IDE with a similar interface and using the current version of GCC as it's default compiler. Not only does it avoid the problem you describe by keeping the console window open, it fixes many of the other issues found in Dev-C++. Dev-C++ hasn't been updated in 8 years, and uses by default a very dated version of GCC; you can update the compiler, but the IDE itself will still be geared to the older version, which causes some problems in using the compiler as it is today. Code::Blocks is both more flexible and more current, and I would strongly recommend it.

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

First off, the statement makes no sense. What are 'manets'? What sort of trust calculations are used for them? Why do you need such calculations? And most of all, what have you done so far on the problem yourself?

After a bit of searching, I am assuming you are referring to MANETs, 'Mobile Ad-Hoc NETworks'. All well and good, but the term is hardly well-known; a bit of clarification could have been useful there, or at least a full sentence would be nice. It would also be useful if you could explain what sort of 'trust calculation' you have in mind. But that isn't the real problem.

You see, DaniWeb is here to assist programmers working on improving their skills. As a matter of policy, we do not and will not provide source code free of charge without some demonstration of effort on the part of the original poster. To quote the DaniWeb community rules:

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

In oher words: Show Us The Code. Let us know what you have done so far, and tell us what you need help with. We are always willing to help you solve a problem, but this does not mean we will solve it for you.

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

There isn't any kind of procedure in Scheme to do that, no; how could there be, when you aren't actually looping in the sense of an iterative construct? Instead, what you would do is have a different pathway in your conditional which makes the appropriate call.

For example, let's say that in our example where you were generating a list, and you wanted to have it skip, say, the values for 5 and 11 in a range of 20. You would do this in one of two ways. The way closer to what you are talking about would have a test for those cases, with calls specific to the case at hand:

(define (interrupted-range m n . skips)
  (let range-loop ((count-up m))
    (cond ((>= count-up n) '())
          ((memv count-up skips)
           (append (list (+ 1 count-up)) (range-loop (+ count-up 2))))
          (else (append (list count-up) (range-loop (+ count-up 1)))))))

(interrupted-range 0 20 5 11)

However, no self-respecting Schemer would do that for this particular case. Instead, you would generate the initial list, and then filter the list to remove the unwanted values:

(define (int-range-2 m n . skips)
  (filter (lambda (x)
            (not (memv x skips)))
          (range 0 20)))

The point is, there may not be an exact equivalent to continue or break, but there are alternatives that are just as effective.

As for the case where you are populating a list or array, Rubberman is correct; the values aren't separate values, but part of the array in question, and in …

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

The good news is, there is a control structure in Scheme that can be used as either a break or a continue; the bad news is, it is really hairy, and not something you would want to use in most cases. The (call-with-current-continuation) function (abbreviated as (call/cc) in most implementations) is more than just a loop short-circuit; it is a generalized form of goto that allows to to halt a computation, move on to a different one, and then pick up again where you left off. This example (taken from a page of Scheme idioms uses a continuation to break out of a nested loop:

   (define (continued x) 
     (call/cc (lambda (return)
                (let loop ((y 0))
                  (if (eq? x y) (return)
                      (begin 
                        (display y)
                        (newline)
                        (display "next? ")
                        (loop (read))))))))

Fortunately, you rarely need it; in most cases, careful design of the returns from a call can avoid the need to break a loop entirely.

Can you give a more specific case of what you want? Scheme (and Racket) uses recursion for nearly all forms of repetition, including those that would be done by iteration in other languages (what is referred to as a 'recursive iteration' in Scheme parlance). Normally in Scheme, you can escape a simple loop by using multiple returns in a (cond) clause, with the return percolating back up the function-call stack.

As for creating new variables, I'm not sure I follow your question. Are you asking how to generate a list or vector, …

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

Does your professor require you to write your own Stack class? If not, then the java.util.Stack class would solve your issues right there.

OTOH, stacks are easy enough to implement yourself; any linear data structure which allows you to add and remove an element from the same end (that is, in Last In, First Out order) can be treated as a stack, so long as you only change it in that order.

The easiest way to design a stack class is to use an array of the type the stack is supposed to hold - String, in this case, as it needs to be able to hold both operators and numbers of one or more digits - and have an int holding the index to the top of the stack. You the would write a method push() that would copy its argument to the top of the stack, and increment the stack index by one. The pop() method would decrement the index by one, and return the value that had been at the top of the stack. This is, in fact, how the built-in hardware stack used by the CPU itself works (though for various reasons, the stacks on most processors grow top down in memory rather than bottom up).

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

Well, fortunately, all you really need to do is change your System.out.print() calls to .append() calls on your StringBuilder:

            StringBuilder motCache = new StringBuilder(nombreLettres);

            for (i = 0; i < nombreLettres; i++) {
                motCache.append('.');
            }

(I hope that 'mot cache' is the correct phrasing for 'hidden word'...)

You can then print out the StringBuilder object whenever you need it, and manipulate the characters using the .setCharAt() method.

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

OK, that does explain things a little, but it still isn't clear what you really need. It sounds as if you are looking to test whether a given public key's numerical value is prime; but that makes no sense - the whole point of the encryption algorithm is that it uses values too large to be factored in a reasonable time period given current hardware. That's why you select 'pseudo-primes' (numbers very likely to be prime, but which can't be factored quickly) rather than ensuring the primality for the keys.

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

I have to agree with Deceptikon on this: the difference in performance between these two approaches is going to be both minor and unpredictable, as the compiler's optimization could get ruined by the cleverness of the hack.

If your concerned about performance, the best thing to do is to start by profiling the unoptimized performance. This will tell you if and where any optimization is needed. Also, you always want to compare the profile results of the 'optimzied' version with the 'unoptimized' version; you may find that your work has actually made things worse rather than better.

Given your interest in optimization, I would highly recommend reading the Graphics Programming Black Book, as it remains the best text on the subject of software optimization I know of despite it's age.

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

To run a program or script that isn't in a path directory, you need to give at least a relative path to the file:

$ ./filterList

This tells bash where to find the script in question.

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

Could you please clarify what it is you need for us? It sounds as if you are having difficulty with the input itself. Is that correct?

Assuming that this is the case, then there are a few options you can choose. The simplest of these is to use scanf() to read in the number, and checking the return value to make sure that it did in fact read in integer (scanf() returns the number of characters read, which in this case would be the number of actual digits read in).

However, using scanf() directly has its disadvantages; for one, it leaves behind whatever extra characters were in the data stream, such as the newline, which you then have to manually clear. I would recommend instead that you read the data in using fgets(), and then using sscanf() (note the extra 's') to extract the integer from the read line of data.

int possible_prime, retval;
char buffer[MAX_LINE];  // whatever you set MAX_LINE to be

// ... now we skip to where you're reading in the data...

do
{
    printf("Enter a number to test for primality: ");
    fgets(buffer, MAX_LINE, stdin);
    retval = sscanf(buffer, "%d", &possible_prime);  // note the ampersand - we use a pointer to the variable here
} while (retval == 0);