CPPNOOB 0 Newbie Poster

Hey i need help with the final assignment of my Microsoft Visual C++ class and its a hard one its an online address book where it keeps a bunch of information such as name id birthday and etc. i know it looks messy but if you copy paste into the studio it would look better i REALLY WOULD APPRECIATE any help with any part of the program .. i have most of the program done it is just some menus that i need to add to this following program and the assignment asks specifically to
1)Load the data into the address book from a file(file name is provided by the user)
2)sort the data by Last name
3)Search for a person
a. Using Id
b. Using Last name
4) print to the monitor their address, phone number, date of birth of persons name or ID
5) print the names of the people whose birthday is in given month
6)depending on users request print the names and phone numbers of all friends, family members, or business associates
7)print the names of all people between 2 given last names
8)add a new member to the address book
9) Delete a member from the address book
10) print to a file all entries of the address book in a tabular form printing name, ID, phone number and classification of the person.


**THE FILE IS STORED IN THIS ONLINE STORAGE: http://www.box.net/shared/5vg50hnzjd
orr the following messy looking code.. but it would look better once you put it in microsoft visual studio

thanks again.

//*******************************************************************
// Author: Jason Chen
//
// Program: Final Program to emulate an online address book.
//*******************************************************************
/* ID: 0414285
Programmer: Jason Chen
Course: Computer Science 1
Assignment: Final
Due Date: 10 Dec. 2008





*/

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;

struct Info_Page
{
	string first, initial, last, day_word, street, city, state, classification;
	double Id, days, zip, month, address_num;
	int year;
};

struct Info_page
{
	string name, bday, address, cityname, statezip, classes;
	double id;
};


int begin(ifstream &fin, ofstream &fout, struct Info_page &);
void getfiles(ifstream &fin, ofstream &fout, struct Info_page &);
void loopfile(ifstream &fin, ofstream &fout, struct Info_page &);
void outfile(ofstream &fout);
void memorize(ifstream &fin, ofstream &fout, struct Info_page &);
int read(struct Info_Page &);
int Write(ofstream &fout, struct Info_Page &);
void sec_main(ofstream &fout, struct Info_Page&);

void main()
{
	ifstream fin;
	ofstream fout;

	Info_Page record;
	Info_page rec;

	begin(fin, fout, rec);

	sec_main(fout, record);
}

int begin (ifstream &fin, ofstream &fout, Info_page &rec)
{
	int num;

	cout << "What would you like to do?" << endl;
	cout << "1: Get information from file." << endl;
	cout << "2: Get information from keyboard." << endl;
	cout << "3~0: Get out of program." << endl;
	cin >> num;
	cin.ignore(100, '\n');
	
	if (num == 1)
	{
		getfiles(fin, fout, rec);
	}
	else if (num == 2)
	{
		return 0;
	}
	else
	{
		cout << "Goodbye." << endl;
		exit(1);
	}
return 1;
}

void getfiles(ifstream &fin, ofstream &fout, struct Info_page &rec)
{
	string I_name, Out_name;

	cout << "Enter Input File Directory: ";
	getline(cin, I_name);

	cout << "Enter Output File Directory: ";
	getline(cin, Out_name);

	fin.open(I_name.c_str());
	if (!fin)
	{
		cout << "Bad File Name. Please choose another file.\n";
		exit(1);
	}

	fout.open(Out_name.c_str());
	if (!fout)
	{
		cout << "Bad File Name. Please choose another file.\n";
		exit(1);
	}

	loopfile(fin, fout, rec);
}

void loopfile(ifstream &fin, ofstream &fout, struct Info_page &rec)
{
	fout << "The information requested:" << endl;
	memorize(fin, fout, rec);
	while (!fin.eof())  //begin looping!!
		{
			memorize(fin, fout, rec);
		}
	fin.close();
	fout.close();
	begin(fin, fout, rec);
}

void memorize(ifstream &fin, ofstream &fout, struct Info_page &rec)
{
	getline (fin, rec.name);
	if (fin.eof())
		return ;
	fin >> rec.id;
	fin.ignore(100, '\n');
	getline (fin, rec.bday);
	getline (fin, rec.address);
	getline (fin, rec.cityname);
	getline (fin, rec.statezip);
	getline (fin, rec.classes);

	if (fin.good() == false)
	{
		cout << "Invalid data, skipping to next line.\n";
		fout << "Invalid data, skipping to next line.\n";
		fin.clear();
		fin.ignore(100,'\n');
	}
	else
	{
		fout << left << setfill(' ') << setw(30) << "\n Name: " << right << rec.name << endl;

		fout << left << setw(30) << "\n Birthday: " << right << rec.bday << endl;

		fout << left << setw(30) << "\n Id#: " << fixed << setprecision(0) << right << rec.id << endl;

		fout << left << setw(30) << "\n Address: " << right << rec.address << endl;
		fout << left << setw(29) << " " << right << rec.cityname << ", " << rec.statezip << endl;

		fout << left << setw(30) << "\n Classification: " << right << rec.classes << endl;
		fout << left << setfill('=') << setw(55) << right << "=" << endl << endl;
	}
}

void outfile(ofstream &fout)
{
	string O_name;

	cout << "Enter Output File Directory: ";
	getline(cin, O_name);

	fout.open(O_name.c_str());
	if (O_name.empty())
	{
		cout << "Bad File Name. Please choose another file.\n";
		exit(1);
	}
}

int read(struct Info_Page &record)
{
	cout << "Please enter your First Name: " << setw(30);
	getline (cin, record.first);
	if (!record.first.empty())
	{
		cout << left << setw(50) << "\n First Name: " << right << record.first;
	}
	else
	{
		cout << "\n Error occured, please recheck data." << endl;

		return 0;
	}

	cout << "\n \n Please enter your Initials: " << setw(30);
	getline (cin, record.initial);
	if (!record.initial.empty())
	{
		cout << left << setw(50) << "\n Initials: " << right << record.initial;
	}
	else
	{
		cout << "\n Error occured, please recheck data." << endl;

		return 0;
	}

	cout << "\n \n Please enter your Last Name: " << setw(30);
	getline (cin, record.last);
	if (!record.last.empty())
	{
		cout << left << setw(50) << "\n Name: " << right << record.last;
	}
	else
	{
		cout << "\n Error occured, please recheck data." << endl;

		return 0;
	}

	cout << "\n \n Please enter your Id Number: " << setw(30);
	cin >> record.Id;
	if (cin.good())
	{
		cout << left << setw(50) << "\n Id: " << fixed << setprecision(0) << right << record.Id;
	}
	else
	{
		cout << "\n Error occured, please recheck data." << endl;

		return 0;
	}

	cout << "\n \n Please enter your Date of Birth (ex. Monday, Tuesday etc.): " << setw(30);
	cin >> record.day_word;
	if (cin.good())
	{
		cout << left << setw(50) << "\n Date of Birth: " << right << record.day_word;
	}
	else
	{
		cout << "\n Error occured, please recheck data." << endl;

		return 0;
	}

	cout << "\n \n Please enter your Year of Birth: " << setw(30);
	cin >> record.year;
	if (cin.good())
	{
		cout << left << setw(50) << "\n Year of Birth: " << right << record.year;
	}
	else
	{
		cout << "\n Error occured, please recheck data." << endl;

		return 0;
	}

	if (record.year < 0 || record.year > 2008)
	{
		cout << "\nInvalid year. Please type the correct year next time." << endl;
		return 0;
	}

	cout << "\n \n Please enter your Month of Birth (number): " << setw(30);
	cin >> record.month;
	if (cin.good())
	{
		cout << left << setw(50) << "\n Month of Birth: " << right << record.month;
	}
	else
	{
		cout << "\n Error occured, please recheck data." << endl;

		return 0;
	}

	if (record.month < 1 || record.month > 12) 
	{
		cout << "\nInvalid month. Please type the correct month next time." << endl;
		return 0;
	}

	cout << "\n \n Please enter your Day of Birth (number): " << setw(30);
	cin >> record.days;
	if (cin.good())
	{
		cout << left << setw(50) << "\n Day of Birth: " << right << record.days;
	}
	else
	{
		cout << "\n Error occured, please recheck data." << endl;

		return 0;
	}

	if (record.month == 1 || record.month == 3 || record.month == 5 || record.month == 7 || record.month == 8 || record.month == 10 || record.month == 12)
	{
		if (record.days < 1 || record.days > 31)
		{
			cout << "\nInvalid day. Please type the correct day next time." << endl;
			return 0;
		}
	}
	else if (record.month == 4 || record.month == 6 || record.month == 9 || record.month == 11)
	{
		if (record.days < 1 || record.days > 30)
		{
			cout << "\nInvalid day. Please type the correct day next time." << endl;
			return 0;
		}
	}
	else if (record.month == 2)
	{
		if (record.year%4 == 0)
		{
			if (record.days < 0 || record.days > 29)
			{
				cout << "\nInvalid day. Please type the correct day next time." << endl;
				return 0;
			}
		}
		else if (record.year%4 > 0)
		{
			if (record.days < 0 || record.days > 28)
			{
				cout << "\nInvalid day. Please type the correct day next time." << endl;
				return 0;
			}
		}
	}

	cout << "\n \n Please enter your Street Address Number: " << setw(30);
	cin >> record.address_num;
	if (cin.good())
	{
		cout << left << setw(50) << "\n Street Adress Number: " << right << record.address_num;
		cin.ignore(100,'\n');
	}
	else
	{
		cout << "\n Error occured, please recheck data." << endl;

		return 0;
	}

	cout << "\n \n Please enter your Street Address: " << setw(30);
	getline (cin, record.street);
	if (!record.street.empty())
	{
		cout << left << setw(50) << "\n Address: " << right << record.street;
	}
	else
	{
		cout << "\n Error occured, please recheck data." << endl;

		return 0;
	}

	cout << "\n \n Please enter your City: " << setw(30);
	getline (cin, record.city);
	if (cin.good())
	{
		cout << left << setw(50) << "\n City: " << right << record.city;
	}
	else
	{
		cout << "\n Error occured, please recheck data." << endl;

		return 0;
	}

	cout << "\n \n Please enter your State (without periods): " << setw(30);
	cin >> record.state;
	if (cin.good())
	{
		cout << left << setw(50) << "\n State: " << right << record.state;
	}
	else
	{
		cout << "\n Error occured, please recheck data." << endl;

		return 0;
	}

	cout << "\n \n Please enter your Zip: " << setw(30);
	cin >> record.zip;
	if (cin.good())
	{
		cout << left << setw(50) << "\n Zip: " << right << record.zip;
		cin.ignore(100,'\n');
	}
	else
	{
		cout << "\n Error occured, please recheck data." << endl;

		return 0;
	}

	cout << "\n \n Please enter your Classification: " << setw(30);
	getline (cin, record.classification);
	if (!record.classification.empty())
	{
		cout << left << setw(50) << "\n Classification: " << right << record.classification << endl;
	}
	else
	{
		cout << "\n Error occured, please recheck data." << endl;

		return 0;
	}

	return 0;
}

int Write(ofstream &fout, struct Info_Page &record)
{
	fout << "The information requested:" << endl;
	fout << left << setw(30) << "\n Name: " << right << record.last << ", " << record.first << " " << record.initial << endl;

	fout << left << setw(30) << "\n Birthday: " << right << record.day_word << ", " << record.month << " " << record.days << ", " << record.year << endl;

	fout << left << setw(30) << "\n Id#: " << fixed << setprecision(0) << right << record.Id << endl;

	fout << left << setw(30) << "\n Address: " << right << record.address_num << " " << record.street << endl;
	fout << left << setw(29) << " " << right << record.city << ", " << record.state << " " << record.zip << endl;

	fout << left << setw(30) << "\n Classification: " << right << record.classification;

	fout.close();

	return 0;
}
void sec_main(ofstream &fout, struct Info_Page &record)
{
	outfile(fout);

	read(record);

	Write(fout, record);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.