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

You will, I suspect, find the online textbook The Craft of Text Editing quite useful for this purpose, if only because it gives examples for each of those tasks.

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

Uhm, first off, what language is this in? It certainly isn't standard C++, not unless you've been doing funny things with the pre-processor. Even that wouldn't explain the lack of semi-colons. Is this supposd to be in an actual language, or is it pseudo-code used to explain the algorithm?

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

What exactly is the behavior? Does it print the shoe data out correctly, or is that also failing?

One problem I see is that when you add an element, it overwrites the first one, rather than adding it to the end of the array. You probably want this:

    //Add new element/////////////////////////////
    cout << "Enter Name, Number and Date: ";
    cin >> Shoe[num].Name >> Shoe[num].Number >> Shoe[num].Size;
    num++;
    //////////////////////////////////////////////

Note that this only adds a single element, at that, since it isn't inside a loop.

As for converting the code into separate functions, this should be fairly dimply to do. The main complication is that you'll need to pass the count of the actual element explicitly to the print, insert and write functions. You can get that count from the read function:

int readShoes(fstream source, Shoe& shoe)
{
    int i = 0;  //counter
    int num; //number of components in file

    input_file >> num;

    for(int i=0; i<num; i++)
    {   
        input_file >> shoe[i].Name >> shoe[i].Number >> shoe[i].Size;
    }

    return num;
}
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Please post what you have done already so we can advise you about it.

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

(duplicate post removed)

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

OK, now that the necessary roughness is out of the way, we can actually begin helping you.

I do have to admit that this is terrible code, and most likely cannot be remediated; but it would be remiss of me not to point out why it is bad, or else the OP won't learn from the experience.

Aside from the formatting issues, the main problem is repetitiveness; you have cut and pasted the same basic code, with only a trivial addition made to it at each step, roughly 20 times, jut in one section of the code alone. This entirely black of code could be replaced with a single for() loop about five lines long. Such repetition is found throughout the code, making it larger and harder to read across the baord.

Similarly, you have (as Phorce points out) created 20 variables with the name in the form x{nth} for what would normally be a 20 element array. Not only is this an exceedly bad naming convention, it limits how you can use the values compared to the equivalent array. Equally atrocious is the use of the n{letter} for what would again be a single 20-element array normally. In fact, the naming conventions use in the program are uniformly awful.

Still, as Deceptikon says, it is the completely lack of indentation that is really doing you in here, as it makes it well-nigh impossible to be certain how the braces match to each other. Even if one is disinclined to …

Nick Evan commented: I've gotta give you credtis for trying to wade through this.. +14
phorce commented: Was there any need to re-post the whole code again? Even if you did fix it! Sorry but, from the previous posts and the fact the o/p hasn't replied to any comments, I think you just might have wasted your time. +6
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, my bad on that; it should have read #define, not $define. I apologize for the mistake.

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

With the exceptions of inline functions and templates, you do not want to have function implementations inside of a header file. You generally need to separate then out of the header and into a code file that will be compiled. Also, you want to use #include guards around the header files themselves, to prevent multiple inclusions in the same compilation unit. This should give you two files that look like this:

story.h

#ifndef STORY_H
$define STORY_H

class Story{

public:
    Story();
    ~Story();
    void mainMenu();
    void start();

private:
    void levelOne();
    void judgement();
};

#endif

and

story.cpp

#include "story.h"



Story::Story(){

}

Story::~Story(){

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

OK, I tried out my own suggestion, and found that it didn't solve the problem. However, I did determine that putting double-quotes around the text does get it to work:

subprocess.call('echo "{0}" | festival --tts'.format(line), shell=True)

I'd still recommend using PyTTSx, though, if it is an option for you..

Gribouillis commented: I didn't know pyttsx +13
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Have you tried using either string interpolation or the .format() method instead of string concatenation?

subprocess.call('echo %s | festival --tts' % (line), shell=True)

or

subprocess.call('echo {0} | festival --tts'.format(line), shell=True)

Also, if you are willing to use espeak instead of Festival, you might consider using PyTTSx rather than shelling out to the system.

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

Actually, there is a free version of Qt available from the Qt Project site; the commercial version is only if you are intending to write commercial software using the Qt libraries, IIUC. The opern source version does lag behind the commercial version by a few revisions, but the differences are not usually that significant.

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

This is a difficult thing to really give any advice on, as everyone has a different 'feel' for their favorite tools. I can only tell you my own impressions, and hope yours may be similar.

Of the handful of Python editors and IDEs I have tried, the best I personally have found are Eric, and the PyDev extensions for Eclipse. Both have the advantage of working with either Python 2.x or 3.x if you have both installed at the same time.

However, I have not tried the any of the commercial IDEs to date (such as WingWare or PyCharm), and cannot give any advice on them.

The question of the version of Python to use is mostly a pragmatic one, in that many 3rd party libraries for Python have not yet been updated to work with Python 3. I would recommend learning Python 3, unless you had reason to use a major Python 2.x package such as Django.

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

So, then, the problem lies in the code provided to you by your professor? Odd, though hardly impossible, I suppose. The lines in question are, if I am not mistaken,

                li $t0, ' '
                sb $t0, 26($sp)
                li $t0, ':'      
                sb $t0, 25($sp)    # error occurs here
                li $t0, 't'
                sb $t0, 24($sp)

It's hard to see how this could possibly cause an arithmetic overflow, however. Are you certain that the error is on line 327?

BTW, could you let us know which MIPS simulator and assemblwer you're using? It could be relevant in trying to help track down the problem.

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

Why are you initializing the data this way? With most MIPS assemblers (including those for SPIM and MARS, as far as I know), you should be able to declare the string constants as, well, constants, like so:

                      .data
vtdPrompt:    .asciiz "vals to do? "
entIntPrompt: .asciiz "enter an int: "
adjMsg:       .asciiz " is bad, make it "
# and so on...

It is hard to imagine an assembler that didn't allow static data initialization... It's a fairly basic and fundamental procedure that it wouldn't make sense not to support it. Even if there were some overriding reason to have the data on the stack rather than in the .data section, it would be far easier to simply initialize it in the global .rodata and then copy it to the stack in a loop.

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

Could you tell us more about what you think is the problem with the code as given? By that I mean, is it not compiling, or running without completing, or completing but giving the wrong result? What are you supposed to return other than the computed diameter?

Nind you, I can see at least two major flaws in the program: first, it doesn't test to see if the input diameter is greater than the needed diameter, which could cause it to loop indefinitely; and second, the increment of the diameter is too large - it should be in the range of 0.001, which is the margin being tested for, not 0.01.

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

For the record, I thought you might want to see the version of the program I came up with; you may find it Illuminating fnord as far as the techniques I used for it.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

const int total_categories = 3;
enum CATEGORY {DELUXE, SUV, LUXURY};
const char* category_name[] = {"Deluxe Vehicle", "Sport-Utility Vehicle", "Luxury Car"};
const int category_size[] = {3, 3, 3};

struct Car
{
    char make[16];
    char model[16];
    char year[6];
    int price;
};

const struct Car DELUXE_MODELS[] =
{
    {"Maruti", "Zen", "2011", 4000},
    {"Maruti", "Omni", "2012", 5000},
    {"Volkswagen", "Polo", "2011", 15000}
};

const struct Car SUV_MODELS[] =
{
    {"Tata", "Sumo", "2010", 9000},
    {"Chevrolet", "Tavera", "2009", 12000},
    {"Trax", "Toofan", "2011", 10000}
};

const struct Car LUXURY_MODELS[] =
{
    {"Mercedes", "E350 Sedan", "2012", 9000},
    {"BMW", "640i Convertible", "2012", 12000},
    {"Audi", "A5 Coupe", "2012", 10000}
};

const struct Car* MODEL_CLASSES[] = {DELUXE_MODELS, SUV_MODELS, LUXURY_MODELS};

struct Customer
{
    char name[32];
    int age, daysOfRental;
    char phone_number[16];
    char address[3][32];      /* three lines of 32 chars each */
    struct Car* vehicle;
};

/* function prototypes */
void printBanner();
void getCustomer(struct Customer* customer);
enum CATEGORY getType();
const struct Car* getCar(enum CATEGORY type);
void printReceipt(struct Customer* customer);
void strTrim(char* s);


int main()
{
    struct Customer customer;
    enum CATEGORY type;

    printBanner();
    getCustomer(&customer);
    type = getType();
    customer.vehicle = (struct Car*) getCar(type);
    printReceipt(&customer);

    return 0;
}

void printBanner()
{

    printf("\n CAR RENTAL APPLICATION \n");
    printf("\n ----------------------- \n");
}

void getCustomer(struct Customer* customer)
{
    char ndays[4], age[4];

    printf("\nEnter the number of days you want …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

As others have already mentioned, you need to show that you have already tried to solve the project in some manner. That having been said, can you give us some idea of what you need help with? Have you tried writing the program on your own yet?

A few basic questions to gauge your level of ability (you don't need to respond to all of them, just those which have a negative answer):

  • Do you know how to declare a simple variable?
  • Do you know the difference between a global variable and a local one?
  • Do you know how to get user input?
  • Do you know how to write a for() loop, and index it based on a variable?
  • Do you know how to declare an array and index it?
  • Do you know how to write a function, how to pass values to a function, and how a function returns a value?

Sorry if this seems a bit simplistic, but it's all I can do without more information from you.

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

As an aside, if you are taking in case-insensitive user input as you are here, I would suggest using either toupper() or tolower() to set the case of the switch variable, thus avoiding the issue entirely.

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

Is this the entire header file? If so, you will need to #include the header for the base class (as well as <windows.h>, to bring in CString) at the beginning of the file. I would also recommend adding include guards around the file, to prevent multiple definition errors.

A minor note on nomenclature: I assume that 'CYoda' is the name of the package in question, right? I don't know if this is feasible, but it may make more sense for you to have a CYoda namespace, rather than having CYoda prepended to each and every class name. That would at least shorten and simplify the naming, while still having the namespace control that th prepends are apparently meant to provide. I realize that this may not be something you have control over (e.g., if it is a requirement of a company style guide), but I thought it should be mentioned.

What are the macros ACCOUNTING_MYLIB_DECL and DECLARE_MESSAGE_MAP () for, anyway? One should always be careful when working with macros of this sort, especially ones which mark up a declaration in non-standard ways.

I should finally mention that, these fora are not like chat or Twitter, where you can and will get immediate responses most of the time. Different people are in different timezones, and not everyone reading these is likely to respond. It can take several hours to get an answer here, and a quick response is often a sign that your question isn't well worded …

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

This approach won't work on C++ string objects, at least not consistently. The string class does not use zero-delimiters to check the length of a string, but rather keeps a private size variable that is updated automagically as the string gets manipulated.

In any case, the string class has a built-in size() method. If you need the length of a string, use that.

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

Not on the C++ forum, that's for certain. Try the Jobs & Resumes forum here, or go to sites specifically for that purpose such as vWorker or Freelancer.com. Craigslist is an excellent site for freelance gigs as well, if you're in an area that is covered by it.

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

First off, for future reference, is is considered bad form to cross-post questions like this, as it can lead to a duplication of effort. In the future, I recommend posting to different forums one at a time, and only if you haven't gotten a response after at least four days post to another forum (and let the people on both forums know you are doing it).

Addressing the question itself, the problem appears to lie in the call to get_driver_instance() on line 44. In order to link in that function, you need to have the library mysqlcppconn-static as part of you build. I'm not entirely certain how you would do this under NetBeans, offhand, but in GCC in general, you woul add -l<name-of-library> to your g++ invocation (in this instance, it would be -lmysqlcppconn-static). If anyone here is more familiar with NetBeans, they may be able to advise you.

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

Ah, OK... well, I will tell you that the printComplex() function is overly complex (if you pardon the pun). You should have only three tests, in more or less this order:

  • If the real part is zero;
  • if the imaginary part is negative; and
  • if the imaginary part is one.

At each step, you print just the one part of the number. This should be fairly straightforward to code.

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

Could you please tell us what you're having trouble with? I can see several things that need to be done, but it would be helpful if we knew what you were looking for specifically.

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

I would recommend using the pickle library with the protocol set to 2. This is a binary format that should be unreadable in a text editor.

Mind you, this means that any Python program that uses your class can still un-pickle and read it. For added security, I would suggest looking into one-way cryptographic hashes (such as SHA224 or MD5) as a way of making the password unreadable: since you only need to confirm that the input password matches the stored one, you only need compare the hash of the password to the hash of the input. This makes it so that you don't need to store the password in a form that can be restored at all. This is in fact how virtually every password system in use today works, AFAIK.

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

If all else fails, you can always add another level of abstraction; indeed, that what it looks like you intended, with the PhoneNumber class. Rather than declaring separate arrays for aName and aNumber, you should define the PhoneNumber class, and then in Phonebook you could declare an array (or better still, a vector) of PhoneNumber entries.

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

I suspect that this is because you are tyring to print a standard int value with %ld, the formatting marker for long int. I you need values greater than 2 billion, then you need to declare the variables as long or even long long (depending) as well.

BTW, has this assignment been handed in yet? It's been over a week.

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

The subject of the suitability of different languages for OS development is discussed at length on the OS-Dev Wiki: Languages page.

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

As I said earlier, you want to have the per day as a constant, and multiply that by the number of days to get the total.

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

First off, as we've already said before, you really should change void main() to int main() and have it return 0; at the end of the function.

Second, the way you now have it, the prices for all the cars will be the same, and total price will always be 120,000; the price per day will decrease with the number of days. I think what you want is more like:

 printf("\n You have selected TATA SUMO | %ldrs per day \n ie total %ldRs\n",12000, 12000 * nod);
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Are you sure that you want to inherit from runtime_error (that is, that a Name is a specific example of a runtime_error), or just throw such an error?

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

Can you please describe this 'too simple' project for us? We can only give advice when we know what we're dealing with...

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

At the beginning of the program, add

#include <string.h>

Now in main() add two more variables:

int price;
char car_model[100];

Then, inside the switch(), instead of printing the information, you set these two values, then print them after the end of the switch():

        switch(d)
        {
            case 1:
            strncpy(car_model, "ZEN", 100);
            price = 4000;
            break;

            case 2:
            strncpy(car_model, "OMNI", 100);
            price = 5000;           
            break;

            case 3:
            strncpy(car_model, "Volkswagen Polo", 100);
            price = 15000;

            break;
        }

        printf("\n You have selected %s | Cost %drs per day \n", car_model, price);
        break;

Do the same for the other two inner switch() statements and you should be good to go. You then can use these variables at the end of the program as well.

Mind you, there are all sorts of ways to simplify this program further; I expect you'll see some of them if you look.

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

I think you'll find that, in order to match the grades up with their counts, you'll want to use a dictionary keyed on the grades.

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

In the future, please let give more information about how the program is failing, otherwise we won't have enough to go by.

As it happens, the answer is quite simple: the function doesn't return a value. Try adding return s at the end of the function and it should work correctly.

def <font style='color:black; background-color:Lime;'>word_score</font>(word):
    '''(<font style='color:black; background-color:Lime;'>str</font>) -> int

    Return the point value the word earns.

    Word length: < 3: 0 points
                 6-9: 1 point per character in word
                 7-11: 2 points per character in word
                 10+: 3 points per character in word

    >>> <font style='color:black; background-color:Lime;'>word_score</font>('DRUDGERY')
    16
    '''
    <font style='color:black; background-color:Lime;'>s=</font>0
    if <font style='color:black; background-color:Lime;'>len</font>(word) in range (6,10):
        for i in range (<font style='color:black; background-color:Lime;'>len</font>(word)):
            s += i
    return s

if <font style='color:black; background-color:Lime;'>__name__</font> == "<font style='color:black; background-color:Lime;'>__main__</font>":
    print(<font style='color:black; background-color:Lime;'>word_score</font>('DRUDGERY'))

I ran this and got a score of 28 for the word DRUDGERY. I know it isn't the correct score, but it should at least get you started.

BTW, the score ranges as given don't make much sense; I suspect that they should be

    Word length: < 3: 0 points
                 3-6: 1 point per character in word
                 7-10: 2 points per character in word
                 11+: 3 points per character in word

Otherwise, you have overlapping score ranges, which would be problematic - not to mention a gap between 3 and 6.

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

OK, I'm more confused than ever, especially with regards to the myStrlen() function. First off, it is getting the size of the array of strings, not any one string itself, so the name is misleading. More to the point, it relies on there being a string at the end of the array consisting of a single null value. But this won't be the case for an array of C++ strings, not without there being an explicit marker! Whe I tested this, it showed that it was indeed going off the array:

int main()
{
    string folks[6] = { "obiwan", "minnie", "han", "simba", "jabba", "ariel" };
    cerr << myStrlen(folks) << endl << endl;
    assert(myStrlen(folks) == 6);
    cerr << "myStrlen() - Test ok" << endl << endl;

    assert(partition(folks, 6, "base") == 1); //return 1 since only the first one “ariel” is less than base

    cerr << "partition() - Test ok" << endl;
}

When I ran it after compiling with MinGW gcc 4.6, the actual size returned by myStrlen() was 9, which means that it was continuing on past the end of the array until it found something that matched the end condition by sheer chance. Similarly, the returned value was 10 when compiled under VC++ Express 2010.

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

Has your coursework covered data structures yet? You can bundle the car model and price up into a struct type and save yourself some hassle:

struct Car
{
    char make[16];
    char model[16];
    char year[4];
    int price;
};

This let's you have a record of the all the car makes and models which in each category:

const struct Car SUV[] = { 
                              {"Tata", "Sumo", "2010", 9000},
                              {"Chevrolet", "Tavera", "2009", 12000},
                              {"Trax", "Toofan", "2011", 10000}
                          };
const int SUV_COUNT = 3;

You can use these records to display the model and price info for the category:

        case 2:
        printf("\n You have chosen Long Trip Vehicles \n");
        printf("\n Vehicles Available are \n");
        for (i = 0; i < SUV_COUNT; i++)
        {
            printf("%d: %s %s, ", i + 1, SUV[i].make, SUV[i].model);
        }
        printf("\n\n ----------------------------- \n");
        printf("Enter the number of the car model you want: ");
        scanf("%d", &r);
        r--;
        printf("\n You have selected %s %s %s | Cost %d rs per day \n", 
               SUV[r].year, SUV[r].make, SUV[r].model, SUV[r].price);

        break;

You would do the same for each of the other two categories.

You can similarly bundle the customer info into a single struct, like so, with a pointer to the car information:

struct Customer 
{
    char name[32];
    int age;
    char address[3][32];      /* three lines of 32 chars each */
    struct Car* vehicle;
} customer;

You could then read in the customer information at the beginning of the program, and print it out again at the end along with …

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

I've seen some ludicrous assignments in my day, but this one is among the most absurd I've ever encountered. I would be tempted to walk out on the class if I were handed a project as pointless as this. Still, an assignment is an assignment...

The key to this assignment is to see that the professor wants you to have set the pointers in the first array so that they each point to the matching element in the second array. To do this, you'll need to loop through the pointer array and set each pointer separately:

    for (int i = 0; i < 5; i++)            //assign values of integer array
    {                                      //to integer pointer array
        ptr[i] = &a[i];
    }

Now here comes the part I consider silly. You need to loop through the character array, and set the values pointed to by the elements of the int pointer array (that is to say, the elements of the int array) to the values in the char array.

    for (int i = 0; i < 5; i++)            //assign values of char array
    {                                      //to the pointer array's references
        *ptr[i] = b[i];
    }

Finally, you need to loop through the int array a, and print it's values. This part does nothing in regards to pointers; you just print the values in the a array.

Now, I suppose that the point of this (if there is one) is to demonstrate what happens when you print characters out as …

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

The problem is that you are taking the size of the array as the highest index:

    int i = n;
    while (i > 0)
    {
        int pos = positionOfMax(a, i); //find the latest one's position
        rotateLeft(a, i, pos); //move the latest one to the end
        i--;
        pos = 0;
    }

Arrays in C++ are zero-indexed, meaning that for an array of size 6, the indices would be 0, 1, 2, 3, 4, and 5. An index number of 6 will go off the end of the array, causing the segfault. You'll want to change this to

    int i = n - 1;
    while (i >= 0)
    {
        int pos = positionOfMax(a, i); //find the latest one's position
        rotateLeft(a, i, pos); //move the latest one to the end
        i--;
        pos = 0;
    }

Since you seem to make this mistake throughout the code, you'll need to make similar changes across the whole program, I'm afraid.

As for why it doesn't fail in Windows (it should), I'm guessing that it is silently trashing some otherwise unimportant piece of data on main()'s stack area.

BTW, where is myStrlen() declared?

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

I think that if you actually open up the file grade.txt, you'll see that there is no actual line with the text EOF on it; rather, in the example given, the EOF stands in the for the actual end-of-file marker, which isn't a printable character.

In any case, Python provides an easy way to iterate through a text file without using readline() or any explicit test for completion, by using just a for: loop:

inFile = open('grade.txt', 'r')
for line in inFile:
    lst = line.split(',')
    print(lst)
inFile.close()

Another way to do this, which may prove even more useful, is to use the with statement. Let's try that, with a little more formatting to the output as well:

with open('grade.txt', 'r') as inFile:
    for line in inFile:
        lst = line.split(',')
        for element in lst:
            print("{0:<15}".format(element.strip()),  end=' ')
        print()

The major advantage of the with is that you don't need to explicitly close the file.

I could also add that files of this type (called a comma-separated value file or CSV file), are especially common, so much so that Python has a special library just for handling the data from them.

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

OK, I'm looking at the code, but I can't find any point in it where you allocate any Node objects. I suspect that Rooms needs to be vector<Node*>, not vector<Node>.

I've taken the liberty of updating the program so that it uses Node pointers, and added a method that prints the whole maze (useful for debugging). I've also added an enumeration for the cardinal directions, and a matching array of direction names. The current versions of the files are as follows:

node.h

#ifndef NODE_H
#define NODE_H 1

#include <string>

enum CARDINAL {NORTH, EAST, SOUTH, WEST};
const std::string DIRECTIONS[] = {"North", "East", "South", "West"};

class Node
{
private:
    std::string name;
    Node *attachedNodes[4];
    Node *ladderOrChuteNodes;

public:
    // c'tors
    Node(std::string newname = "aNode");
    Node(const Node& other);

    ~Node()
    {
        return;
    }


    Node& operator=(const Node& other);

    void attachLadderChuteNode(Node *newNode);
    Node *getLadderChuteNode();
    std::string move_options();

    Node *getAttachedNode(CARDINAL direction)
    {
        return attachedNodes[direction];
    };

    void setNodeName(std::string newname)
    {
        name = newname;
    };

    std::string getNodeName()
    {
        return name;
    };

    void attachNewNode(Node *newNode, CARDINAL direction);
};

#endif

node.cpp

#include <string>

#include "node.h"

Node::Node(std::string newname): name(newname), ladderOrChuteNodes(0)
{
    for (int i = 0; i < 4; i++)
    {
        attachedNodes[i] = 0;
    }
}

Node::Node(const Node& other): name(other.name), ladderOrChuteNodes(other.ladderOrChuteNodes)
{
    for (int i = 0; i < 4; i++)
    {
        attachedNodes[i] = other.attachedNodes[i];
    }
}


Node& Node::operator=(const Node& other)
{
    name = other.name;
    ladderOrChuteNodes = other.ladderOrChuteNodes;

    for (int i = 0; i < 4; i++)
    {
        attachedNodes[i] = other.attachedNodes[i];
    }

    return *this;
}


void Node::attachLadderChuteNode(Node *newNode)
{
    return;   // dummy …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Would you mind posting or attaching a copy of the data file? It is hard to test the program without it.

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

The main problem I see is that you are indexing the arrays incorrectly, which is probably the cause of the segfault. In C++, arrays are zero-indexed, that is to say, an array arr[5] would have elements arr[0], arr[1], arr[2], arr[3], and arr[4]. When you try to access arr[5], you overrun the array and get an access violation.

What this means is that you need to fix all of the array indices in the program. Fortunately for you, I've done just that:

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
    srand(time(NULL));

    //Constants
    const double SALESTAX = 0.08;
    const double DISCOUNTRATE = 0.05;
    const double DISCOUNT = 95;

    //Counts
    int customer, book;

    //Customer arrays
    string customer_Non[5][2]; // 1 = name, 2 = address
    int customer_Num[5][2]; // 1 = age, 2 = receipt#
    int quantity = 3; //3 books per customer

    //Book arrays
    string book_Non[5][3][3]; // 1 = book number, 2 = Title, 3 = Author
    int bookAisle[5][3]; // 1 aisle per book
    double bookPrice[5][3][2]; // 1 = book price, 2 = discount

    //Calculations
    double calculation[5][5];
    /* 1 = subtotal, 2= total discount, 3 = subtotal and discount
     * 4 = sales tax, 5 = Total to be paid */

    //Validations
    int customerValid [5][2]; //1 = name validation, 2 = address validation
    int bookValid[5][3][3]; //1 = booknum validation, 2 = title validation,
                            //3 = author validation
    ofstream fOut;
    fOut.open("Project4_A00635756_Output.txt");

    for(customer = 0; customer < 5; customer++)
    {
        customer_Num[customer][1] = rand() % 999 …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I can see a number of issues with the code as it stands, but the most serious one is that you are repeatedly walking off the end of the attachedNodes array; for an array of 4 items, the range of indices is 0, 1, 2, and 3, not 0, 1, 2, 3, 4. So, this line, and others like it:

attachedNodes[4] = NULL;

are incorrect, and will lead to a segmentation fault. I don't know if this is the source of the problem you'e now having, but it is the first place to look.

Also, I would recommend against mixing C-strings and the <cstring> functions with C++ string objects. With C++ strings, the equality operator is overloaded, so you can simply compare them, without having to resort to strcmp().

BTW, what compiler and editor are you using? I have an important piece of advice, but how you would apply it depends on how you are compiling the program. The advice is to break the program up into separate files, with a header file and a code file for each of the classes and a code file for the main() function. Thus, your code would look like so (with a few corrections added):
node.h

#ifndef NODE_H
#define NODE_H 1

#include <string>

class Node
{
private:
    std::string name;
    Node *attachedNodes[4];
    Node *ladderOrChuteNodes;

public:
    // c'tors
    Node(std::string newname = "aNode");
    Node(const Node& other);

    Node& operator=(const Node& other);

    void attachLadderChuteNode(Node *newNode);
    Node *getLadderChuteNode();
    std::string move_options();

    Node *getAttachedNode(int direction)
    {
        return …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

There are two ways to do this, though one of them only works on 2.5 and later (it was developed for Python 3, then later backported to Python 2). In either approaches, you first need to use split() to divide the string into a list of individual words.

aprime = "help I don't know how to do these tables.".split(' ')

The first way to do this is to us string interpolation syntax, which provides a minimum field width argument to the formatting specifier.

print("%s%10s%10s\n%s%10s%10s\n%s%10s%10s" % tuple(aprime))

The second approach, which is a bit more flexible but is only supported under newer versions of the language, is to use the string method format(). This also has field width sub-field in its formatting specifiers, but can also define whether the word should be to the right, to the left, or to the center:

print("{0:<10}{1:^10}{2:>10}\n{3:<10}{4:^10}{5:>10}\n{6:<10}{7:^10}{8:>10}".format(*aprime))
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

That's going to depend on a lot of factors, really. Different programmers find different languages appealing.

As for which language to choose, the obvious choice would be Java itself. However, you could in principle use any language which runs on the Java JVM platform, which includes Jython (a Python port to the JVM), JRuby (the same, for Ruby), Scala, Groovy, Kawa Scheme, and Clojure. Which of those would be best for you? That's really not something I can say easily; my own preferences would be for either Kawa or Clojure, for example, but a lot of people find the unusual syntax of the Lisp languages to be off-putting. IME, most people do well with either Python or Ruby as their first language, so one of those might be the place to start.

The real question is, will the language you want run under J2ME? As far as I am aware, Java and Scala are the only ones which do to date.

Mind you, as far as I am aware, J2ME is something of a dead issue for mobile development at this point; most smartphone development is being done on other platforms, such as Android (which uses Google's own Java virtual machine and development libraries) or iOS (which, last I'd heard, can only be programmed with Objective-C, and has to be developed from a Mac). While there are still plenty of J2ME devices around, they aren't neccessarily ones you'd …

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

For this case, you would use the alternate method calling syntax, using the class name instead of the object name, and passing the self argument explicitly:

class.method(self, args)

This isn't specific to inherited methods; it could be used anywhere you have a method call. It's uncommon to use it for an ordinary method invocation because it is a bit confusing, but it can be done.

class A(object):
    def printhello(self):
        self.message1="hello"
class B(object):
    def printbye(self):
        self.message2="bye"
class C(A,B):
    def __init__(self):
        A.printhello(self)
        B.printbye(self)
    def printboth(self):
        print(self.message1)
        print(self.message2)

a = A()
b = B()
c = C()

c.printboth()

Mind you, this probably isn't the typical approach to this; a more Pythonic way might be:

class A(object):
    def __init__(self):
        self.message1="hello"

    def __str__(self):
        return self.message1

class B(object):
    def __init__(self):
        self.message2="bye"

    def __str__(self):
        return self.message2

class C(A,B):
    def __init__(self):
        A.__init__(self)
        B.__init__(self)

    def __str__(self):
        return A.__str__(self) + '\n' + B.__str__(self)

a = A()
b = B()
c = C()

print(c)

But that's neither here nor there.

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

BTW, just as Woooee pointed out about updateboard() (which can just be update(), given that the board part is implied), you can simplify printboard() fairly easily:

def display(self):
    for i in range(0, 3):
        for j in range(0, 3):
            print(self.board[i][j])
        print() 
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I think that you're having some conceptual issues with inheritance, resulting in what is sometimes called 'spaghetti inheritance' (that is, inheriting from an otherwise unrelated class just to get a desired behavior). There's a simple test to see if the inheritance is valid: is a Board a specific example of a Human in your model? If it isn't then Board shouldn't be inheriting from Human.

Perhaps a change of names will clarify things a bit. Replace Human with the more general name Player, and subclass Player with HumanPlayer and AiPlayer. Separate the playing behaviors of Board out into AiPlayer, and have Board be a representation of just the board itself. This should disentangle your current inheritance structure a bit.

On a secondary note, you might want to separate the part of makeboard() which initializes the board into a separate clear() function. If you then have it called by the c'tor rather than makeboard(), follwed by a call to updateboard(), it will allow you to eliminate makeboard() entirely.

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

Ah, in that case, you want

       while sum in point:

It may be better, too, if you were to declare point explicitly as a list or tuple; as it is, it becomes a tuple anyway, because of the assignment unpacking rules, but it would be better to explicit.

       point = (4,5,6,8,9,10)

I should add that sum isn't a great variable name, because there is a built-in function of the same name, which gets masked as a result of using that as a a variable. A better variable name might be result. EDIT: Ah, PyTony already mentioned that, I see.

Finally, most of what appears to be meant as the body of the loop is in fact outside of it. you need to indent this part correctly, or else the only thing you'll get is an infinite series of the phrase "Phase 2". Also, you never generate a new pair of dice rolls, so it never ends, anyway. It would make more sense to have the rolls generated with a small function that returns two values:

def rollDice():
    return r.randint(1,6), r.randint(1,6)

Then call it both at the start of the main() function, and each pass of while: loop:

        print("phase 2")
        firstResult = result
        while result in point:
            roll1, roll2 = rollDice()
            if result == 7:
                print("you lose")
            elif result == firstResult:
                print("you win!")
            else:
                print ("roll again.")