Purchase Solution

How to find errors in C++ source code ?

Not what you're looking for?

Ask Custom Question

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;
}

Attachments
Purchase this Solution

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

Purchase this Solution


Free BrainMass Quizzes
Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

C# variables and classes

This quiz contains questions about C# classes and variables.

Basic Networking Questions

This quiz consists of some basic networking questions.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.