Thread: Vectors
View Single Post
Old Apr 20th, 2008, 1:12 PM   #15
White-Hat`
Programmer
 
Join Date: Sep 2005
Location: Oopland
Posts: 36
Rep Power: 0 White-Hat` is on a distinguished road
Re: Vectors

That seems to be just what I need. Although I've never used queue's, so trying to view it in terms of how I would use it for vectors is giving me some difficulty. I'll update when I get it figured out.

Edit:

Alright, first attempt. Getting several errors, some syntax but generally it's the iterator errors I'm concerned about. Any help or pointers if I'm making obvious mistakes would be helpful.

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

class CAddressBook {
private:
	string name;
	string address;
	string pn;	//phone number
	string on;	//other notes
public:
	CAddressBook();
	CAddressBook(string, string, string, string);
	~CAddressBook();
	void CABoutput(void);
};
CAddressBook::CAddressBook() {
	name = " ";
	address = " ";
	pn = " ";
	on = " ";
}
CAddressBook::CAddressBook(string a, string b, string c, string d) {
	name = a;
	address = b;
	pn = c;
	on = d;
}
CAddressBook::~CAddressBook() {
	cout << "Object destroyed";
}
void CAddressBook::CABoutput(void) {
	cout << "Name: " << name << "\nAddress: " << address << "\nPhone Number: " << pn << "\nOther Notes: " << on;
	cout << endl << endl;
}
int main() {
	size_t size = 100;
	vector<CAddressBook*> a_b(size);
	string end;
	int choose;
	int i = 0;
	cout << "Welcome to your address book!\n";
	while(end != ("quit")) {
		string name = "Jon Doe";
		string address = "None entered";
		string pn = "None entered";
		string on = "None entered";

		cout << "Would you like to...>\n1.) Enter a new entry\n2.) List current entries\n3.) Quit\n" << 
			"Please enter your choise by number.\n";
		cin >> choose;
		if (choose == 1) {
			cout << "Enter name: ";
			cin >> name;
			cout << "\nEnter address: ";
			cin >> address;
			cout << "\nEnter phone number: ";
			cin >> pn;
			cout << "\nEnter other notes: ";
			cin >> on;
			cout << endl;
			a_b[i] = new CAddressBook(name, address, pn, on);
			i++;
		}
		else if (choose == 2) {
			for (vector<string>::iterator it = a_b.begin(); it != a_b.end(); it++) {
				a_b(it)->print();
				cout << endl;
			}
		}
		else (choose == 3) {
			end = ("quit");
		}
	}
	return 0;
}

Last edited by White-Hat`; Apr 20th, 2008 at 1:40 PM.
White-Hat` is offline   Reply With Quote