As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

[Programming] djmitchella travelling through snow to rfind duplicate dates for singletons

17172747677100

Posts

  • Options
    DyasAlureDyasAlure SeattleRegistered User regular
    so c++ question, what is the cleanest way to verify console input?

    I want to take the input in, and make sure the first char only is one of my menu items.

    My%20Steam.png?psid=1My%20Twitch%20-%20Mass%20Effect.png?psid=1=1My%20Youtube.png?psid=1
  • Options
    ecco the dolphinecco the dolphin Registered User regular
    DyasAlure wrote: »
    so c++ question, what is the cleanest way to verify console input?

    I want to take the input in, and make sure the first char only is one of my menu items.

    Are you using std::string?

    If so, consider using std::getline() - see the example on that page on how to use it.

    Alternatively, if you're feeling particularly C++ standard library friendly, you can look into std::istringstream, which I personally don't like, but have found use for in the past.

    Penny Arcade Developers at PADev.net.
  • Options
    DyasAlureDyasAlure SeattleRegistered User regular
    DyasAlure wrote: »
    so c++ question, what is the cleanest way to verify console input?

    I want to take the input in, and make sure the first char only is one of my menu items.

    Are you using std::string?

    If so, consider using std::getline() - see the example on that page on how to use it.

    Alternatively, if you're feeling particularly C++ standard library friendly, you can look into std::istringstream, which I personally don't like, but have found use for in the past.

    Yes this is what I have been using, but this will put it into a string. Now I can think of lots of ways to do it messy, but if I want to get an int out of the string, or maybe two ints, is there a nice way? I'm just looking for good practices for this, verses me just forcing it with switch tables, ascii tables, or some other terrible thing I can dream up.

    My%20Steam.png?psid=1My%20Twitch%20-%20Mass%20Effect.png?psid=1=1My%20Youtube.png?psid=1
  • Options
    ecco the dolphinecco the dolphin Registered User regular
    DyasAlure wrote: »
    Yes this is what I have been using, but this will put it into a string. Now I can think of lots of ways to do it messy, but if I want to get an int out of the string, or maybe two ints, is there a nice way? I'm just looking for good practices for this, verses me just forcing it with switch tables, ascii tables, or some other terrible thing I can dream up.

    std::istringstream is one of the easier ways to do it using just native C++.

    Penny Arcade Developers at PADev.net.
  • Options
    DyasAlureDyasAlure SeattleRegistered User regular
    DyasAlure wrote: »
    Yes this is what I have been using, but this will put it into a string. Now I can think of lots of ways to do it messy, but if I want to get an int out of the string, or maybe two ints, is there a nice way? I'm just looking for good practices for this, verses me just forcing it with switch tables, ascii tables, or some other terrible thing I can dream up.

    std::istringstream is one of the easier ways to do it using just native C++.

    I was messing with stringstreams recently. I guess I will have to look into this. Thanks for the direction.

    My%20Steam.png?psid=1My%20Twitch%20-%20Mass%20Effect.png?psid=1=1My%20Youtube.png?psid=1
  • Options
    GrobianGrobian What's on sale? Pliers!Registered User regular
    RE: batch file dark magicks on the last page:

    I much prefer powershell when it's just about automating tasks and doesn't really have to be a cmd or bat file. It has cleaner code and also there's a bunch of stuff built in (e.g. a cmdlet to call webservices)

  • Options
    TraceTrace GNU Terry Pratchett; GNU Gus; GNU Carrie Fisher; GNU Adam We Registered User regular
    (^want,INFORMATION)!
    (^wonder,INFORMATION)!
    
    <SUBJECT.DATA-->INFORMATION>. %1.00%
    <{(&,{SUBJECT.METADATA},{SUBJECT.PROFILE})}{--SUBJECT.DATA>. %1.00%
    <{SUBJECT.METADATA}{--INFORMATION>. %1.00%
    <{SUBJECT.PROFILE}{--INFORMATION>. %1.00%
    
    <TARGET.DATA-->INFORMATION>. %1.00%
    <{(&,{TARGET.METADATA},{TARGET.PROFILE})}{--TARGET.DATA>. %1.00%
    <{TARGET.METADATA}{--INFORMATION>. %1.00%
    <{TARGET.PROFILE}{--INFORMATION>. %1.00%
    
    <{(&,SUBJECT_ID,CLASSIFICATION,TYPE,PRIORITY)}<->{SUBJECT.METADATA}>. %1.00%
    
    <{001}-->{SUBJECT_ID}>. %1.00%
    <{SUBJECT_ID}{--{IDENTIFICATION}>. %1.00%
    <{IDENTIFICATION}{--INFORMATION>. %1.00%
    
    <{RELEVANT}-->{CLASSIFICATION}>. %1.00%
    <{NON_RELEVANT}-->{CLASSIFICATION}>. %1.00%
    <{RELEVANT}<->{NON_RELEVANT}>. %0.00%
    <{NON_RELEVANT}<->{RELEVANT}>. %0.00%
    <{CLASSIFICATION}{--{EVALUATION}>. %1.00%
    <{EVALUATION}{--INFORMATION>. %1.00%
    
    <{NON_IMPORTANT}-->{TYPE}>. %1.00%
    <{CIVILIAN}-->{TYPE}>. %1.00%
    <{ASSET}-->{TYPE}>. %1.00%
    <{DEVIANT}-->{TYPE}>. %1.00%
    <{THREAT}-->{TYPE}>. %1.00%
    <{TYPE}{--{OBSERVATION}>. %1.00%
    <{OBSERVATION}{--INFORMATION>. %1.00%
    
    <{LOW}-->{PRIORITY}>. %1.00%
    <{MEDIUM}-->{PRIORITY}>. %1.00%
    <{HIGH}-->{PRIORITY}>. %1.00%
    <{LOW}<->{MEDIUM}>. %0.00%
    <{LOW}<->{HIGH}>. %0.00%
    <{MEDIUM}<->{LOW}>. %0.00%
    <{MEDIUM}<->{HIGH}>. %0.00%
    <{HIGH}<->{LOW}>. %0.00%
    <{HIGH}<->{MEDIUM}>. %0.00%
    <{PRIORITY}{--{EVALUATION}>. %1.00%
    
    <{(&,Name,Occupation,Affiliation,Situation,Location)}<->{SUBJECT.PROFILE}>. %1.00%
    
    <{Joe_Smith}-->{Name}>. %1.00%
    <{Name}{--{IDENTIFICATION}>. %1.00%
    
    <{City_Guard}-->{Occupation}>. %1.00%
    <{Occupation}{--{OBSERVATION}>. %1.00%
    <{PROFILE}{--INFORMATION>. %1.00%
    
    <{Eisendale}-->{Affiliation}>. %1.00%
    <{Affiliation}{--{RELATION}>. %1.00%
    <{RELATION}{--INFORMATION>. %1.00%
    
    <{Normal}-->{Situation}>. %1.00%
    <{Situation}{--{EVALUTATION}>. %1.00%
    
    <{Eisendale}-->{Location}>. %1.00%
    <{Location}{--{OBSERVATION}>. %1.00%
    
    <SUBJECT{--SUBJECT.DATA>. %1.00%
    <{Subject}{--SUBJECT>. %1.00%
    <{(&,SUBJECT.METADATA,SUBJECT.PROFILE)}<->{Subject}>. %1.00%
    
    <Joe_Smith{--{Subject}>. %1.00%
    <{(&,{001},{NON_RELEVANT},{NON_IMPORTANT},{LOW})}<->{Joe_Smith}>. %1.00%
    <{(&,{Joe_Smith},{City_Guard},{Eisendale},{Normal},{Eisendale})}<->{Joe_Smith}>. %1.00%
    

    Funhouse Code in NARS.


    for when I get codersblock

  • Options
    DaedalusDaedalus Registered User regular
    DyasAlure wrote: »
    DyasAlure wrote: »
    so c++ question, what is the cleanest way to verify console input?

    I want to take the input in, and make sure the first char only is one of my menu items.

    Are you using std::string?

    If so, consider using std::getline() - see the example on that page on how to use it.

    Alternatively, if you're feeling particularly C++ standard library friendly, you can look into std::istringstream, which I personally don't like, but have found use for in the past.

    Yes this is what I have been using, but this will put it into a string. Now I can think of lots of ways to do it messy, but if I want to get an int out of the string, or maybe two ints, is there a nice way? I'm just looking for good practices for this, verses me just forcing it with switch tables, ascii tables, or some other terrible thing I can dream up.

    I'm going to go against the C++ orthodoxy here and suggest scanf(). The C++ stream libraries are the worst parts of the standard library and really should be deprecated and replaced.

  • Options
    bowenbowen How you doin'? Registered User regular
    I also find myself using the C console libraries for shit like that over the stream libraries.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    SpawnbrokerSpawnbroker Registered User regular
    I asked a client what version of SSRS they were running, and what their SharePoint farm version was so we could set up an environment to reproduce a bug.

    Their response:

    SSRS version: 2012
    SharePoint farm number: 2013

    Thanks guys, super helpful. Can I get a technical resource from your company now?

    Steam: Spawnbroker
  • Options
    crimsoncoyotecrimsoncoyote Registered User regular
    Sometimes, I really like where I work.

    I had the opportunity last week to participate in an internal hacking competition. I'm not very good at it, but it's a ton of fun! I even got to play with some ruby for the first time. I did better than last year, so that's awesome too.

    Hopefully I'll have the opportunity to do it next year

  • Options
    ecco the dolphinecco the dolphin Registered User regular
    edited January 2015
    Daedalus wrote: »
    DyasAlure wrote: »
    DyasAlure wrote: »
    so c++ question, what is the cleanest way to verify console input?

    I want to take the input in, and make sure the first char only is one of my menu items.

    Are you using std::string?

    If so, consider using std::getline() - see the example on that page on how to use it.

    Alternatively, if you're feeling particularly C++ standard library friendly, you can look into std::istringstream, which I personally don't like, but have found use for in the past.

    Yes this is what I have been using, but this will put it into a string. Now I can think of lots of ways to do it messy, but if I want to get an int out of the string, or maybe two ints, is there a nice way? I'm just looking for good practices for this, verses me just forcing it with switch tables, ascii tables, or some other terrible thing I can dream up.

    I'm going to go against the C++ orthodoxy here and suggest scanf(). The C++ stream libraries are the worst parts of the standard library and really should be deprecated and replaced.

    Yeah.

    On the flip side, one problem that I've recently had with scanf() is writing cross platform code that uses SCNd8 ("%hhd") and SCNu8 ("%hhu") - Visual Studio's C support is famously lacking, and the CRT is being refactored.

    So on gcc, you use SCNd8 and co to read in one byte, but recent versions of Visual Studio sees the %, ignores the hh, and therefore stomps your stack/heap something fierce by treating a one byte %hhu as a %u.

    Edit: Coincidentally, that's when I discovered that VS2013 has a form of stack corruption detection enabled for debug modes. Neat!

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • Options
    Jimmy KingJimmy King Registered User regular
    Daedalus wrote: »
    DyasAlure wrote: »
    DyasAlure wrote: »
    so c++ question, what is the cleanest way to verify console input?

    I want to take the input in, and make sure the first char only is one of my menu items.

    Are you using std::string?

    If so, consider using std::getline() - see the example on that page on how to use it.

    Alternatively, if you're feeling particularly C++ standard library friendly, you can look into std::istringstream, which I personally don't like, but have found use for in the past.

    Yes this is what I have been using, but this will put it into a string. Now I can think of lots of ways to do it messy, but if I want to get an int out of the string, or maybe two ints, is there a nice way? I'm just looking for good practices for this, verses me just forcing it with switch tables, ascii tables, or some other terrible thing I can dream up.

    I'm going to go against the C++ orthodoxy here and suggest scanf(). The C++ stream libraries are the worst parts of the standard library and really should be deprecated and replaced.
    Agreed. Last semester I had to write C++ using only standard library stuff. One of the assignments I had a menu with integer options and the requirement was that we had to use << and >> for all io. The best I could come up with (and the best the teacher could as well... he was a C guy and had barely used C++ himself) was something like so:
    int selectedOption;
    // QUIT and the other menu options all have #DEFINEs in a header
    while(selectedOption != QUIT) {
        menu.showMenu();
        if(not (cin >> selectedOption)) {
          // something which is not an int got entered
          cin.clear();
          cin.ignore();
        } else {
            // do whatever needs doing
        }
    }
    

    This does not ensure that the first character is an int, though. It just ensures that somewhere in whatever was input there is an int and then will use that. So the user could have entered "1" or "poop1" and it wouldn't have matttered. As a nasty side effect, they also could enter "poop1 wangs" and then wangs would be taken as the next input, which selecting option 1 would have prompted for. I suspect that second issue there probably has a solution similar to how input was cleared when no int was entered.

  • Options
    KhavallKhavall British ColumbiaRegistered User regular
    edited January 2015
    Ok I have what is probably a really, really, really basic and dumb question.

    But it seems that either I'm just searching for the wrong thing or it's just so basic that nobody else needs it.


    I'm in C++(which I am, just, terrible at. I'm basically learning it to make objects in Max/MSP that are more performative than doing "js" objects and coding it in Javascript)


    I've, hopefully, created a constructor
    // Defines constructor of "Note" and assigns variables
    // Arguments for Note are in order: (Polarity, Strength, x, y)
    class Note {
    public:
        Note(bool Polarity, int Strength, int x, int y){
            Pol = Polarity;
            Str = Strength;
            LocX = x;
            LocY = y;
            };
    
    private:
        bool Pol;
        int Str;
        int LocX;
        int LocY;
    
    };
    
    And now, I'm trying to create n Notes, where n will be the input from max/msp.

    Then after that, I'm going to do a really basic, not-quite-genetic algorithm(really a not-quite-Conway's game of life) where the notes interact based on their variables, and then the output will be a string of notes that will be played by Max/MSP through either Ableton Live via maxforlive, based just on their polarity and strength(Polarity will be relation to user-input note from a midi keyboard, strength will be distance from user-input note)

    In theory, I want it to have the option to have larger or smaller generations based on the user preference. I'll also have a similar problem when I have each generation "reproduce" if they happen to.


    I've got
    void Generate() {
        for (unsigned int x=0; x<n; x+1) {
            bool P = rand() % 1;
            int S = rand() % 100;
            int lX = rand() % 50;
            int lY = rand() % 50;
            Note note = *new Note(P, S, lX, lY);
            
        };
    
    but that obviously just creates a single note. Is there a way to have each note be named, say, "note_x" automatically when generated?

    Khavall on
  • Options
    ecco the dolphinecco the dolphin Registered User regular
    edited January 2015
    Jimmy King wrote: »
    Agreed. Last semester I had to write C++ using only standard library stuff. One of the assignments I had a menu with integer options and the requirement was that we had to use << and >> for all io. The best I could come up with (and the best the teacher could as well... he was a C guy and had barely used C++ himself) was something like so:
    int selectedOption;
    // QUIT and the other menu options all have #DEFINEs in a header
    while(selectedOption != QUIT) {
        menu.showMenu();
        if(not (cin >> selectedOption)) {
          // something which is not an int got entered
          cin.clear();
          cin.ignore();
        } else {
            // do whatever needs doing
        }
    }
    

    This does not ensure that the first character is an int, though. It just ensures that somewhere in whatever was input there is an int and then will use that. So the user could have entered "1" or "poop1" and it wouldn't have matttered. As a nasty side effect, they also could enter "poop1 wangs" and then wangs would be taken as the next input, which selecting option 1 would have prompted for. I suspect that second issue there probably has a solution similar to how input was cleared when no int was entered.

    I much prefer doing something like:
    while( !std::cin.eof() )
    {
      std::string currentLine;
      std::getline( std::cin, currentLine );
    
      // Parse current line using your favourite parsing algorithm (istringstream, scanf, manual string manips etc)
    }
    

    If you abort on the first error for that line, that would have solved most of your problems, I think.

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • Options
    ecco the dolphinecco the dolphin Registered User regular
    Khavall wrote: »
    Ok I have what is probably a really, really, really basic and dumb question.

    But it seems that either I'm just searching for the wrong thing or it's just so basic that nobody else needs it.


    I'm in C++(which I am, just, terrible at. I'm basically learning it to make objects in Max/MSP that are more performative than doing "js" objects and coding it in Javascript)


    I've, hopefully, created a constructor
    // Defines constructor of "Note" and assigns variables
    // Arguments for Note are in order: (Polarity, Strength, x, y)
    class Note {
    public:
        Note(bool Polarity, int Strength, int x, int y){
            Pol = Polarity;
            Str = Strength;
            LocX = x;
            LocY = y;
            };
    
    private:
        bool Pol;
        int Str;
        int LocX;
        int LocY;
    
    };
    
    And now, I'm trying to create n Notes, where n will be the input from max/msp.

    Then after that, I'm going to do a really basic, not-quite-genetic algorithm(really a not-quite-Conway's game of life) where the notes interact based on their variables, and then the output will be a string of notes that will be played by Max/MSP through either Ableton Live via maxforlive, based just on their polarity and strength(Polarity will be relation to user-input note from a midi keyboard, strength will be distance from user-input note)

    In theory, I want it to have the option to have larger or smaller generations based on the user preference. I'll also have a similar problem when I have each generation "reproduce" if they happen to.


    I've got
    void Generate() {
        for (unsigned int x=0; x<n; x+1) {
            bool P = rand() % 1;
            int S = rand() % 100;
            int lX = rand() % 50;
            int lY = rand() % 50;
            Note note = *new Note(P, S, lX, lY);
            
        };
    
    but that obviously just creates a single note. Is there a way to have each note be named, say, "note_x" automatically when generated?

    Are you comfortable with using arrays?

    I'm heading off right now, otherwise I'd do something more detailed. When I head home, if none of the other guys around have picked it up, I'll write something up.

    Penny Arcade Developers at PADev.net.
  • Options
    EndEnd Registered User regular
    edited January 2015
    Khavall wrote: »
    [...]
    but that obviously just creates a single note. Is there a way to have each note be named, say, "note_x" automatically when generated?

    It sounds like you probably want an array (or something array-like like a vector)

    If my memory is correct, something like:
    int *notes = new Note[n];
    ...
        notes[x] = new Note(P, S, lX, lY);
    

    also:
    for (unsigned int x=0; x<n; x+1) {
                                ^
    

    *cough*

    (also "*new" seems a little silly, ...you're creating on the heap and then copying it onto the stack?)

    End on
    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpg
  • Options
    KhavallKhavall British ColumbiaRegistered User regular
    Khavall wrote: »
    Ok I have what is probably a really, really, really basic and dumb question.

    But it seems that either I'm just searching for the wrong thing or it's just so basic that nobody else needs it.


    I'm in C++(which I am, just, terrible at. I'm basically learning it to make objects in Max/MSP that are more performative than doing "js" objects and coding it in Javascript)


    I've, hopefully, created a constructor
    // Defines constructor of "Note" and assigns variables
    // Arguments for Note are in order: (Polarity, Strength, x, y)
    class Note {
    public:
        Note(bool Polarity, int Strength, int x, int y){
            Pol = Polarity;
            Str = Strength;
            LocX = x;
            LocY = y;
            };
    
    private:
        bool Pol;
        int Str;
        int LocX;
        int LocY;
    
    };
    
    And now, I'm trying to create n Notes, where n will be the input from max/msp.

    Then after that, I'm going to do a really basic, not-quite-genetic algorithm(really a not-quite-Conway's game of life) where the notes interact based on their variables, and then the output will be a string of notes that will be played by Max/MSP through either Ableton Live via maxforlive, based just on their polarity and strength(Polarity will be relation to user-input note from a midi keyboard, strength will be distance from user-input note)

    In theory, I want it to have the option to have larger or smaller generations based on the user preference. I'll also have a similar problem when I have each generation "reproduce" if they happen to.


    I've got
    void Generate() {
        for (unsigned int x=0; x<n; x+1) {
            bool P = rand() % 1;
            int S = rand() % 100;
            int lX = rand() % 50;
            int lY = rand() % 50;
            Note note = *new Note(P, S, lX, lY);
            
        };
    
    but that obviously just creates a single note. Is there a way to have each note be named, say, "note_x" automatically when generated?

    Are you comfortable with using arrays?

    I'm heading off right now, otherwise I'd do something more detailed. When I head home, if none of the other guys around have picked it up, I'll write something up.

    Generally yes, unless C++ handles them in some weird super-esoteric way.

  • Options
    EndEnd Registered User regular
    and now I should probably stop criticizing typos in a language I barely use once a year

    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpg
  • Options
    KhavallKhavall British ColumbiaRegistered User regular
    End wrote: »
    Khavall wrote: »
    [...]
    but that obviously just creates a single note. Is there a way to have each note be named, say, "note_x" automatically when generated?

    It sounds like you probably want an array (or something array-like like a vector)

    If my memory is correct, something like:
    int *notes = new Note[n];
    ...
        notes[x] = new Note(P, S, lX, lY);
    
    Ok. I'm right in rehearsal now, but I'll check it out tomorrow and see if I can get that to work.
    also:
    for (unsigned int x=0; x<n; x+1) {
                                ^
    

    *cough*

    (also "*new" seems a little silly, ...you're creating on the heap and then copying it onto the stack?)
    I was getting really weird errors in Xcode and went "Fuck it, you want x+1? WILL THAT MAKE YOU HAPPY?! HERE, HAVE A STAR IN FRONT OF NEW SINCE YOU'RE COMPLAINING"


    I'm also at the end of a really busy week and taking my aggression out on Xcode is helpful.

  • Options
    hippofanthippofant ティンク Registered User regular
    edited January 2015
    Khavall wrote: »
    Khavall wrote: »
    Ok I have what is probably a really, really, really basic and dumb question.

    But it seems that either I'm just searching for the wrong thing or it's just so basic that nobody else needs it.


    I'm in C++(which I am, just, terrible at. I'm basically learning it to make objects in Max/MSP that are more performative than doing "js" objects and coding it in Javascript)


    I've, hopefully, created a constructor
    // Defines constructor of "Note" and assigns variables
    // Arguments for Note are in order: (Polarity, Strength, x, y)
    class Note {
    public:
        Note(bool Polarity, int Strength, int x, int y){
            Pol = Polarity;
            Str = Strength;
            LocX = x;
            LocY = y;
            };
    
    private:
        bool Pol;
        int Str;
        int LocX;
        int LocY;
    
    };
    
    And now, I'm trying to create n Notes, where n will be the input from max/msp.

    Then after that, I'm going to do a really basic, not-quite-genetic algorithm(really a not-quite-Conway's game of life) where the notes interact based on their variables, and then the output will be a string of notes that will be played by Max/MSP through either Ableton Live via maxforlive, based just on their polarity and strength(Polarity will be relation to user-input note from a midi keyboard, strength will be distance from user-input note)

    In theory, I want it to have the option to have larger or smaller generations based on the user preference. I'll also have a similar problem when I have each generation "reproduce" if they happen to.


    I've got
    void Generate() {
        for (unsigned int x=0; x<n; x+1) {
            bool P = rand() % 1;
            int S = rand() % 100;
            int lX = rand() % 50;
            int lY = rand() % 50;
            Note note = *new Note(P, S, lX, lY);
            
        };
    
    but that obviously just creates a single note. Is there a way to have each note be named, say, "note_x" automatically when generated?

    Are you comfortable with using arrays?

    I'm heading off right now, otherwise I'd do something more detailed. When I head home, if none of the other guys around have picked it up, I'll write something up.

    Generally yes, unless C++ handles them in some weird super-esoteric way.

    So you definitely need... something to store all your notes in. Your idea of having dynamically created variable names is not a feature supported in any major programming language, AFAIK, and it's unnecessary. You just need a container of some sort. An array would be the most basic, but you might consider a vector or a set if you have the standard libraries.

    You... probably also want to dynamically allocate the container and dynamically allocate the notes on the heap. I'm not sure how far your simulation's supposed to scale, but stack space is limited and heap space is... less limited, so you could just create an arbitrarily sized number of Notes without worrying too much about that.

    So what I think you want is (I'm not a C++ programmer, btw, so...):
    Note* Generate(int n) {
        Note *notes;
        notes = new Note[n];
    
        for (unsigned int x=0; x<n; x+=1) {
            bool P = rand() % 1;
            int S = rand() % 100;
            int lX = rand() % 50;
            int lY = rand() % 50;
            notes[i] = new Note(P, S, lX, lY);
        };
    
        return notes
    };
    

    And then remember to free everything when you're done with it.

    Edit: Unfortunately, with this model, you need a default constructor for notes = new Note[n] to work. I'm not sure how you intend to use your Notes class, so you might want to just create a stupid one that takes 0 or -1 for values, or just initialize the randomized values within the default constructor. OR you should probably use vectors instead (since they won't force immediate construction of the Note objects). And maybe do some shit with const, but I hate const and could never understand it.

    hippofant on
  • Options
    EndEnd Registered User regular
    edited January 2015
    Khavall wrote: »
    End wrote: »
    Khavall wrote: »
    [...]
    but that obviously just creates a single note. Is there a way to have each note be named, say, "note_x" automatically when generated?

    It sounds like you probably want an array (or something array-like like a vector)

    If my memory is correct, something like:
    int *notes = new Note[n];
    ...
        notes[x] = new Note(P, S, lX, lY);
    
    Ok. I'm right in rehearsal now, but I'll check it out tomorrow and see if I can get that to work.
    also:
    for (unsigned int x=0; x<n; x+1) {
                                ^
    

    *cough*

    (also "*new" seems a little silly, ...you're creating on the heap and then copying it onto the stack?)
    I was getting really weird errors in Xcode and went "Fuck it, you want x+1? WILL THAT MAKE YOU HAPPY?! HERE, HAVE A STAR IN FRONT OF NEW SINCE YOU'RE COMPLAINING"


    I'm also at the end of a really busy week and taking my aggression out on Xcode is helpful.

    well
    to be fair
    now that I think about it, I think my example isn't quite right either anyway.

    I think you'll want an array of pointers, not just an array.

    (my syntax is a bit fuzzy, I...I'm not sure what it should look like offhand...?)

    I don't do a lot of C++ :-/

    End on
    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpg
  • Options
    hippofanthippofant ティンク Registered User regular
    edited January 2015
    Fuck it. Here's the version with vectors, which will be a lot more familiar, I think, if you're coming from Java or Python or whatnot:
    #include <vector>
    
    class Note
    {
    ... your stuff ...
    };
    
    std::vector<Note> Generate(int n)
    {
        std::vector<Note> notes;
        notes.reserve(n); // optional: reserve the memory upfront
    
        for (int i = 0; i < n; i++)
           bool P = rand() % 1;
           int S = rand() % 100;
           int lX = rand() % 50;
           int lY = rand() % 50;
           notes.push_back(Note(P, S, lX lY));
    
        return notes
    } 
    

    hippofant on
  • Options
    KhavallKhavall British ColumbiaRegistered User regular
    Oh yeah that makes way more sense to me.


    I'll do it that way.



    Also, in terms of number of notes, I probably won't need to go beyond, like, 24 per generation. So it's somewhat limited overall, just needs to be something from 6-24.

  • Options
    ecco the dolphinecco the dolphin Registered User regular
    Hi5 programming thread!

    I get home, and we have one perhaps satisfied customer!

    ...

    Can I get you guys to do this for my work as well?

    Penny Arcade Developers at PADev.net.
  • Options
    hippofanthippofant ティンク Registered User regular
    edited January 2015
    No, because I kinda suck at C++. For example... now that I think about it, I'm not sure rand() % 1 does what it's supposed to do. Rand() generates a random integer value, no? And any integer mod 1 is just 0? I think it needs to be rand() % 2.

    hippofant on
  • Options
    InfidelInfidel Heretic Registered User regular
    Any integer mod 1 is 0, since mod 2 is 1 or 0. (Not 2 or 1)

    OrokosPA.png
  • Options
    KhavallKhavall British ColumbiaRegistered User regular
    Oh whoops... yeah, there's that too.


    Don't code sleep-deprived while also learning a new language

  • Options
    CarpyCarpy Registered User regular
    So I'm taking an ethics in computing class this semester and I was really excited for it because the class can explore so many interesting and current topics that are also relevant to what new graduates might end up working with. Instead I was somewhat disappointed on the first day when the syllabus made it clear that the focus would be on things like technological singularities. Which is an interesting concept in itself but having it as the focus of the class feels like such wasted potential given the happenings of the past 5 years or so.

  • Options
    hippofanthippofant ティンク Registered User regular
    Carpy wrote: »
    So I'm taking an ethics in computing class this semester and I was really excited for it because the class can explore so many interesting and current topics that are also relevant to what new graduates might end up working with. Instead I was somewhat disappointed on the first day when the syllabus made it clear that the focus would be on things like technological singularities. Which is an interesting concept in itself but having it as the focus of the class feels like such wasted potential given the happenings of the past 5 years or so.

    Personally, I have always hated various "ethics in X" courses offered at universities, because I feel they're pretty shallow philosophy bait. You just can't get a good foundational grasp of ethics in a single term, and honestly, these courses are often taught by people who don't have the proper depth in ethics.


    Out of curiousity, what topics do you think the course should cover? I have my own laundry list, because I honestly believe that we are living in a new Industrial Revolution, with computers automating white-collar work that was previously considered "safe" irreplaceable employment, the Internet has completely changed how science is conducted, computers have completely distorted worldwide labour markets, driven up energy consumption, dramatically altered how nation-states engage in warfare, etc, etc, and it seems at times like we're all just focused on social interactions.

  • Options
    HounHoun Registered User regular
    hippofant wrote: »
    Carpy wrote: »
    So I'm taking an ethics in computing class this semester and I was really excited for it because the class can explore so many interesting and current topics that are also relevant to what new graduates might end up working with. Instead I was somewhat disappointed on the first day when the syllabus made it clear that the focus would be on things like technological singularities. Which is an interesting concept in itself but having it as the focus of the class feels like such wasted potential given the happenings of the past 5 years or so.

    Personally, I have always hated various "ethics in X" courses offered at universities, because I feel they're pretty shallow philosophy bait. You just can't get a good foundational grasp of ethics in a single term, and honestly, these courses are often taught by people who don't have the proper depth in ethics.


    Out of curiousity, what topics do you think the course should cover? I have my own laundry list, because I honestly believe that we are living in a new Industrial Revolution, with computers automating white-collar work that was previously considered "safe" irreplaceable employment, the Internet has completely changed how science is conducted, computers have completely distorted worldwide labour markets, driven up energy consumption, dramatically altered how nation-states engage in warfare, etc, etc, and it seems at times like we're all just focused on social interactions.

    I've got one. How about discussing the ethics of building a network device an employer (or government) can use to crack open outgoing SSL encrypted connections your employees open to various non-corporate internet sites. Because that's a thing, and I'm glad that there are ways to defeat it cropping up.

  • Options
    SpawnbrokerSpawnbroker Registered User regular
    There's also the question of ethics in hiring practices within the industry, treatment of women and minorities, some companies' use of perks to try to get their employees to work more hours, exploitation of H1B visas for cheaper labor...

    And also the ethics of automating vast amounts of work in almost every industry, from self-driving cars threatening the trucking industry to workflows negating the need for middle managers.

    It would be a fascinating course. Talking about singularities is a waste.

    Steam: Spawnbroker
  • Options
    EtheaEthea Registered User regular
    There's also the question of ethics in hiring practices within the industry, treatment of women and minorities, some companies' use of perks to try to get their employees to work more hours, exploitation of H1B visas for cheaper labor...

    And also the ethics of automating vast amounts of work in almost every industry, from self-driving cars threatening the trucking industry to workflows negating the need for middle managers.

    It would be a fascinating course. Talking about singularities is a waste.

    That majority of those issues are not isolated to the computer industry, and are most likely covered by other classes at the school ( Side note I remember taking a labor history first year class that covered the ethics of automation ). It is highly likely that Computer Ethics must avoid retreading ground that other departments or courses cover.

  • Options
    SpawnbrokerSpawnbroker Registered User regular
    Ethea wrote: »
    There's also the question of ethics in hiring practices within the industry, treatment of women and minorities, some companies' use of perks to try to get their employees to work more hours, exploitation of H1B visas for cheaper labor...

    And also the ethics of automating vast amounts of work in almost every industry, from self-driving cars threatening the trucking industry to workflows negating the need for middle managers.

    It would be a fascinating course. Talking about singularities is a waste.

    That majority of those issues are not isolated to the computer industry, and are most likely covered by other classes at the school ( Side note I remember taking a labor history first year class that covered the ethics of automation ). It is highly likely that Computer Ethics must avoid retreading ground that other departments or courses cover.

    Interesting!

    Louvdte.jpg

    Steam: Spawnbroker
  • Options
    CarpyCarpy Registered User regular
    edited January 2015
    I think the one that immediately jumped out to me was data aggregation and the way we trade our information for service. Some other ones off the top of my head: The way the internet has changed privacy and the relative anonymity of a person's actions, legal frameworks for the increasingly autonomous machines we are creating (like Google's cars), considering that a large portion of my schools graduates end up working for the DoD in some fashion you could pull some very good topics out of that as well.

    I guess I was hoping that if the school was going to have us take a class on ethics taught by a CS faculty member that they would at least do the legwork to design the course around engaging ideas or situations that their graduates might encounter. It's not as easy putting together a lecture plan on the singularity and then running with that for 10 years but it's probably better for the students.

    I'm also probably not being entirely fair to the course, there's at least one book we'll be reading on robotics and morality, but the professor did make it seem like that topic would be covered at a much higher level. Like at a can we impart morality on the intelligent machines we eventually develop level.

    Carpy on
  • Options
    KakodaimonosKakodaimonos Code fondler Helping the 1% get richerRegistered User regular
    Houn wrote: »
    hippofant wrote: »
    Carpy wrote: »
    So I'm taking an ethics in computing class this semester and I was really excited for it because the class can explore so many interesting and current topics that are also relevant to what new graduates might end up working with. Instead I was somewhat disappointed on the first day when the syllabus made it clear that the focus would be on things like technological singularities. Which is an interesting concept in itself but having it as the focus of the class feels like such wasted potential given the happenings of the past 5 years or so.

    Personally, I have always hated various "ethics in X" courses offered at universities, because I feel they're pretty shallow philosophy bait. You just can't get a good foundational grasp of ethics in a single term, and honestly, these courses are often taught by people who don't have the proper depth in ethics.

    Out of curiousity, what topics do you think the course should cover? I have my own laundry list, because I honestly believe that we are living in a new Industrial Revolution, with computers automating white-collar work that was previously considered "safe" irreplaceable employment, the Internet has completely changed how science is conducted, computers have completely distorted worldwide labour markets, driven up energy consumption, dramatically altered how nation-states engage in warfare, etc, etc, and it seems at times like we're all just focused on social interactions.

    I've got one. How about discussing the ethics of building a network device an employer (or government) can use to crack open outgoing SSL encrypted connections your employees open to various non-corporate internet sites. Because that's a thing, and I'm glad that there are ways to defeat it cropping up.

    Which companies are starting to do this? The places I've worked at that needed an SSL policy have just had a blanket ban on unapproved SSL connections and just blocked them at the network level and made any attempt to circumvent the block a fireable offense.

  • Options
    bowenbowen How you doin'? Registered User regular
    Why would you block SSL?

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    First guess is so it's harder for someone to hide what they're doing on their company's network.

  • Options
    hippofanthippofant ティンク Registered User regular
    Ethea wrote: »
    There's also the question of ethics in hiring practices within the industry, treatment of women and minorities, some companies' use of perks to try to get their employees to work more hours, exploitation of H1B visas for cheaper labor...

    And also the ethics of automating vast amounts of work in almost every industry, from self-driving cars threatening the trucking industry to workflows negating the need for middle managers.

    It would be a fascinating course. Talking about singularities is a waste.

    That majority of those issues are not isolated to the computer industry, and are most likely covered by other classes at the school ( Side note I remember taking a labor history first year class that covered the ethics of automation ). It is highly likely that Computer Ethics must avoid retreading ground that other departments or courses cover.

    I don't think that's a particularly valid line of reasoning, because, like I said, often these field-specific ethics courses are the only ethics courses taken by those students. That is, engineers take their engineering ethics courses and rarely go further and take philosophy courses, and philosophy students are highly unlikely to take Ethics in Computer Science, in my experience.

    I'd also add, in an ethics course for computer scientists, teaching THEM about ethical treatment of women and minorities would be critical. Though I'm willing to bet that the person teaching the course is a white male, so....

  • Options
    bowenbowen How you doin'? Registered User regular
    First guess is so it's harder for someone to hide what they're doing on their company's network.

    There's no reason to expose yourself to more risks by not using SSL because you have terrible people management skills.

    I hate it when people using malicious intent as an excuse to circumvent/squash good practices.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
Sign In or Register to comment.