Please use C++,thank you!
1.
#include <iostream>
using namespace std;
// Person class
class Person
{
private:
string Firstname, Lastname,
Fullname;
int id;
public:
//default constructors fro ibitializing the values to
empty strings and ID to 0
Person()
{
Firstname = "";
Lastname = "";
Fullname = "";
id = 0;
}
//assign the values using parameterized
constructor
Person(string fn, string ln, int
i)
{
Firstname =
fn;
Lastname =
ln;
Fullname =
Firstname + Lastname;
id = i;
}
//get Firstname
string getFirstname()
{
return
Firstname;
}
//get Lastname
string getLastname()
{
return
Lastname;
}
//get Fullname
string getFullname()
{
Fullname =
Firstname + Lastname;
return
Fullname;
}
//get id
int getId()
{
return id;
}
//set Firstname
void setFirstname(string
name)
{
Firstname = name;
}
//set Lastname
void setLastname(string name)
{
Lastname = name;
}
//set id
void setId(int x)
{
id = x;
}
//set Fullname
void setFullname()
{
Fullname = Firstname +
Lastname;
}
//printer functios to print
separate values
void printFirstname()
{
cout<<"First Name is: "<<Firstname<<endl;
}
void printLastname()
{
cout<<"Last Name is: "<<Lastname<<endl;
}
void printFullname()
{
cout<<"Full Name is: "<<Fullname<<endl;
}
void printId()
{
cout<<"ID
of person is: "<<id<<endl;
}
//display function will print all
the details
void display()
{
cout<<"First Name is:
"<<Firstname<<endl;
cout<<"Last Name is:
"<<Lastname<<endl;
cout<<"ID of person is:
"<<id<<endl;
}
};
// class AddressBook
class AddressBook
{
public:
Person pe[100]; // create an array of persons
int i=0;
//insert the persons accordingly
void insert(Person p)
{
pe[i++] = p;
}
//search using Firstname
void searchFN(string name)
{
for(int x=0;x<i;x++)
if(pe[x].getFirstname() == name)
pe[x].display();
}
//search using Lastname
void searchLN(string name)
{
for(int x=0;x<i;x++)
if(pe[x].getLastname() == name)
pe[x].display();
}
//search using id
void searchID(int I)
{
for(int x=0;x<i;x++)
if(pe[x].getId() == I)
pe[x].display();
}
//delete the persons
void deletePerson(Person p)
{
for(int x=0;x<i;x++)
{
if(pe[x].getFirstname() == p.getFirstname() &&
pe[x].getLastname() == p.getLastname() && pe[x].getId() ==
p.getId());
{
pe[x].setFirstname("");
pe[x].setLastname("");
pe[x].setId(0);
pe[x].setFullname();
break;
}
}
}
//display the AddressBook
void display()
{
for(int x=0;x<i;x++)
{
//if(pe[x].getFirstname() == "" && pe[x].getLastname() ==
"" && pe[x].getId() == 0);
//continue;
pe[x].display();
cout<<"\n";
}
}
};
int main()
{
string f,l;
int id;
Person p[5];//create an array of 5 persong to insert into
AddressBook
//get the details of the person
for(int i=0;i<5;i++)
{
cout<<"Enter First Name: ";
cin>>f;
cout<<"Enter Last Name: ";
cin>>l;
cout<<"Enter PID: ";
cin>>id;
p[i].setFirstname(f);
p[i].setLastname(l);
p[i].setId(id);
p[i].setFullname();
cout<<"\n";
}
AddressBook a;
//insert into AddressBook
for(int i=0;i<5;i++)
{
a.insert(p[i]);
}
//search using First Name
cout<<"\n Searching using First Name 'A'";
a.searchFN("A");
//search using Lastname
cout<<"\n Searching using Last Name 'F'";
a.searchLN("F");
//search using ID
cout<<"\n Searching using ID '5'";
a.searchID(5);
//display before deletion
cout<<"\n Before Deleting: \n";
a.display();
//delete first person
a.deletePerson(p[0]);
//display after deletion
cout<<"\n After Deleting: \n";
a.display();
return 0;
}
OUTPUT:
2.
#include <iostream>
using namespace std;
// Person class
class Person
{
private:
string Firstname, Lastname,
Fullname;
int id;
public:
//default constructors fro ibitializing the values to
empty strings and ID to 0
Person()
{
Firstname = "";
Lastname = "";
Fullname = "";
id = 0;
}
//assign the values using parameterized
constructor
Person(string fn, string ln, int
i)
{
Firstname =
fn;
Lastname =
ln;
Fullname =
Firstname + Lastname;
id = i;
}
//get Firstname
string getFirstname()
{
return
Firstname;
}
//get Lastname
string getLastname()
{
return
Lastname;
}
//get Fullname
string getFullname()
{
Fullname =
Firstname + Lastname;
return
Fullname;
}
//get id
int getId()
{
return id;
}
//set Firstname
void setFirstname(string
name)
{
Firstname = name;
}
//set Lastname
void setLastname(string name)
{
Lastname = name;
}
//set id
void setId(int x)
{
id = x;
}
//set Fullname
void setFullname()
{
Fullname = Firstname +
Lastname;
}
//printer functios to print
separate values
void printFirstname()
{
cout<<"First Name is: "<<Firstname<<endl;
}
void printLastname()
{
cout<<"Last Name is: "<<Lastname<<endl;
}
void printFullname()
{
cout<<"Full Name is: "<<Fullname<<endl;
}
void printId()
{
cout<<"ID
of person is: "<<id<<endl;
}
//display function will print all
the details
void display()
{
cout<<"First Name is:
"<<Firstname<<endl;
cout<<"Last Name is:
"<<Lastname<<endl;
cout<<"ID of person is:
"<<id<<endl;
}
};
int main()
{
string f,l;
int i;
cout<<"Enter First Name: ";
cin>>f;
cout<<"Enter Last Name: ";
cin>>l;
cout<<"Enter PID: ";
cin>>i;
Person p(f,l,i);
cout<<"\n";
p.printFirstname();
p.printLastname();
p.printFullname();
p.printId();
return 0;
}
Please use C++,thank you! Write an AddressBook class that manages a collection of Person objects. Use the Person class developed in question 2. An AddressBook will allow a person to add, delete, o...
C++, Visual Studio (Optional-Extra Credit) Write an AddressBook class that manages a collection of Person objects. Use the Person class developed in question Lab 4 Question 2. An AddressBook will allow a person to add, delete, or search for a Person object in the address book 1. The add method should add a person object to the address book .The delete method should remove the specified person object from the address book .The search method that searches the address book...
Create a class called AddressBook. It should be able to store a maximum of 50 names and 50 phone numbers (make an array of structures in the object or two arrays). It should contain a method called addName that will take a name and phone number and add it to the address book. There should be a method called findName that will take a string for the name and return the phone number if found in the list otherwise return...
Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...
You will design a program to keep track of a restaurants waitlist using a queue implemented with a linked list. Create a class named waitList that can store a name and number of guests. Use constructors to automatically initialize the member variables. Add the following operations to your program: Return the first person in the queue Return the last person in the queue Add a person to the queue Delete a person from the queue Create a main program to...
Requirements Create an Address Book class in Java for general use with the following behaviors: 1. Constructor: public Address Book Construct a new address book object. • A contact has four fields: first name, last name, email and phone. (There could be more information for a real contact. But these are sufficient for the assignment.) . The constructor reads from the disk to retrieve previously entered contacts. If previous contacts exist, the address book will be populated with those contacts...
Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program: Design a class named Person and its two subclasses, Student and Employee. Make Faculty and Staff subclasses of Employee. A Person object has a name, address, phone number, and email address (all Strings). A Student Object has a class status (freshman, sophomore, junior, or senior). Define the status as a final String variable. An Employee Object has an office number, salary (both ints ), and a date hired. Use...
a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the MyDate classto create an object for date hired. A faculty...
c++ programming language Instructions In this exercise, you will design the class memberType. Each object of memberType can hold the name of a person, member ID, number of books bought, and amount spent. Include the member functions to perform the various operations on the objects of memberType—for example, modify, set, and show a person’s name. Similarly, up-date, modify, and show the number of books bought and the amount spent. Add the appropriate constructors. Write the definitions of the member functions...
Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person and Student represent individuals with a first and last name as String class variables, and Student has an additional int class variable that represents a ID number. The Roster class represents a group of people that are objects of either the Person or Student class. It contains an ArrayList. The Person class has been completed for you with class variables, a constructor, and a...
Exercise 1: Adding a Test Harness to the Person class To make it easier to test code that you have written for a Java class you can add to that class a main method that acts as a "test harness". A test harness is a main method that includes calls to methods that you wish to test. For convention this main method is the last method of the class. If you have a test harness, you do not need to...