Help in C++

hi

im trying to do a program about an array of ppl.

i need to let the user input the details of 10 or less ppl. and the information to be stored in th program. the program should consis of two loops th 1st loop should continue repeating round and allows the user to enter the next person until the array is full up or the user decides to stop. the 2nd loop is shold print out all the dtails entered by the usr. i need to delare an array of 19 ppl and an integer that will hold the numbr of ppl so far.

this is wat i done so far....and now im confused.....n stuck plz help me

#include <iostream.h>

class person
{
private:

int age;

public:

void set_age(int a);
int get_age();
void print();
void input();
};
void person::input()
{
cout<<"age?"<<endl;
cin>>age;
}
void person::set_age(int a)
{
age = a;
}
int person::get_age()
{
return age;
}
void person:rint()
{
cout << age<<endl;
}
int main()
{
person[10];
int num_stored;
}

please help
UJAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

meow00Commented:
Hello,

    I am not quite sure what u need, but several things :
 
1.
-----------------------
 void person:rint()
{
cout << age<<endl;
}
----------------------
should be "void person::print()". typo ?

2. In main, the declaration of person is not proper. I would change to :
-----------------------------------------
int main()
{
 person PPL[10];
 int num_stored;
 for(int i=0; i<10;i++){
  PPL[i].input() ;
 }
 return 0 ;
}
-----------------------------------------

 It would be good if u can describe more clear about what u need !

 meow ....

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
UJAuthor Commented:
i  need to let the user input the details of 10 or less ppl. and the information to be stored in th program. i need to delare an array of 10 ppl and an integer that will hold the numbr of ppl so far.

the program should consist of two loops th 1st loop should continue repeating round and allows the user to enter the next person until the array is full up or the user decides to stop. the 2nd loop is shold print out all the dtails entered by the user.
RJSoftCommented:
You have not instructed your person objects to do anything.

int main()
{
person[10];
int num_stored;
}


First you need to create the 10 people. You did that with this statement

person[10];

This means that you now have 10 objects (or instances) of the class person.

Begin Outer loop//////////////////////////

Next you need to load those 10 persons.

I am not going to give you the exact code, but give you hints...

Remember person is an array of objects (arrays can be indexed, array[0])


index = zero (valid is 0 to 9)

begin load loop

clear the screen here.

prompt "Enter person age or X to exit"
INPUT = get input value from user.

if user entered X break this loop.

person is indexed to first instance (index value).SetAge(INPUT);

index is advanced by 1.

if index is equal to 10 then break this loop.

end load loop


Now you have some or all of your persons loaded with values.

Also it is possible that the user did not enter anything here. So you might want to check for that condition, if so say someting like.

Press Y if you wish to exit app? if so break the outer loop. That is because you probably dont want to print an empty person.

Note index still contains the value of how many of the 10 persons got an age value. So you can use it in the next printing loop part.

//printing loop
int X=0;
while(1)
{

print the value of the person using the X to index from person to person of your array and of each person use the accessor function GetAge to return that persons age. Use newline at the end of each print statement to go down a line.

X++;
if(X==index)break;
}//endwhile and end printing loop

You might like a pause statement here. Sometimes that can getch() ya.

Now you printed out what the user stated. Time to do it all over again.

So here is the end of the outer loop but before you do the whole thing over you might want to reset your index. Either at the top of the loop with index =0 or here at the bottom. Just so you dont keep adding and adding to your idex which will cause an error if you go past 9 (remember valid is 0 to 9 in C/C++ array)

End outer loop/////////////////////////////////

RJ

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.