baavgai's Profile User Rating: *****

Reputation: 6099 Overlord
Group:
Mentors
Active Posts:
13,221 (4.8 per day)
Joined:
16-October 07
Profile Views:
131,689
Last Active:
User is offline Today, 03:05 AM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Linux
Favorite Browser:
FireFox
Favorite Processor:
Who Cares
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
725
Expert In:
C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

Latest Visitors

Icon   baavgai has not set their status

Posts I've Made

  1. In Topic: how do I create a strike through in an array when the word is clicked

    Posted 4 May 2015

    This looked amusing enough I thought I'd take a stab at it. It also struct me that the toggle could be generalized.

    http://jsfiddle.net/xbwrted3/3/
  2. In Topic: Need help with 2D arrays and out putting decimal points - Homework

    Posted 3 May 2015

    Heh, I wasn't critiquing the description style. Rather, the recommended approach is poor. Using a 2D array as a kind of table of of data, with one dimension being rows and each column being a different field is messy, confusing, and teaches bad habits.

    The proper approach for "read data of type X from file, perform actions using elements of that type, and display results Y" would be to define a type X and go from there.

    e.g.
    struct Batter {
        int playerNum;
        int appearances;
        int hits;
        int walks;
        int outs;
        double getAverage() const;
    };
    typedef std::vector<Batter> Batters;
    
    void display(const Batter &);
    void display(const Batters &);
    int load(Batters &, std::istream &);
    int load(Batters &, const char *filename);
    
    


    You reasonably should cover std::vector and struct before messing with std::ifstream.
  3. In Topic: Need help with 2D arrays and out putting decimal points - Homework

    Posted 3 May 2015

    There is no reason you should store the average in the array. Your instructions suck, you shouldn't be using a 2D array at all, but at least they don't tell you to do that.

    I would do something like:
    // First column is player number, second column is plate appearances, 3rd is hits, 4th is walks, and last is strike outs.
    const int COLS = 5;
    // note, an enum would be helpful for the cols...
    
    const int MAX_ROWS = 10;
    typedef int Batters[MAX_ROWS][COLS];
    
    double calcAverage(Batters, int rowNum);
    void displayBatters(Batters, int rows);
    int load(Batters, std::istream &);
    int load(Batters, const char *filename);
    
    int main() {
        Batters batters;
        int rows = load(batters, "batters.txt");
        if (rows==0) { return 1; }
        displayBatters(batters, rows);
    
        // system ("pause");
        return 0;
    }
    
    void displayBatters(Batters ar, int rows) {
        for(int row = 0; row < rows; row++) {
            for(int col = 0; col < COLS; col++) {
    			cout<<fixed<<showpoint<<setprecision(3);
                cout << ar[row][col] << " ";
            }
            cout << calcAverage(ar) << endl;
        }
    }
    
    


    Hope this helps.
  4. In Topic: How to initialize a variable only once?

    Posted 3 May 2015

    public void addNewSong() {
    
        Song song1 = new Song();
        Song song2 = new Song();
        Song song3 = new Song();
        Song song4 = new Song();
    
    


    You see those, the are ALL local variables. So, assuming you've defined the same variables somewhere in your object, you ain't writing to them. Also, your input code is repeated over and over...

    Consider the following method:
    private Song getFromUser() {
        Song song = new Song();
        System.out.println("Name of song:");
        song.setName(console.next());
        // consider returning null here if the user enteres a blank line
        // no empty song titles!
    
        System.out.println("Artist:");
        song.setArtist(console.next());
    
        System.out.println("File size (MB):");
        song.setFileSize(console.nextInt());
    
        System.out.println("Duration (seconds):");
        song.setDuration(console.nextInt());
        System.out.println("Song successfully added.");
        System.out.println("");
        return song;
    }
    
    


    That gets a loaded Song object from the user. There is no conceivable reason to have an isEmpty method in your song, you just don't let the user enter blanks. For your program, you can do something like:
    
    class SongDatabase {
        // these belong here
        private Song song1, song2, song3, song4;
    
        public void addNewSong() {
            if (song1==null) {
                song1 = getFromUser();
            } else if (song2==null) {
                song2 = getFromUser();
            } else if (song3==null) {
                song3 = getFromUser();
            } else if (song4==null) {
                song4 = getFromUser();
            } else {
                System.out.println("The database is currently full. Please delete a song before adding a new one.");
            }
        }
    
    


    Hope this helps.
  5. In Topic: operator<< overloading

    Posted 2 May 2015

    I would avoid the friend functions and throw the operator override outside, if you are allowed. e.g.
    #include <iostream>
    
    class Thing {
    public:
        Thing(const std::string &name);
        virtual void print(std::ostream &) const;
        const std::string &getName() const;
    private:
        std::string name;
    };
    
    class Thing2 : public Thing {
    public:
        Thing2();
        void print(std::ostream &) const;
    };
    
    struct Thing3 : public Thing {
        Thing3();
    };
    
    
    std::ostream &operator<< (std::ostream &, const Thing &);
    
    int main() {
        std::cout << Thing("Bob") << std::endl;
        std::cout << Thing2() << std::endl;
        std::cout << Thing3() << std::endl;
    
        return 0;
    }
    
    std::ostream &operator<< (std::ostream &out, const Thing &x) { x.print(out); return out; }
    
    Thing::Thing(const std::string &n) : name(n) { }
    void Thing::print(std::ostream &out) const { out << "Thing [" << name << "]"; }
    const std::string &Thing::getName() const { return name; }
    
    Thing2::Thing2() : Thing("Thing2") { }
    void Thing2::print(std::ostream &out) const { out << "The amazing Thing2 [" << getName() << "]"; }
    
    Thing3::Thing3() : Thing("Thing3") { }
    
    


    Hope this helps.

My Information

Member Title:
Dreaming Coder
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
Jersey, be afraid.
Years Programming:
25
Programming Languages:
Most.

Contact Information

E-mail:
Click here to e-mail me
Website URL:
Website URL  http://

Comments

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  1. Photo

    mireille4U Icon

    30 Apr 2015 - 05:26
    Greeting from mireille i saw your profile today and i became interested in you and i will like to know more about you and if you can mail an email to my mail address (mireille4u@live.com) i will give you my picture.here is my mail address i hope we can move from here.above. Mireille
  2. Photo

    ImChicago Icon

    17 Mar 2015 - 17:34
    Hey, im new to coding, how do you recommend starting? What should I master first? Should I use a website to help me?
  3. Photo

    8byte Icon

    10 Jan 2014 - 11:08
    Awesome, thanks for all the help!
  4. Photo

    codiddle Icon

    07 Mar 2013 - 18:59
    GENIUS GUY HERE MAN. Write a book!
  5. Photo

    mamelove25 Icon

    19 Feb 2013 - 10:53
    Hello My Dear, My Name is Mame. i saw your profile today and became interested in you,i will also like to know you more,and if you can send an email to my email address,i will give you my pictures here is my email address (mame25live@yahoo.co.uk) I believe we can move from here! Am waiting for your mail to my email address above because i have much to tell you,
    love Miss Mame.
  6. Photo

    bilbil0629 Icon

    24 Oct 2012 - 05:39
    hey! you mongolian?
  7. Photo

    Ticon Icon

    20 Aug 2012 - 13:23
    I just noticed your an expert in cheese. I lol'd
  8. Photo

    mostyfriedman Icon

    18 Aug 2012 - 23:13
    Hello there Brett
  9. Photo

    MehrdadSecret Icon

    26 Jul 2012 - 05:51
    hello, can i have a contact email or Yahoo or something? Need ur help badly
  10. Photo

    Jeet.in Icon

    18 Apr 2012 - 23:17
    Thanks ! Solved My problem !
    http://www.dreamincode.net/forums/topic/275578-simple-whitespace-remover/page__gopid__1603556&#entry1603556
  11. Photo

    RetardedGenius Icon

    25 Oct 2011 - 14:29
    I agree so much with your opinion of incompetent CS teachers. So true!
    http://www.dreamincode.net/forums/topic/252848-venting-a-frustration/page__view__findpost__p__1469659
  12. Photo

    WabiSabi Icon

    21 Oct 2011 - 11:00
    I agree with assert(C). However, I'd rather not specify what you are "the best" at.
  13. Photo

    assert(C) Icon

    20 Oct 2011 - 08:38
    You are the best
  14. Photo

    macosxnerd101 Icon

    30 Sep 2011 - 09:33
    Congrats on hitting the big 3k!
  15. Photo

    sjin Icon

    16 Aug 2011 - 18:41
    This guy is AWESOME! Cheers bro!
  • (3 Pages)
  • +
  • 1
  • 2
  • 3