Important alert: (current site time 7/15/2013 5:25:50 PM EDT)
 

VB icon

A very simple address book

Email
Submitted on: 7/16/2007 12:57:34 PM
By: Rayan D. 
Level: Beginner
User Rating: By 1 Users
Compatibility: C++ (general), Microsoft Visual C++, Borland C++, UNIX C++
Views: 14334
(About the author)
 
     This a VERY simple address book. It will write a file for you and then can add contacts to the file. It also shows you your address book. Also, I want to know how to delete the contact. Can anyone help?
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :A very simple address book
//**************************************
#include <fstream>
#include <string>
#include <iostream>
#include <stdlib.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: A very simple address book
// Description:This a VERY simple address book. It will write a file for you and then can add contacts to the file. It also shows you your address book. Also, I want to know how to delete the contact. Can anyone help?
// By: Rayan D.
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=11524&lngWId=3//for details.//**************************************

#include <fstream>
#include <string>
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
	int start;
	char ch;
	int k = 0;
	int finish;
	string str1;
	string str2;
	string str3;
	string str4;
	string str5;
	string str6;
	string str7;
	string str8;
	string str9;
	string str[9];
	int i=0, j=0, last;
	ifstream myFile("addressbook.txt");
intro:
	
	cout << "Hello! If this is your first time using Rayan's Address Book, please enter 1.\n Otherwise press 2." << endl;
	cin >> start;
	{ 
		if(start==1)
		{
			ofstream myFile("addressbook.txt");
			{
				if (! myFile)
				{
					cout << "Error opening output file.\a Please make sure this file is not open during writing process." << endl;
					return -1;
				}
			}
			
			myFile.close();
			system("cls");
			cout << "A file under the name 'addressbook.txt' has been created." << endl;
				system("pause");
				system("cls");
		}
		else if(start==2)
		{
			system("cls");
			system("pause");
			goto menu;
		}
		else if(start > 1 || start < 2)
		{
			system("cls");
		cout << " NUMBER MUST BE LESS THAN 2 AND ABOVE 1. " << start << " IS NOT AN OPTION!\a\a\a\a\a" << endl;
		system("pause");
		system("cls");
		goto intro;
		}
	}
menu:
		system("cls");
		cout << " 1) Add Entry to address book" << endl;
		cout << " 2) View address book" << endl;
		cin >> start;
		{
			if (start==1)
			{
				cout << "Enter First Name" << endl;
				cin >> str1;
				cout << "Enter Last Name" << endl;
				cin >> str2;
				cout << "Enter Street Number" << endl;
				cin >> str3;
				cout << "Enter Street Name(no spaces in between name and suffix, e.g. SomeDrive)" << endl;
				cin >> str4;
				cout << "Enter town\n" << endl;
				cin >> str5;
				cout << "Enter State(abbr. e.g. CA)" << endl;
				cin >> str6;
				cout << "Enter zip-code" << endl;
				cin >> str7;
				cout << "Enter e-mail address" << endl;
				cin >> str8;
				cout << "Enter Phone Number(no spaces)" << endl;
				cin >> str9;
				ofstream myFile("addressbook.txt", ios::app);
				myFile << " " << str1 << " " << str2 << "\n " << str3 << " " << str4 << " " << str5 << " " << str6 << " " << str7 << "\n " << str8 << " " << str9 << "\n" << endl;
				myFile.close();
finish:				
				system("cls");
				cout << "To go back to the menu, press 1, to exit press 2" << endl;
				cin >> finish;
				{
					if(start == 1)
					{
						system("cls");
						goto menu;
					}
					else if(start == 2)
					{
						system("cls");
						goto end;
					}
					else
					{
						system("cls");
						cout << " Pick 1 or 2" << endl;
						system("pause");
							goto finish;
					}
				}
			}
			else if(start==2)
			{
				system("cls");
				ifstream myFile("addressbook.txt", ios::in);
				while(! myFile.eof())
				{
					if( ( i +1 ) % 4 ==0) getline(myFile, str[i++]);
					else getline(myFile, str[i++], '\t');
				}
				last = i;
				i = 0;
				while ( i < last)
				{
					cout << "Information: \n" << str[i++] << endl;
				}
				myFile.close();
				system("pause");
			}
			
			else if(start > 1 || start < 2)
			{
				system("cls");
				cout << "/a/a/aEnter a 1 or a 2/a/a/a/a/a" << endl;
				system("pause");
				system ("cls");
				goto menu;
			}
			
		}
end:
		return 0;
}


Other 7 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
6/20/2007 1:03:01 AMlinuxmigrator

if you made all of your "str" variables a "const *char" into another header file, your code would love soooo much better and can be handled better as well. But you did develop something that worked so I give you that... good job.
(If this comment was disrespectful, please report it.)

 
12/2/2007 10:16:41 PMarvind

thank you
(If this comment was disrespectful, please report it.)

 
2/18/2008 10:46:39 PMSanju

Hello, Can you pls mail me the source code in C++ "Write a program that reads text file and creates another file that is identical except that every sequence of consecutive blank space is replaced by a single space"
(If this comment was disrespectful, please report it.)

 
7/28/2008 10:39:27 AMpardeep dhingra

this code is one of the gud code
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.