well i ran into a major problem, my head has been throw for a loop and it wont stop spinning,
here is the main jist of my assignment:
Quote
Create a project called addressBook
Add a header file and cpp file for your project
All of your definitions should go in the header file.
In the header file create the definition for your structure. Call it PERSON.
Your structure should have fields for first name, last name, address, and optionally a phone number.
Inside the cpp file you will create the functionality for your address book
Inside the cpp file declare a global array of 10 PERSONS to hold all of the records in your address book call it people. Use a const called MAXPEOPLE to set the size of the array. Put the const in the header file.
You are probably going to want to declare an integer variable to keep track of where you are at in the array.
Create functions addPerson, getPerson
These functions should take as arguments a reference to a PERSON structure.
The addPerson method 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.
Create overloaded findPerson functions. One function should take only the persons last name
The other function should take both the persons last and first names.
All code for the functions should be in the cpp file
From main write functionality that will test your address book code
Add a header file and cpp file for your project
All of your definitions should go in the header file.
In the header file create the definition for your structure. Call it PERSON.
Your structure should have fields for first name, last name, address, and optionally a phone number.
Inside the cpp file you will create the functionality for your address book
Inside the cpp file declare a global array of 10 PERSONS to hold all of the records in your address book call it people. Use a const called MAXPEOPLE to set the size of the array. Put the const in the header file.
You are probably going to want to declare an integer variable to keep track of where you are at in the array.
Create functions addPerson, getPerson
These functions should take as arguments a reference to a PERSON structure.
The addPerson method 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.
Create overloaded findPerson functions. One function should take only the persons last name
The other function should take both the persons last and first names.
All code for the functions should be in the cpp file
From main write functionality that will test your address book code
Here is what my code is so far
Header file
const int MaxPeople = 10;
struct person
{
char first;
char last;
char *address;
char *number;
};
int i = 0;
Main
#include <iostream>
#include "header.h"
int maincounter = 0;
int getcount = 0;
using namespace std;
void addPerson(struct person &add);
void getPerson(struct person &get);
void findPerson (struct person &find);
void findPerson (struct person &findlast, struct person &findfirst);
person bookArray[MaxPeople]; //This is the main "address book" array
int main()
{
char *last = new char[20];
char *first = new char[20];
char choice;
person add;
person getStruct;
cout << "Address Book" << endl<< endl;
while (true)
{
cout << " Enter 1 to add to the address book. " <<endl;
cout << " Enter 2 to get a person. " << endl;
cout << " Enter 3 to find a person by last name only." << endl;
cout << " Enter 4 to find a person by last name and first. " << endl;
cout << " Enter any other key to quit. " << endl;
cout << endl << "Please make a selection: ";
cin >> choice;
switch(choice)
{
case '1':
cout << "Enter First Name" << endl;
cin >> add.first;
cout << "Enter Last Name" << endl;
cin >> add.last;
cout << "Enter Address" << endl;
cin.getline(add.address, 40);
addPerson(add);
break;
case '2':
cout << "Getting the next person in the address book: " << endl << endl;
getStruct = getPerson(getStruct)
cout << getStruct << endl;
break;
case '3':
cout << "Please enter the last name to search for: " << endl;
cin >> last;
findPerson(last);
break;
case '4':
cout << "Please enter the last name and then the first name to search for: " << endl;
cout << "Last name: ";
cin >> last;
cout << "First name: ";
cin >> first;
findPerson(last, first);
break;
*/
default:
return 0;
break;
}
}
return 0;
}
void addPerson(struct person &add)
{
bookArray[maincounter]=add;
maincounter++;
}
void getPerson(struct person &get)
{
if (getcount > maincounter)
{
getcount = 0;
get = bookArray[getcount];
getcount++;
}
else
{
get = bookArray[getcount];
getcount++;
}
}
void findPerson (struct person &find)
{
for (int i=0; i<=MaxPeople; i++)
{
if (find == person.last)
{
// Display all the data from the array location that holds the structure with the matching value.
}
}
//I have a feeling my logic is incorrect using a counter to check each array value for the last name.
}
void findPerson (struct person &findlast, struct person &findfirst)
{
for (int i=0; i<=MaxPeople; i++)
{
if (findlast == person.last || findfirst == person.first)
{
// Display all the data from the array location that holds the structure with the matching values.
}
}
//I have a feeling my logic is incorrect using a counter to check each array value for the last and first names.
}
i thought i was off to a good start, but it appears my looking into the eyes of god as a dead end....can anyone guide me through the proper way of completing this? im troubled on this project :(
rep of course for help
thank you so much
kevin


Sign In
Create Account


Back to top









