Explore BrainMass

Explore BrainMass

    How to find errors in C++ source code ?

    Not what you're looking for? Search our solutions OR ask your own Custom question.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Please correct the errors with replacement lines beside it. And then give short notes on why it is wrong.

    The code is attached.

    1) Please correct the errors with replacement lines beside it. And then give short notes on why it is wrong.

    class Person
    {
    private:
    char name[30];
    int age;

    public:
    Person (string, int);
    int setage (int);
    int setname (char *);
    void show (void);

    };

    ///////////////////////////////////////////////

    void main()
    {
    Person a_group [5];
    int i;

    for (i=0; i<6; i++)
    a_group[i].setage(i+1);

    for (i=0;i<6;i++)
    cout << "Person " << i+1 << " is " << a_group[i].age << end1;
    }

    //////////////////////////////////////////////

    2) Please correct the errors with replacement lines beside it. And then give short notes on why it is wrong if the below codes replace the codes between the two === in 1):

    void main (void)
    {
    Person a_person;
    a_person.age = 99;
    }

    © BrainMass Inc. brainmass.com March 4, 2021, 6:30 pm ad1c9bdddf
    https://brainmass.com/computer-science/cpp/find-errors-source-code-47384

    Attachments

    Solution Summary

    The main things that you can learn from this example are:
    1) practical mistakes and how can they can be avoided
    2) use of get and set constructors to access private members of a class
    3) declaration of iostream to use cout and cin
    4) why you need to be careful about array bounds

    $2.49

    ADVERTISEMENT