Contains the source code from the course work throughout my undergraduate Computer Engineering degree at Brigham Young University. There is a mixture of Go, Python, C, C++, Java, VHDL, Verilog, Matlab, Bash, Assembly, etc..
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.5KB

  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. #include "person.h"
  5. void display_list_of_friends(vector<person> & p) {
  6. for(unsigned int i = 0; i < p.size(); i++) {
  7. cout << p[i].name << endl;
  8. cout << "\t" << p[i].fav_food << endl;
  9. cout << "\tlist of friends: " << endl;
  10. for(unsigned int j = 0; j < p[i].friends.size(); j++) {
  11. cout << "\t\t" << p[i].friends[j] << endl;;
  12. }
  13. }
  14. }
  15. int get_person(vector<person> & p, string name) {
  16. int position = -1;
  17. for(unsigned int i = 0; i < p.size(); i++) {
  18. if(p[i].name == name) {
  19. position = i;
  20. break;
  21. }
  22. }
  23. return position;
  24. }
  25. int main() {
  26. vector<person> people;
  27. string selection;
  28. while(1) {
  29. cout << "1)add person\n2)display all people\n3)add friend\n4)remove friend" << endl;
  30. cout << "5)modify food\n6)display friends/food" << endl;
  31. cin >> selection;
  32. if(selection[0] == '1') { //optimized
  33. string name, food;
  34. cout << "what is the persons name followed by favorite food on a new line " << endl;
  35. cin.ignore();
  36. getline(cin, name);
  37. getline(cin, food);
  38. person p = person(name, food);
  39. int p1 = get_person(people, p.name);
  40. if(p1 == -1) {
  41. people.push_back(p);
  42. }
  43. }
  44. else if(selection[0] == '2') { //optimized
  45. display_list_of_friends(people);
  46. }
  47. else if(selection[0] == '3') { //optimized
  48. cout << "which relationship do you want to start (enter two names, seperated by newlines)?" << endl;
  49. string first, second;
  50. cin.ignore();
  51. getline(cin, first);
  52. getline(cin, second);
  53. int p1 = get_person(people, first);
  54. int p2 = get_person(people, second);
  55. if(p1 != -1 and p2 != -1 and first!= second) {
  56. people[p1].add_friend(second);
  57. people[p2].add_friend(first);
  58. }
  59. }
  60. else if(selection[0] == '4') { //optimized
  61. cout << "which relationship do you want to end (enter two names, seperated by newlines)?" << endl;
  62. string first, second;
  63. cin.ignore();
  64. getline(cin, first);
  65. getline(cin, second);
  66. int p1 = get_person(people, first);
  67. int p2 = get_person(people, second);
  68. if (p1 != -1 and p2 != -1) {
  69. people[p1].delete_friend(people[p2].name);
  70. people[p2].delete_friend(people[p1].name);
  71. }
  72. }
  73. else if(selection[0] == '5') { //optimized
  74. string name;
  75. cout << "what is the name of the person to whom you would like to modify fav food?" << endl;
  76. cin.ignore();
  77. getline(cin, name);
  78. int p1 = get_person(people, name);
  79. if(p1 != -1) {
  80. string new_food;
  81. cout << "what food do you want to add?" << endl;
  82. getline(cin, new_food);
  83. people[p1].modify_food(new_food);
  84. }
  85. }
  86. else if(selection[0] == '6') {
  87. cout << "What is the name of the person to whom you would like to view friends with same food?" << endl;
  88. string name;
  89. cin.ignore();
  90. getline(cin, name);
  91. int p1 = get_person(people, name);
  92. if(p1 != -1) {
  93. people[p1].display_person(people);
  94. }
  95. }
  96. else if(selection[0] == 'q') {
  97. break;
  98. }
  99. }
  100. }