Using classes, design an online address book to keep track of the names, address
ID: 669097 • Letter: U
Question
Using classes, design an online address book to keep track of the names, addresses, phone numbers, and dates of birth of family members, close friends, and certain business associates. Your program should be able to handle a maximum of 500 entries.
a. Define a class addressType that can store a street address, city, state, and ZIP code. Use the appropriate functions to print and store the address. Also, use constructors to automatically initialize the member variables.
b. Define a class extPersonType using the class personType (as defined in Example 10-10, Chapter 10), the class dateType (as designed in this chapter’s Programming Exercise 2), and the class addressType. Add a member variable to this class to classify the person as a family member, friend, or business associate. Also, add a member variable to store the phone number. Add (or override) the functions to print and store the appropriate information. Use constructors to automatically initialize the member variables.
c. Define the class addressBookType using the previously defined classes. An object of the type addressBookType should be able to process a maximum of 500 entries. The program should perform the following operations:
Load the data into the address book from a disk.
Sort the address book by last name.
Search for a person by last name.
Print the address, phone number, and date of birth (if it exists) of a given person.
Print the names of the people whose birthdays are in a given month.
Print the names of all the people between two last names.
Depending on the user’s request, print the names of all family members, friends, or business associates.
Explanation / Answer
Create a table guestbook in MYSQL
=========================
mysql> create databse guestbook;
mysql> use guestbook;
CREATE TABLE IF NOT EXISTS `guestbook` (
`name` varchar(40) DEFAULT NULL,
`location` varchar(40) DEFAULT NULL,
`email` varchar(40) DEFAULT NULL,
`url` varchar(80) DEFAULT NULL,
`comments` text
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT COMMAND
=================
INSERT INTO `guestbook` (`name`, `location`, `email`, `url`, `comments`) VALUES
('sateesh', 'seet', 'bagadhi.sateesh@gmail.com', 'http://bagadhicomputersciencetutorials.blogspot.com', 'hi');
====================
Create the following php files
1)dbconnect.php
2) create_entry.php
3)sign.php
4)view.php
code for the above files
------------------------------
1)dbconnect.php
<html>
<body>
<?php
mysql_connect("localhost", "sateesh","bagadhi") or
die ("Could not connect to database");
mysql_select_db("guestbook") or
die ("Could not select database");
?>
</body>
</html>
2)create_entry.php
<html>
<body>
<?php
include("dbconnect.php");
$submit = "Sign!";
$name=$_POST['name'];
$location=$_POST['location'];
$email=$_POST['email'];
$url=$_POST['URL'];
$comments=$_POST['comments'];
if ($submit == "Sign!")
{
$query = "insert into guestbook
(name,location,email,url,comments) values
('$name','$location','$email','$url','$comments')";
mysql_query($query) or die (mysql_error());
?>
<h2>Thanks!</h2>
<h2> <a href="view.php">View My Guest Book!</a></h2>
<?php
}
else
{
include("sign.php");
}
?>
</body>
</html>
3)sign.php
<html>
<body>
<h2>Sign my Guest Book!</h2>
<form method=post action="create_entry.php">
<b>Name :<t></t></b>
<input type=text size=40 name=name>
<br>
<b>Location :</b>
<input type=text size=40 name=location>
<br>
<b>Email :<t></t></b>
<input type=text size=40 name=email>
<br>
<B>Home page URL:</B>
<INPUT TYPE=TEXT SIZE=40 NAME=URL>
<BR>
<b>comments :<t></t></b>
<textarea name=comments cols=40 rows=10 wrap=virtual></textarea>
<br>
<input type=submit name=submit value="Sign!">
<input type=reset name=reset value="Start Over">
</form>
</body>
</html>
4)view.php
<html>
<body>
<?php include("dbconnect.php"); ?>
<h2>View My Guest Book!</h2>
<?php
$result = mysql_query ("select * from guestbook") or
die (mysql_error());
while ($row = mysql_fetch_array($result))
{
echo "<b>Name:</b>";
echo $row["name"];
echo "<br> ";
echo "<b>Location:</b>";
echo $row["location"];
echo "<br> ";
echo "<b>Email:</b>";
echo $row["email"];
echo "<br> ";
echo "<b>URL:</b>";
echo $row["url"];
echo "<br> ";
echo "<b>Comments:</b>";
echo $row["comments"];
echo "<br> ";
echo "<br> ";
echo "<br> ";
}
mysql_free_result($result);
?>
<h2> <a href="sign.php">Sign My Guest Book!</a></h2>
<body>
</html>
Save all files and run in localhost
sign.php
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.