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

Write an application to maintain a list of friends. I need assistance with my co

ID: 675230 • Letter: W

Question

Write an application to maintain a list of friends.

I need assistance with my code since I'm a little lost as to how I should correctly write my code.

Specifications

Create a simple Friend class with, as a minimum, the following:

firstName, lastName and cellPhone fields

appropriate constructors

get/set functions

display() function - prints a friend's name and cell phone number

Create an array of Friends.

Write a program to manage your list of friends.

Run the program from a menu with the following options:

Add a Friend

Remove a Friend

Display all Friends

Exit

#include <iostream>

using namespace std;

class Friend {

public:
Friend();
Friend(string, string, string);

string GetfirstName()
{
return firstName;
}

void SetfirstName(string val)
{
firstName = val;
}

string GetLastName()
{
return lastName;
}

void setlastName(string val )
{
lastName = val;
}

};


Friend::Friend(): firstName(""), lastName(""), cellPhone("")
{


}

Friend::Friend(string fn, string ln, string cp): firstName(fn), lastName(ln), cellPhone(cp)
{

}

void Friend::display()
{

cout << firstName <<
<< lastName <<
<< cellPhone << endl;

}

const size_t SZ = 10;


void mAddFriend(array < Friend, SZ>&, int&);

void mRemoveFriend(array < Friend, SZ>&, int&);
void mDisplayFriends(const array<Friend, SZ>&, int&);
void sortMyFriendsList(array<Friend, SZ>&, int&);


int main()
{

int num = 0;
array<Friend, SZ> myFriends = {};

makeSomeFriend(myFriends, num):
cout << "num = " << num << endl;

char selection;


do{

system("cls");
cout << "Welcome to Friend List Manager "
<< "1) Add a Friend "
<< "2) "


switch(selection)

}

return 0;
}

void mAddFriend()
{
string firstName, lastName, cellPhone;
system("cls");
cout << "Add a Friend "
cout << "First Name: ";
cin >> firstName;

cout << "Last name: ";
cin >> lastName;

cout << "Cell Phone: ";
cin >> cellPhone;

friends[n++]= Friend(firstName, lastName, cellPhone);


}

void mRemoveFriend()
{
int lineNumber;

system("cls");
cout << "Remove a Friend: ";
mDisplayFriends(friends, n);

cout << "Enter line number of friend to remove: ";
cin >> lineNumber;

for(int i = lineNumber-1; i < n-1; i++)
{
friends[i] = friends[i+1];
}
n--;

cout << endl;
mDisplayFriends(friends , n);
system("PAUSE");
}

void mDisplayFriends(array<Friend SZ>&, int&)
{
sortMyFriendsList(friends, n);
for(int i = 0; i < n; i++)
{

cout << i + 1 << "";
friends[i].display();
}
cout << endl;

}


void makeSomeFriends(const array<Friend, SZ> &friends, int&n)
{
friends[n++]= Friend("Jack", "Smith", "111-111-111");
friends[n++] = Friend("Jill", "Jones", "222-222-2222");
friends[n++] = Friend(""
}

void sortMyFriendsList(const array<Friend, SZ > &friends, int&n)
{
int minIndex;
Friend otherFriend;

for(int i = 0; i<n-1; i++)
{ minIndex = i;
otherFriend = friends[minIndex];

for(int j = i+1; j < n; j++ )
{
if(friends[j].GetlastName()<otherFriend.GetlastName())
{
minIndex = j;
otherFriend = friends[j];
}
}

friends[minIndex] = friends[i];
friends[j] = otherFriend;


}

}

Explanation / Answer

package friends; import java.util.ArrayList; import java.util.Scanner; public class FriendsTest { public static void main( String[] args ) { int menu; int choice; choice = 0; Scanner input = new Scanner(System.in); ArrayList friends = new ArrayList< >(); System.out.println(" 1. Add a Friend "); System.out.println(" 2. Remove a Friend "); System.out.println(" 3. Display All Friends "); System.out.println(" 4. Exit "); menu = input.nextInt(); while(menu != 4) { switch(menu) { case 1: while(choice != 2) { System.out.println("Enter Friend's Name: "); String name = input.next(); System.out.println("Enter Friend's Age: "); int age = input.nextInt(); FriendsTest f = new FriendsTest(name, age); friends.add(f); System.out.println("Enter another? 1: Yes, 2: No"); choice = input.nextInt(); } break; case 2: System.out.println("Enter Friend's Name to Remove: "); friends.remove(input.next()); break; case 3: for(int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote