Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ (Data structure) develop a simple database system. using AVL tree as the mai

ID: 3697334 • Letter: C

Question

C++ (Data structure)

develop a simple database system.  using AVL tree as the main data structure. You are in full control of the choice of data structures (except the main data structure of AVL tree), algorithms, internal file format, and detailed user interface scheme.

Each contact information includes followings:

Unique ID number. ID is a 9 digit number

First name

Middle name (or initial)

Last name

Company name  

Home phone

Office phone

Email

Mobile number

Street address

City

State

Zip code

Country

List of affiliates (such as family members or associates name). Each affiliate has first name, and last name. They may have one individual mobile phone number and one email. Note that all affiliates will share the rest of the contact info, and you need to make sure that the shared info is not duplicated. The total number of affiliates is unknown.

Explanation / Answer

main.cpp

#include <iostream>
#include "Contact.h"
#include "bstnode.h"
#include "bstree.h"
#include "avltree.h"
#include "menu.h"

using namespace std;

int main()
{
AVLClass Recordtree;
mainmenu(Recordtree);
return 0;
}

==========================

AVLGetter.cpp


#include "AVLGetter.h"
void AVLGetter::treeSearching(BSTNodePtr ptr, vector<Contact*> &searchlist, searchBy sBy , searchType sType,string key) {
subtreeSearching(classptr->Root,searchlist,sBy,sType,key);
}
void AVLGetter::loadTree(BSTNodePtr ptr, vector<Contact*> &searchlist) {
subloadTree(classptr->Root,searchlist);
}
void AVLGetter::subloadTree(BSTNodePtr ptr,vector<Contact*> &searchlist) {
if (ptr != nullptr) {
{
searchlist.push_back(&ptr->Info);
subloadTree(ptr->Right, searchlist);
subloadTree(ptr->Left, searchlist);
}
}
}
void AVLGetter::subtreeSearching(BSTNodePtr ptr,vector<Contact*> &searchlist, searchBy sBy, searchType sType, string key) {
if (ptr != nullptr) {
{
if (ptr->Info.find(sBy, sType, key)) {
searchlist.push_back(&ptr->Info);
}
subtreeSearching(ptr->Right, searchlist, sBy, sType, key);
subtreeSearching(ptr->Left, searchlist, sBy, sType, key);
}
}
}
Contact* AVLGetter::subsearchID(BSTNodePtr Current, string id) {
{
if (Current == nullptr)
return nullptr;
else if (id == Current->Info.__ID)
return &Current->Info;
else if (id < Current->Info.__ID)
return subsearchID(Current->Left, id);
else
return subsearchID(Current->Right, id);
}
}
Contact* AVLGetter::searchID(string id) {
return subsearchID(classptr->Root,id);
}

======================================

AVLGetter.h

#ifndef DATASTRUCTFINAL_AVLGETTER_H
#define DATASTRUCTFINAL_AVLGETTER_H

#include "bstree.h"
#include "avltree.h"
#include "Contact.h"
class AVLGetter{

private:
AVLClass *classptr;
Contact* subsearchID(BSTNodePtr ptr,string);
void subtreeSearching(BSTNodePtr,vector<Contact*> &,searchBy,searchType,string);
void subloadTree(BSTNodePtr ptr,vector<Contact*> &searchlist);

public:
void treeSearching(BSTNodePtr, vector<Contact*> &,searchBy,searchType,string);
void loadTree(BSTNodePtr ptr, vector<Contact*> &searchlist);
AVLGetter(AVLClass* Record){classptr=Record;};
Contact* searchID(string);
BSTNodePtr getroot(){return classptr->Root;};
};

#endif //DATASTRUCTFINAL_AVLGETTER_H

==========================================

Affiliates.cpp

#include "Affiliates.h"
void Affiliate::setFirstname(string fname) {
__firstname=fname;
}

void Affiliate::setLastname(string lname) {
__lastname=lname;
}

void Affiliate::setPhonenumber(string tele) {
__phonenumber=tele;
}

void Affiliate::setEmail(string email) {
__email=email;
}

string Affiliate::getFirstname() {
return __firstname;
}

string Affiliate::getLastname() {
return __lastname;
}

string Affiliate::getPhonenumber() {
return __phonenumber;
}

string Affiliate::getEmail() {
return __email;
}
//**************************************************************************************************
//simple os operator<< overload to print out the contents of an affiliate
//**************************************************************************************************
ostream &operator<<(ostream &os, Affiliate aff) {
os<<aff.__firstname<<' '<<aff.__lastname<<','<<aff.__phonenumber<<','<<aff.__email<<';'<<endl;
return os;
}

========================================

Affiliate.h

#ifndef DATASTRUCTFINAL_AFFILIATES_H
#define DATASTRUCTFINAL_AFFILIATES_H

#include <iostream>

using namespace std;

class Affiliate{
string __firstname;
string __lastname;
string __phonenumber;
string __email;
public:
Affiliate(){};
//setters
void setFirstname(string);
void setLastname(string);
void setPhonenumber(string);
void setEmail(string);
//getters
string getFirstname();
string getLastname();
string getPhonenumber();
string getEmail();
friend ostream &operator<<(ostream &,Affiliate);
};

#endif //DATASTRUCTFINAL_AFFILIATES_H

===========================================

Contact.cpp

#include <algorithm>
#include <cstring>
#include "Contact.h"


//**************************************************************************************************
//setters and getters for the Contact class
//**************************************************************************************************

void Contact::setID(string ID)
{
__ID=ID;
}

void Contact::setfirstName(string fName)
{
__firstName=fName;
}

void Contact::setmiddleName(string mName)
{
__middleName=mName;
}

void Contact::setlastName(string lName)
{
__lastName=lName;
}

void Contact::setcompanyName(string cName)
{
__companyName=cName;
}

void Contact::sethomePhone(string phonenum)
{
__homePhone=phonenum;
}

void Contact::setofficePhone(string phonenum)
{
__officePhone=phonenum;
}

void Contact::setEmail(string email)
{
__email=email;
}

void Contact::setmobileNumber(string phonenum)
{
__mobileNumber=phonenum;
}

void Contact::setstreetAddress(string Addy)
{
__streetAddress=Addy;
}

void Contact::setcityName(string cName)
{
__cityName=cName;
}

void Contact::setstateName(string sName)
{
__stateName=sName;
}

void Contact::setzipCode(string zCode)
{
__zipCode=zCode;
}

void Contact::setcountryName(string cName)
{
__countryName=cName;
}

string Contact::getID()
{
return __ID;
}

string Contact::getfirstName()
{
return __firstName;
}

string Contact::getmiddleName()
{
return __middleName;
}

string Contact::getlastName()
{
return __lastName;
}

string Contact::getcompanyName()
{
return __companyName;
}

string Contact::gethomePhone()
{
return __homePhone;
}

string Contact::getofficePhone()
{
return __officePhone;
}

string Contact::getemail()
{
return __email;
}

string Contact::getmobileNumber()
{
return __mobileNumber;
}

string Contact::getstreetAddress()
{
return __streetAddress;
}

string Contact::getcityName()
{
return __cityName;
}

string Contact::getstateName()
{
return __stateName;
}

string Contact::getzipCode()
{
return __zipCode;
}

string Contact::getcountryName()
{
return __countryName;
}
//default constructor
Contact::Contact()
{
}


//**************************************************************************************************
//simple less than overide so that the AVL tree can place contacts into the tree
//**************************************************************************************************
bool operator<(Contact lhs, Contact rhs) {
double left;
double right;
left=stod(lhs.__ID.c_str());
right=stod(rhs.__ID.c_str());
if(left<right)
return true;
else
return false;
}


//**************************************************************************************************
//compares if the contacts are == based on id
//**************************************************************************************************
bool operator==(Contact lhs, Contact rhs) {
double left;
double right;
left=stod(lhs.__ID.c_str());
right=stod(rhs.__ID.c_str());
if(left<right)
return true;
else
return false;
}


//**************************************************************************************************
//find function for Contact
//takes the users input of by type and key to search the avltree and used to search the
//vector that is loaded after the first search by the user
//**************************************************************************************************
bool Contact::find(searchBy by, searchType type,string key) {
string temp;
//**************************************************************************************************
//simple if else statements.
//use of transform to make comparing user input and actual data acurate.
//if the user inputs lilian but the contacts actual name is Lilian with a capital
//allows the information to match
//use of string find function also to find if the string contains user input
//**************************************************************************************************
if(by==Allfields||by==ID){
temp=__ID;
temp.pop_back();
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
transform(key.begin(),key.end(),key.begin(),::tolower);

if(type==Exact){
if(temp==key)
return true;
}
else if(type==Contains){
if(temp.find(key)!=string::npos) //todo test
return true;
}
}
else if(by==Allfields||by==Firstname){
temp=__firstName;
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
transform(key.begin(),key.end(),key.begin(),::tolower);

if(type==Exact){
if(temp==key)
return true;
}
else if(type==Contains){
if(temp.find(key)!=string::npos) //todo test
return true;
}
}
else if(by==Allfields||by==Middlename){
temp=__middleName;
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
transform(key.begin(),key.end(),key.begin(),::tolower);

if(type==Exact){
if(temp==key)
return true;
}
else if(type==Contains){
if(temp.find(key)!=string::npos) //todo test
return true;
}
}
else if(by==Allfields||by==Lastname){
temp=__lastName;
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
transform(key.begin(),key.end(),key.begin(),::tolower);

if(type==Exact){
if(temp==key)
return true;
}
else if(type==Contains){
if(temp.find(key)!=string::npos) //todo test
return true;
}
}
else if(by==Allfields||by==Company){
temp=__companyName;
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
transform(key.begin(),key.end(),key.begin(),::tolower);

if(type==Exact){
if(temp==key)
return true;
}
else if(type==Contains){
if(temp.find(key)!=string::npos) //todo test
return true;
}
}
else if(by==Allfields||by==Homephone){
temp=__homePhone;
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
transform(key.begin(),key.end(),key.begin(),::tolower);

if(type==Exact){
if(temp==key)
return true;
}
else if(type==Contains){
if(temp.find(key)!=string::npos) //todo test
return true;
}
}
else if(by==Allfields||by==OfficePhone){
temp=__officePhone;
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
transform(key.begin(),key.end(),key.begin(),::tolower);

if(type==Exact){
if(temp==key)
return true;
}
else if(type==Contains){
if(temp.find(key)!=string::npos) //todo test
return true;
}
}
else if(by==Allfields||by==Email){
temp=__email;
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
transform(key.begin(),key.end(),key.begin(),::tolower);

if(type==Exact){
if(temp==key)
return true;
}
else if(type==Contains){
if(temp.find(key)!=string::npos) //todo test
return true;
}
}
else if(by==Allfields||by==MobileNumber){
temp=__mobileNumber;
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
transform(key.begin(),key.end(),key.begin(),::tolower);

if(type==Exact){
if(temp==key)
return true;
}
else if(type==Contains){
if(temp.find(key)!=string::npos) //todo test
return true;
}
}
else if(by==Allfields||by==Street){
temp=__streetAddress;
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
transform(key.begin(),key.end(),key.begin(),::tolower);

if(type==Exact){
if(temp==key)
return true;
}
else if(type==Contains){
if(temp.find(key)!=string::npos) //todo test
return true;
}
}
else if(by==Allfields||by==City){
temp=__cityName;
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
transform(key.begin(),key.end(),key.begin(),::tolower);

if(type==Exact){
if(temp==key)
return true;
}
else if(type==Contains){
if(temp.find(key)!=string::npos) //todo test
return true;
}
}
else if(by==Allfields||by==State){
temp=__stateName;
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
transform(key.begin(),key.end(),key.begin(),::tolower);

if(type==Exact){
if(temp==key)
return true;
}
else if(type==Contains){
if(temp.find(key)!=string::npos) //todo test
return true;
}
}
else if(by==Allfields||by==Zip){
temp=__zipCode;
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
transform(key.begin(),key.end(),key.begin(),::tolower);

if(type==Exact){
if(temp==key)
return true;
}
else if(type==Contains){
if(temp.find(key)!=string::npos) //todo test
return true;
}
}
else if(by==Allfields||by==Country){
temp=__countryName;
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
transform(key.begin(),key.end(),key.begin(),::tolower);

if(type==Exact){
if(temp==key)
return true;
}
else if(type==Contains){
if(temp.find(key)!=string::npos) //todo test
return true;
}
}
else if(by==Allfields||by==AffiliateFirstname){
for(int k=0;k<__affil.size();k++) {
temp=__affil[k].getFirstname();
transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
transform(key.begin(), key.end(), key.begin(), ::tolower);

if (type == Exact) {
if (temp == key)
return true;
}
else if (type == Contains) {
if (temp.find(key) != string::npos) //todo test
return true;
}
}
}
else if(by==Allfields||by==AffiliateLastname){
for(int k=0;k<__affil.size();k++) {
temp=__affil[k].getLastname();
transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
transform(key.begin(), key.end(), key.begin(), ::tolower);

if (type == Exact) {
if (temp == key)
return true;
}
else if (type == Contains) {
if (temp.find(key) != string::npos) //todo test
return true;
}
}
}
else if(by==Allfields||by==Affiliatephone){
for(int k=0;k<__affil.size();k++) {
temp=__affil[k].getPhonenumber();
transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
transform(key.begin(), key.end(), key.begin(), ::tolower);

if (type == Exact) {
if (temp == key)
return true;
}
else if (type == Contains) {
if (temp.find(key) != string::npos) //todo test
return true;
}
}
}
else if(by==Allfields||by==Affiliateemail){
for(int k=0;k<__affil.size();k++) {
temp=__affil[k].getEmail();
transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
transform(key.begin(), key.end(), key.begin(), ::tolower);

if (type == Exact) {
if (temp == key)
return true;
}
else if (type == Contains) {
if (temp.find(key) != string::npos) //todo test
return true;
}
}
}
return false;
}
//**************************************************************************************************
//operator<< overload
//simple os<< of the contents of a Contact.
//**************************************************************************************************
ostream &operator<<(ostream &os, Contact con) {
os<<con.getID()<<endl;
os<<con.getfirstName()<<endl;
os<<con.getmiddleName()<<endl;
os<<con.getlastName()<<endl;
os<<con.getcompanyName()<<endl;
os<<con.gethomePhone()<<endl;
os<<con.getofficePhone()<<endl;
os<<con.getemail()<<endl;
os<<con.getmobileNumber()<<endl;
os<<con.getstreetAddress()<<endl;
os<<con.getcityName()<<endl;
os<<con.getstateName()<<endl;
os<<con.getzipCode()<<endl;
os<<con.getcountryName()<<endl;
for(int k=0;k<con.__affil.size();k++){
cout<<con.__affil[k];
}
os<<'|'<<endl;
return os;
}

==========================

Contact.h


#ifndef CLUSTERING_CONTACT_H
#define CLUSTERING_CONTACT_H
#include <iostream>
#include <vector>
#include "Affiliates.h"

using namespace std;
//enum relating to the fields inside of the Contact class
//contact class consisting of private values for a contact with setters getters
enum searchBy{Allfields=1,ID,Firstname,Middlename,Lastname,Company,Homephone,OfficePhone,Email,MobileNumber,
Street,City,State,Zip,Country,AffiliateFirstname,AffiliateLastname,Affiliatephone,Affiliateemail};
enum searchType{Contains=1,Exact};
class Contact{

string __ID;
string __firstName;
string __middleName;
string __lastName;
string __companyName;
string __homePhone;
string __officePhone;
string __email;
string __mobileNumber;
string __streetAddress;
string __cityName;
string __stateName;
string __zipCode;
string __countryName;

public:
Contact();
//Setters
void setID(string);
void setfirstName(string);
void setmiddleName(string);
void setlastName(string);
void setcompanyName(string);
void sethomePhone(string);
void setofficePhone(string);
void setEmail(string);
void setmobileNumber(string);
void setstreetAddress(string);
void setcityName(string);
void setstateName(string);
void setzipCode(string);
void setcountryName(string);
//Getters
string getID();
string getfirstName();
string getmiddleName();
string getlastName();
string getcompanyName();
string gethomePhone();
string getofficePhone();
string getemail();
string getmobileNumber();
string getstreetAddress();
string getcityName();
string getstateName();
string getzipCode();
string getcountryName();
//Vector holding Affiliates.

std::vector<Affiliate> __affil;
//overloaded operator less to compare contact id numbers so the avl tree can insert them correctly and sort contacts
friend bool operator<(Contact lhs,Contact rhs);
friend bool operator==(Contact lhs,Contact rhs);
friend class AVLGetter;
//find function for searching by user arguments
bool find(searchBy by, searchType type,string key);
//overloaded os operator for contact class
friend ostream &operator<<(ostream &,Contact);
};


#endif //CLUSTERING_CONTACT_H

====================================

avlnode..cpp


#include "avlnode.h"


AVLNodeClass::AVLNodeClass(const ItemType & Item,
AVLNodeClass * LeftPtr, AVLNodeClass * RightPtr, int BalanceValue):
// call BSTNodeClass constructor, initialize field:
BSTNodeClass(Item, LeftPtr, RightPtr), Balance(BalanceValue)
{
#ifdef DEBUG
cout << "DEBUG: AVLNodeClass constructor called" << endl;
#endif
}

================================

avlnode.h

#ifndef AVLNODE_H
#define AVLNODE_H

#include "bstnode.h"


class AVLNodeClass: public BSTNodeClass
{
private:
int Balance;
public:
// constructor:
AVLNodeClass(const ItemType & Item, AVLNodeClass * LeftPtr = NULL,
AVLNodeClass * RightPtr = NULL, int BalanceValue = 0);
friend class AVLClass;
friend class AVLTableClass; // may not get to implementing this
};

typedef AVLNodeClass * AVLNodePtr;

#endif

=================================