Hello, I am a new programmer attempting to tackle this puzzle after a couple of setbacks. I was excited about this project, but I am very stuck, and I am not sure where to go, or even if I'm on the right track. Okay, so let's get down to the problem: I am trying to write an address book; it needs to have ten people in it but right now I have everything set for two just for the sake of testing everything. (It takes ages to write in ten sets of addresses!) Anyway, what it needs to do is take the information of the people from the user and put it into an array of structures. What I am working on right now is the addPerson and getPerson functions: I'm not even going to worry about the others untill I can understand them better.
The addPerson function should copy the structure passed to it to the end of the array.
The getPerson should start at array element 0 and with each successive call return the next person in the array.
Both of these functions need to take a reference from a structure called PERSON, which is where all of the fields for the first and last names, and the address should be.
//Structure definition Person.
//contains definitions for Functionality.
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
struct PERSON
{
char firstName[20];
char lastName[20];
char address[50];
};
const int MAXPEOPLE = 2;
PERSON people[MAXPEOPLE];
PERSON p;
Now, this section is the functionality of the program. (this is my first time using a header file)
//.cpp file
//Contains functionality of addressBook
#include <iostream>
using namespace std;
#include "definitionsAddressBook.h"
int addPerson(PERSON p);
int getPerson(PERSON p);
int addPerson(PERSON p)
{
for(int i = 0; i < MAXPEOPLE; i++)
{
PERSON people[MAXPEOPLE];
people[0] = p;
}
return 0;
}
int getPerson(PERSON p)
{
for(int i = 0; i < MAXPEOPLE; i++)
{
people[i];
}
return 0;
}
int main()
{
cout << "This is an address book that can hold ten people. " << endl;
for(int i = 0; i < MAXPEOPLE; i++)
{
cout << "Please enter the first name: " << endl;
cin >> p.firstName;
cout << "Please enter the last name: " << endl;
cin >> p.lastName;
cout << "Now enter the address: " << endl;
cin >> p.address;
addPerson(p);
}
getPerson(p);
cout << people << endl;
}
I know that it is very rough, I am having a lot of trouble with my memory right now and that doesn't mix with learning new things. I would really appreciate some help, but I also want to say that this is my homework so please do not post a full answer: I really, really want to learn! I just need help with some explanations about structs and maybe how to use them in a situation like this. I'm not sure if I am referencing it properly in the functions with PERSON p. I also am trying very quickly to re-learn about arrays and how to manipulate them. If you can point me in the right direction, I would greatly appreciate it. Thank you very much, in advance :)