Manipulating menus, switching from one to another...

OK, so my current assignment, (which I thought was due next week, but is apparently due this week), is to take a menu program we wrote earlier in the semester, and basically pop it into he current address book program were working on. Now bear with me, there is going to be a bit of code I have to show so you can see all whats going on, and where I'm at so far. I have managed to get two menu functions up and running, my addPerson, and my printBook. They both work, and I'm relatively certain I can keep doing what I'm doing and get everything switched out, but what I want to know is, is there a better way to do this than the way I'm doing it now? I have created a separate header file that contains my Menu class and functions so that I only need to pop in a few lines in my Main to get the program out to the screen. If anyone knows of a more efficient, or even better way, then I'm all ears (and please remember, this is homework, so don't just post code, I'm trying to learn, not skate through the class ;-) ).

I'll post the assignment, then all my code files....

So here's what were asked to do :


Implement the menu you crated in lab 1 for use inside your addressBook. Because the menu is setup to take pointers to void functions you are going to have to create a layer of functionality that sits between the two. This kind of structure can be thought of as a three tier approach.

Here is a simplistic example

addressBook ab;
Menu m;

void addPerson();

int main()
{

m.addMenu("1. Add Person", addPerson);
m.runMenu();

}
void addPerson()
{
PERSON p;
// get the persons information from the keyboard and store it in p

ab.addPerson(p);
m.waitKey();
}
You will have to create functions for each of your menu items which inturn call corresponding funcitons in the addressBook. Also, notice that global variables are being used. For now, this is acceptable.


Here is my Menu.h file :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include<iostream>
#include<string>
using std::string;
#include <cstdlib>
#include <conio.h>
#include "addressbook.h"


using namespace std;

#ifndef MENU
#define MENU

const int MAXCOUNT = 20;

struct menuItem
{
	void (*funct) ();
	char descript[50];

};

class Menu
{

private:

	menuItem mi[MAXCOUNT];
	int count;
	void runSelection ();

public:
	Menu();
	void addMenu(char *Description, void (*f) () );
	void runMenu();
	void waitKey();
	void func1();
	bool func1(const PERSON &p);
	void func2();
	void func3();
	void Exit();
	void printBook();
	bool addPerson();
	
};
#endif

addressBook newBook;

Menu::Menu()

		: count()
{

}


void Menu::addMenu(char *Description, void (*f) () )

{

	if(count < MAXCOUNT)
	{

		this->mi[count].funct = f;
		strcpy(this->mi[count].descript, Description);
		count++;
	}
}


void Menu::runMenu()

{
		for(;;)
		{
			system("CLS");;
			for(int i = 0; i < count; i++)
			{
				cout << this->mi[i].descript << endl;
			}

		runSelection();
		
		}
}

	

		void Menu::runSelection()
		{

		int select;

		cin >> select;

		if(select <= count)
			this->mi[select - 1].funct();

		}

		void waitKey()
{

	cout << "Press a key to continue " << endl;
	while(!kbhit())
		;

	getch();
	fflush(stdin);

};


		void func1()

{
	
	PERSON p;
	bool status;
char lName[50];
char fName[50];
	cout << "Enter First Name " << endl;
				cin >> p.fName;
				cout << "Enter last Name " << endl;
				cin >> p.lName;
				cout << "Enter Address " << endl;
				cin >> p.Address;
				status = newBook.addPerson(p);
				if(status == false)
					cout << "Sorry There is no more room in the address book " << endl;
				else
					cout << "Thanks for your Entry " << endl;	
				
}

		void func2()

{
	addressBook newBook("Test1", "TEST2", "1234");

	PERSON me = {"Johnny", "Rocket", "923 go"};

	PERSON me2 = {"CJ", "MZ", "123"};

	PERSON me3 = {"YEP", "NOPE", "4321"};
	newBook+=me;
	newBook+=me2;
	newBook+=me3;
	&addressBook::printBook;
	newBook.printBook();
	waitKey();
	return;
}






void func3()

{
	char c;
	cout << "hello from function 3 " ;
	cin >> c;
}

void Exit()

{

	cout << "Goodbye! " << endl;
	exit(0);

}


void addPerson()
 {
 PERSON p; 
 // get the persons information from the keyboard and store it in p
 addressBook newBook;
 Menu m;
newBook.addPerson(p);
 m.waitKey(); 

}


And here is my addressbook.h file :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef _ADDRESSBOOK
#define _ADDRESSBOOK
#include <vector>
#include<string>
using std::string;
#include <iostream>
using namespace std;

using std::istream;
using std::ostream;

const int MAXADDRESS =25;

struct PERSON
{
 string fName;
 string lName;
 string Address;
};

class addressBook
{
private:
vector<PERSON> people;

 int head;
 int tail;

public:

 addressBook();

 addressBook(const PERSON &p);
 addressBook(const PERSON p[], int size);
 addressBook(char *fName, char *lName, char *address);
 bool addPerson(const PERSON &p);
 bool sortcomp(const PERSON& p1, const PERSON& p2);
 bool getPerson(PERSON &p);
 bool findPerson(const string& lastName, PERSON& p);
 bool findPerson(const string& lastName, const string& firstName, PERSON& p);
 void bubbleSort(int *array,int length);
 void printBook();
 void sort();
 bool func1(const PERSON &p);
 void newBook();

friend ostream &operator << (ostream &, addressBook &);
addressBook operator =(const string& str);
addressBook &operator +=(const PERSON &p); 
addressBook operator [](int x); 

};
#endif 


And here is my addressbook.cpp file :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>
#include<string>
using std::string;
#include "addressBook.h"

using namespace std;

addressBook::addressBook()
: head(0), tail(-1)
{
 
}

addressBook::addressBook(const PERSON &p)
: head(0), tail(-1)
{
	addPerson(p);
}

addressBook::addressBook(const PERSON p[], int size)
: head(0), tail(-1)
{
 for(int i = 0; i < size; i++)
 addPerson(p[i]);
 
}

addressBook::addressBook(char *fName, char *lName, char *Address)
: head(0), tail(-1)
{
 PERSON tmp;
 tmp.fName = fName;
 tmp.lName = lName;
 tmp.Address = Address;
addPerson(tmp);
}

bool addressBook::addPerson(const PERSON &p)
{
 
 
 people.push_back(p);

 if(tail == -1)
 tail++;
 return true;
 
}

bool addressBook::getPerson(PERSON &p)
{
 if(tail >=0)
 {
 if(tail >= people.size())
 tail = 0;
 p = people[tail];
 tail++;
 return true;
 }
 return false;
}
bool addressBook::findPerson(const string &lastName, PERSON &p)
{
	for(size_t i = 0; i < people.size(); i++)
	{
		if(people[i].lName.compare(lastName))
		{
			p = people[i];
			return true;
		}
	}
	return false;
}
bool addressBook::findPerson(const string &lastName, const string &firstName, PERSON &p)
{
	for(size_t i = 0; i < people.size(); i++)
	{
		if(people[i].lName.compare(lastName) && people[i].fName.compare(firstName))
		{
			p = people[i];
			return true;
		}
	}
	return false;
}


void addressBook::printBook()
{
	for(size_t i = 0; i < people.size(); i++)
	{		
		std::cout << people[i].fName << "\t" << people[i].lName << "\t" << people[i].Address << std::endl;
	}
}


 bool addressBook::sortcomp(const PERSON& p1, const PERSON& p2)
{
	int result = (p1.lName.compare(p2.lName)) ;
    if ( result > 0 )
        return true ;
    if ( result < 0 )
        return false ;
    return (p1.fName.compare(p2.fName)) > 0 ;
}

void addressBook::sort() 
{
    bool didSwap ;
    do
    {
        didSwap = false ;

        for ( unsigned i=1; i<people.size(); ++i )
            if ( sortcomp(people[i-1], people[i]) )
            {
                std::swap(people[i-1], people[i]) ;
                didSwap = true ;
            }

    } while ( didSwap ) ;
}

addressBook &addressBook::operator +=(const PERSON &p)
{
	addPerson(p);
	return *this;
};

addressBook addressBook::operator [](int x)
{
	return people[x];
};

ostream &operator << (ostream &output, addressBook &ab)
{
	PERSON tmp;
    ab.getPerson(tmp);
	output << tmp.fName << " " << tmp.lName << " " << tmp.Address << endl;
	return output;
}


I have one more file to post, but I've ran out of room in this post, so see the next post please.
Last edited on
And finally, here is my main.cpp file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include <iostream>
#include <cstdlib>
#include <conio.h>
#include <string>
using std::string;
#include "addressBook.h"
#include "menu.h"

using namespace std;
int printMenu();
void waitKey();
/*
bool addPerson();

void func1();
void func2();
void func3();
void Exit();
*/
void func1();
const int ADDPERSON = 1;
const int GETPERSON = 2;
const int FINDLAST = 3;
const int FINDBOTH = 4;
const int PRINT = 5;
const int NAMESORT = 6;
const int EXIT = 0;
void func2();
int main()
{
	
	
	PERSON p;
	addressBook ad;
	addressBook ab;
	addressBook myBook;

	addressBook newBook("Test1", "TEST2", "1234");
	
	PERSON me = {"Johnny", "Rocket", "923 go"};

	PERSON me2 = {"CJ", "MZ", "123"};

	PERSON me3 = {"YEP", "NOPE", "4321"};

	newBook+=me;
	newBook+=me2;
	newBook+=me3;

	newBook.printBook();
	
	Menu m;
	m.addMenu("1. AddPerson ", func1);
	m.addMenu("2. PrintBook ", func2);
	m.runMenu();
	/*
	m.addMenu("3. GetPerson ", newBook.getPerson);
	m.addMenu("4. Exit ", Exit);

	m.runMenu();

	*/

int selection;

bool status;
char lName[50];
char fName[50];
		

		selection = printMenu();
		while(selection != EXIT )
		{
		switch(selection)
			{

			case ADDPERSON :
				cout << "Enter First Name " << endl;
				cin >> p.fName;
				cout << "Enter last Name " << endl;
				cin >> p.lName;
				cout << "Enter Address " << endl;
				cin >> p.Address;
				status = ad.addPerson(p);
				if(status == false)
					cout << "Sorry There is no more room in the address book " << endl;
				else
					cout << "Thanks for your Entry " << endl;

				waitKey();	
				break;
			case GETPERSON :
				status = ad.getPerson(p);
				if(status)
					cout << p.fName << "\t" << p.lName << " " << p.Address << endl;
				else
					cout << "Sorry The address book is empty " << endl;

				waitKey();

				break;
			case FINDLAST :
				cout << "Enter a last name " << endl;
				cin >> lName;
				status = ad.findPerson(lName,p);
				if(status)
						cout << p.fName << "\t" << p.lName << " " << p.Address << endl;
				else
					cout << "Sorry, Name not found " << endl;

				waitKey();
				break;

			case FINDBOTH :
				cout << "Enter last name " << endl;
				cin >> lName;
				cout << "Enter first name " << endl;
				cin >> fName;
				status = ad.findPerson(lName, fName,p);
				if(status)
					cout << p.fName << "\t" << p.lName << " " << p.Address << endl;
				else
					cout << "Sorry, Name not found " << endl;

				waitKey();
				break;

			case NAMESORT :
				ad.sort();
				newBook.sort();
				myBook.sort();
				cout << "Your addressbook has been alphabetically sorted, choose print from the main menu to see the results " << endl;
				waitKey();
				break;
				
			case PRINT :
				
				newBook.printBook();
				ad.printBook();
				myBook.printBook();
				waitKey();
				break;
			case EXIT :
				cout << "Thanks for using the address book " << endl;
				exit(0);
		}
			selection = printMenu();
		}
		
};

int printMenu()
{
	

int selection;

	system("CLS");
	cout << "1. Add A Person" << endl;
	cout << "2. Get A Person " << endl;
	cout << "3. Find A person By Last Name " << endl;
	cout << "4. Find A person By First and Last Name " << endl;
	cout << "5. Print the address book " << endl;
	cout << "6. Sort by last name " << endl;
	cout << "0. Exit this program " << endl;
	cin >> selection;

	return selection;

};

void Menu::waitKey()
{

	cout << "Press a key to continue " << endl;
	while(!kbhit())
		;

	getch();
	fflush(stdin);

};

I know that this is a whole heaping heck of a lot to look at, this class project just keep getting bigger and bigger.

So if anyone sees a way I can do this better, and if you feel up to, I' appreciate being pointed in the right direction, thanks in advance.
All right it's me again .... :)

Now that you are going to have a menu class - you should put the functionality for it, in the class - there should be hardly anything in main().

The functionality for Person & AddressBook would also reside in their respective classes.

Here are some thoughts

- main() creates a Menu object & calls it's constructor to get everything rolling - it should be about 10-15 lines long maximum;
- A menu item would create an AddressBook object.
- The Person class should have it's own interface & constructors and be in it's own header file, to make it easier to get at it's info. Because I would create the person first, then add it to the address book, not add it through the address book constructor;
- A menu item would create a Person object using it's constructors, then send it to one of the AddressBook functions;
- The menu class should contain only menu stuff - most of the work is done by the AddressBook & Person classes. Don't be tempted to copy code from main() as is, into the menu class;

The classes should provide the interface, not the main() function.

So your thinking: "Awww Crap - I have change everything completely !! "

But it is all about encapsulation & modularity which is meant to make things easier. If you had all of the addressBook & Person functionality in their classes then adding the menu class would have been easy.

Just as an aside: In a real app, the Person class would be composed of Names, PostalAddress, PhysicalAddress, Phone numbers, Email etc. - all of which would be objects in their own right, so one might consider renaming Person to something like CAddrBkEntry . I realise your assignment is simple in this regard - it's just an idea.

There you go - more stuff to think about !!

Yeah, I can see how doing things that way would work better, but were only allowed to do what the teacher wants us to do. I'm not even sure I'm allowed to add in the menu header. Chances are, I'm probably going to have to integrate the constructors and functions into the existing address book, and the change in menu will probably only be a temporary move, just to show us how to do it. I hit the teacher up earlier in an email to see if what I've done so far is what he's looking for. I have a feeling I'm not doing what he's expecting. When were done working on this as an assignment, I plan to try out what your saying, I'd like to see if I can do it. Once I know for sure what needs to be done I'll be back in here trying to work it all out.
Yeah, I can see how doing things that way would work better, but were only allowed to do what the teacher wants us to do.


But what I am proposing doesn't violate the requirements of the assignment & it's not complicated either.

Chances are, I'm probably going to have to integrate the constructors and functions into the existing address book, and the change in menu will probably only be a temporary move, just to show us how to do it.


I have a feeling I'm not doing what he's expecting.
When were done working on this as an assignment, I plan to try out what your saying, I'd like to see if I can do it.


In my mind it is best to do it the best & most elegant & organised way as possible. There don't seem to be too many restrictions in your assignment & I am not proposing anything really hard. I think you have the ability to do it properly now.

Maybe I need to explain it better.

The interface for the app is the menu, and this is implemented with a menu class. Ideally you would create a new menu class derived from the base menu class called CMenuAddrBk say. This is so you can create different menus for different things. This isn't really needed here but a good practice anyway, because it's easier to extend in the future. To do that you would need virtual functions, - I don't know whether you have learnt that either. Always think about how things might need to be scaled up in the future.

The example code for the menu class, indicates to me that you should set it up with the menu options & associate a function for each one.

The CMenuAddrBk class would have an addressbook object as a member, so you can call it's functions.

In your existing main(), each case in the switch would correspond to a function in the CMenuAddrBk class. The functions should call the appropriate addressbook function - which actually does the work. The addPerson function might look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
bool addressBook::addPerson() {
	PERSON p;
	
	cout << "Enter First Name " << endl;
	cin >> p.m_fName;
	cout << "Enter last Name " << endl;
	cin >> p.m_lName;
	cout << "Enter Address " << endl;
	cin >> p.m_Address;
	
	people.push_back(p);
	
	if(tail == -1) {
		tail++;
	}
	return true;
}


I am not sure of your reasoning for returning bool in this function as it always returns true. Error checking is important - I would have used a try - catch block with an exception, but you probably haven't learnt that yet.

What was the purpose of the head & tail variables?

So now the code is in the addressbook class & not in main() .

Once you have done that, there is not a lot left to go in main(). In a simple situation, main() should only create a menu object & call it's runmenu function - and that is all. That's why I said 10 -15 lines in my last post.

The menu functions should be brief too, because all they do is call an addressbook function.

All this stuff is about modularity & encapsulation - one of the main concepts in OOP.

I am just trying to get you to put the logic in the right place. Here is a real world example:

Say you are writing code to simulate a fruit shop, and you have machines that pack different sorts of fruit. There is a main function which calls a selection function that sends the right fruit to the correct packing machine, and each packing machine is a function of its own.

None of the functions care or even know what is happening with the details of the other functions - they are all separate. They have particular input & output, but what the details of next function does, is irrelevant to the current function.

What you are doing at the moment, is putting code for the Apple Packing Machine into the main function.

Anyway - you sound dedicated & committed to your programming which is really good, hopefully you have enough time left over for your other subjects!!

Hopefully I (& others) can steer you towards getting a really good grade which you deserve for putting in so much time & effort.
So let me try and work this out conceptually if you don't mind...

1
2
3
4
5
6
7
8
9
10
11
// in a simplistic version, I would have 3 files working together...


addressbook.h // this has my address book constructors and their functions all in one spot

menu.h // this contains pretty much what I have in main at the moment, which 
      //calls on my address book functions, including my user inputs and 
     //outputs to the screen.

main.cpp // Basically, I'm running a switch case that calls up what I have
        // in my menu.h file, which is in turn calling from addressBook.h 


See, if that's what your getting at, and I think it is, then that makes perfect sense to do that, and I will be asking today if I can do that when I see the teacher in a couple hours. For now, he's told me that I am to completely replace the current menu system with that of the one we did in week one, so main is going to get a whole lot smaller, it's just a question right now of how he wants that done, which I will learn soon enough.
So now I know. I need an addressbook.h, addressbook.cpp, menu.h, menu.cpp and main.cpp. My original menu files are already separated the way they should be, so it's just a simple matter of integrating the menu in with the addressbook, far simpler than what I was trying to do. I asked about making a separate header for the structs, but he said they are integrated into the header so it's not necessary.

I'll have a go at this after I clean out all the stuff I've already done, and post the code for the first function, just so I can show the direction I'm heading in so you can have a look at it, but I think I have tis one figured out already.
So, without posting code that could give it away before it's due, here's what my main now looks like, from start to finish...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void func1();
void func2();
void func3();
void func4();
void func5();
void func6();
void Exit();

int main()
{
	Menu m;
	m.addMenu("1. Add A Person ", func1);
	m.addMenu("2. Get A Person " , func2);
	m.addMenu("3. Find A person By Last Name ", func3);
	m.addMenu("4. Find A person By First and Last Name ", func4);
	m.addMenu("5. Print the address book " , func5);
	m.addMenu("6. Sort by last name ", func6);
	m.addMenu("7. Exit this program ", Exit);

	m.runMenu();		
};


Everything ties into what it's supposed to, and the program runs correctly. The bonus being that my main isn't a huge mess anymore, and I am beginning to see the plus side of separate files for separate tasks. It makes it easier to work with everything.
Last edited on
All right it is looking good.

So IMO, func1 would look like this:

1
2
3
void func1() {
    NewBook.addPerson();
} 


NewBook is a private member of the Menu class, and addPerson would be similar to what I posted earlier.

This is at odds with what is written in the assignment, which gets person info in func1, whereas I have that in the addPerson function. I am thinking this is in line with my Fruit Packing Machine analogy.

I am hoping either way would be acceptable to your teacher. I think I have a valid reason for doing it my way.

Any way - here's hoping you get an A for your assignment !

Well, func1 has that in it yes, but it also has the output info to the screen as well. Kind of like what you posted five posts up, but inside of func1 and not addPerson. I didn't put it into the addressbook.cpp functions, I put them in the menu.cpp functions, since they are for the actual menu. I had thought about doing it in addressbook, but if I ever want to call something up form address book that doesn't need that info, or even needs something outputted differently, then I have to go and screw around with the function again, and the less I mess with stuff, the better it is for the program ;-)
Next lab we get rid of the global variables we were allowed to use for this assignment through the use of something called a singleton design pattern, (whatever that is). After that we dive into storing the address book info thats been inputted into some sort of external file. That's the one I'm looking forward to. I've never had a program store some sort of permanent memory before, and I'm looking forward to seeing how it's done.
For design patterns, read this:

http://www.vincehuston.org/dp/


There is also the book by the gang of four which gives a much better explanation.
I didn't put it into the addressbook.cpp functions, I put them in the menu.cpp functions, since they are for the actual menu.I had thought about doing it in addressbook, but if I ever want to call something up form address book that doesn't need that info, or even needs something outputted differently, then I have to go and screw around with the function again, and the less I mess with stuff, the better it is for the program ;-)


But there is a 1 to 1 relationship between the menu items & the functions in adressbook. Say you want to add something new, like delete person from address book - just create a menu item for it, and a corresponding addressbook function.

What do you mean by:

but if I ever want to call something up form address book that doesn't need that info, or even needs something outputted differently


Different output should be covered by different menu items with corresponding addressbook functions:

1
2
void addressbook::PrintABRawOutput();
void addressbook::PrintABFancyReport();


Member functions only get the info they need from the user.

To refer to the Fruit Packing Machine analogy again, you want to avoid putting individual Packing Machine code into the SelectPackingMachine function.

IMO the problem is that your teacher has given a slightly bad example in the assignment. Here's another good reason why I think it is misleading:

If you have another menu that uses addressbook - say one which had administrator's privileges & called functions that shouldn't be available in the ordinary user's menu, then you would have to re-write the code that gets the user input. This is code duplication - which shouldn't happen in a good design, which is why I am harping on about putting code that is to do with the addressbook in addressbook member functions. Getting input could be a private function in the addressbook class, which could be used by either menu.

Edit: Actually getting input for a person should be in a person constructor. The Person class could have 3 constructors:

1 An empty one to just create a blank Person object;
2 An interactive one that gets input from the users keyboard;
3 One that takes arguments, for use when reading info from a file.

The last one could be a set function.

It would be interesting to see what your teacher says if you were to present this argument to him / her.

The other thing is, we haven't seen any disagreement from any other members of this forum - if my advice had been even slightly wrong, usually someone would have said something. I am hoping some of the more experienced members might reply to this, with luck they might agree with what I am saying.

Sorry for being so stubborn - I just like things to be right & there is nothing worse than learning something wrong from the start.
Last edited on
Well, I've been chewing on your last post for a while now, working it all out in my head, and it makes sense to do what your saying. Doing so would allow me to make several types of address books, say for home, work, and so on, and let the user decide which one to use from main, and all I would need is just another menu.cpp type of file to carry it out, with each different one saving to a different address book, but all having the same basic menu after they choose which to use. Heck, I could probably tie them all into just the one menu.cpp file if I really think about it. It would also allow me to call up all the address books and get their info, or even post a copy of an entry to each if need be. At least, thats how I'm seeing it in my head at least.

I'll see the teacher again on Tuesday, and I will show him your last post, since you've probably described it better that I ever could, and I'll let you know what he says. It may be that we eventually get to doing just that, and he's just got us taking baby steps at the moment, who knows.
Last edited on
Topic archived. No new replies allowed.