This is my default screen(output):
a - Add a friend
m - Modify a friend's
p - Print list of friend's
s - Search by Last name
(a, m , p , s is what the users type to access that part of the database)
a - For my addFriend's function, I want the user to input the names into the data base by physically typing in the name
p - I want to print the names that the user input.
m - I want to be able to modify a name in the database and change the name...Lets say Roy Rogers is the name the user input... I want to go into modify and change the name to Roy Williams. The screen will now print with all names including his name changed to Roy Williams.
s - I want to be able to search the Database by using the Last name of the name.
Problems that I'm having:
1) I am having trouble printing the names that I input
2) When I type "m" for Modify, I type in the name of the person, and when it ask Enter New Name...It does not let me enter a new name.
3) In the searchfunction...When i type in the last name, it shows a blank and takes me back to the default screen.
.cpp
#include <iostream>
using namespace std;
#include "Unknown.h"
const int FRIENDS = 4;
void addFriends(friendType friends[]);
void modifyFriends(friendType friends[]);
void printFriends(friendType friends[]);
void searchbyLastName(friendType friends[]);
int main()
{
friendType friends[FRIENDS];
char selection;
do
{
cout<<"m - Modify a friend "<<endl;
cout<<"a - Add a friend "<<endl;
cout<<"p - Print friend list "<<endl;
cout<<"s - Search by Last Name "<<endl;
cout<<"q - Quit "<<endl;
cin>>selection;
switch(selection)
{
case 'm': modifyFriends(friends);
break;
case 'a': addFriends(friends);
break;
case 'p': printFriends(friends);
break;
case 's': searchbyLastName(friends);
break;
case 'q':
break;
default: cout<<"Invalid option "<<endl;
}
}
while (selection != 'q');
system("PAUSE");
return 0;
}
void addFriends (friendType friends[])
{
string name;
cout<<"Enter 5 friends names (First and Last)"<<endl;
for (int i = 0; i<FRIENDS; i++)
{
cin>>name;
}
}
void printFriends(friendType friends[])
{
for (int i=0; i<FRIENDS; i++)
{
friends[i].print();
cout<<endl;
}
}
void modifyFriends(friendType friends[])
{
string name;
string Nname;
cout<<"Enter the name you want to change"<<endl;
cin>>name;
cout<<endl;
cin>>Nname;
cout<<"Enter new name"<<endl;
for (int i=0; i<FRIENDS; i++)
{
if (friends[i].getName() == name)
friends[i].modifyFriends();
}
}
void searchbyLastName (friendType friends[])
{
string LName;
cout<<"Enter Friend's Last Name to conduct search"<<endl;
cin>>LName;
for (int i=0; i<FRIENDS; i++)
{
friends[i].printByLastName(LName);
cout<<endl;
}
}
.h file
class friendType
{
public:
void addFriends();
void modifyFriends();
void print()const;
void searchLast(string n);
void printByLastName(string n);
void modifyName(string n);
string getName();
friendType(string n);
friendType();
private:
string name;
};
void friendType::print() const
{
cout<<name<<endl;
}
friendType::friendType(string n)
{
name = n;
}
friendType::friendType()
{
name = "Unknown";
}
void friendType::addFriends()
{
}
void friendType::modifyFriends()
{
}
string friendType::getName()
{
return name;
}
void friendType::modifyName(string n)
{
name = n;
}
void friendType::printByLastName(string n)
{
if (n == name)
cout<<name<<endl;
}