Question
Write a program to maintain a database of your friends. The data to be maintained on the friends consist of first name, last name, year
Write a program to maintain a database of your friends. The data to be maintained on the friends consist of first name, last name, year of birth, month of birth, and day of birth, and sex. The data is to be stored in a linked list of struct and an object-oriented interface be provided to access the data and provide functionality. A menu-driven interface is to be provided to maintain the database. The following features will be provided: Add a friend Delete a friend by the last name Print the names ages of all friends Print information on a friend: name, age, day born (Monday, Tuesday,.,), season born Print the oldest friend Print the youngest friend Print sorted list of friends Print the average age of friends Print the list of male friends
Most of the code is already there. Applied what is needed to the existing code.
//Preprocessors #include const int MAXSIZE = 100;
//Namespace Statement using namespace std; struct friendType { string firstName; string lastName; int birthYear; int birthMonth; int birthDay; string dayBorn; string season; char sex; int age;
};
typedef list
//Object Classes class friends {
public: int searchArray(); void deleteFriend(listIt);
void printFriends(listIt); void printFriend(listIt); void printOldest(); void printYoungest(); void printAverageAge(); void printMales(); void printFemales(); void addFriend(); friends();
private: int computeAge(int bYear, int bMonth, int bDay); string computeSeason(int bMonth, int bDay); string computeDayBorn(int byear, int bmonth, int bday); void loadFile();
int selection; list
//This void function loads the file into the program. void friends::loadFile() { cout << "Loading..." << endl; ifstream infile; infile.open("friends.dat"); //size = 0; cout << "Entering while loop..." << endl;
friendType temp;
while (!infile.eof()) {
infile >> temp.firstName >> temp.lastName >> temp.birthYear >> temp.birthMonth >> temp.birthDay >> temp.sex; temp.age = computeAge(temp.birthYear, temp.birthMonth, temp.birthDay); temp.dayBorn = computeDayBorn(temp.birthYear, temp.birthMonth, temp.birthDay); temp.season = computeSeason(temp.birthMonth, temp.birthDay); //place data in the node friendsList.push_back(temp); } infile.close(); }
//This void function allows the user to add a friend. void friends::addFriend() {
}
//This void function allows the user to delete a friend. void friends::deleteFriend(friendType) { cout << "Deleting a single friend..." << endl;
friendType temp; cout << "Please enter the name "; cin >> temp.lastName; friendType.remove(temp);
}
//This void functions prints out all the friends in the file. void friends::printFriends() { cout << "Printing friends information..." << endl;
for (listIt f = friendsList.begin(); f != friendsList.end(); f++) printFriend(f);
}
//This void function allows the user to print out a friend of their choice. void friends::printFriend(listIt f) { cout << f->firstName << " " << f->lastName << " " << f->birthYear << " " << f->birthMonth << " " << f->birthDay << " " << f->sex << " " << f->age << " " << f->dayBorn << " " << f->season<< endl;
}
//This void function prints out the name of the oldest friend. void friends::printOldest() {
}
//This void function prints out the name of the youngest friend. void friends::printYoungest() {
}
//This void function prints out all female friends. void friends::printFemales() { }
int friends::computeAge(int bYear, int bMonth, int bDay) { int todayYear = 2021; int todayMonth = 02; int todayDate = 26;
int age = todayYear - bYear; if (todayMonth < bMonth) age--; if (todayMonth == bMonth && todayDate < bDay) age--; //You should prompt the user for the current year, current month and current day return age; }
string friends::computeSeason(int bMonth, int bDay) { string season = ""; if (bMonth == 1 || bMonth == 2) season = "Winter"; if (bMonth == 4 || bMonth == 5) season = "Spring"; if (bMonth == 7 || bMonth == 8) season = "Summer"; if (bMonth == 10 || bMonth == 11) season = "Fall"; if (bMonth == 3 && bDay >= 21) season = "Spring"; if (bMonth == 3 && bDay < 21) season = "Winter"; if (bMonth == 6 && bDay >= 21) season = "Summer"; if (bMonth == 6 && bDay < 21) season = "Spring"; if (bMonth == 9 && bDay >= 21) season = "Fall"; if (bMonth == 9 && bDay < 21) season = "Summer";
return season; }
string friends::computeDayBorn(int bYear, int bMonth, int bDay) { int d = bDay; int m = bMonth;
int y = bYear % 100; int c = bYear / 100; if (m == 1 || m == 2) { m += 12; y--; }
int D = (d + (m + 1) * 26 / 10 + y + y / 4 + c / 4 + 5 * c) % 7; if (D == 0) return "Saturday"; else if (D == 1)return "Sunday"; else if (D == 2)return "Monday"; else if (D == 3)return "Tuesday"; else if (D == 4)return "Wednesday"; else if (D == 5)return "Thursday"; else if (D == 6)return "Friday"; return "impossible";
}
friends::friends() {
loadFile();
} void menu(int& selection); void quit();
int main() { friends myFriends; int selection;
do { menu(selection); if (selection == 1); // myFriends.addFriend(); else if (selection == 2); //myFriends.deleteFriend(friendType); else if (selection == 3); myFriends.printFriend(listIt); else if (selection == 5) //myFriends.printOldest(); else if (selection == 6); //myFriends.printYoungest(); else if (selection == 7); //myFriends.printAverageAge(); else if (selection == 8); //myFriends.printMales(); else if (selection == 9); //myFriends.printFemales(); else if (selection == 0) quit(); else cout << "Invalid selection " << endl; } while (selection != 0);
system("pause"); return 0; } void menu(int& selection) { cout << " Welcome to My Friend Book " << endl << endl; cout << "1: Add a Friend " << endl; cout << "2: Delete a Friend " << endl; cout << "3: Print all Friends " << endl; cout << "5: Print oldest Friend" << endl; cout << "6: Print youngest Friend" << endl; cout << "7: Print average age of friends " << endl; cout << "8: Print all male friends" << endl; cout << "9: Print all female friends" << endl; cout << "0: quit" << endl; cin >> selection; }
void quit() { cout << "Bye bye " << endl; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started