Hi! please help me with my home work.
This assignment is to create a contact book so you can keep track of your friends. With this contact book you will both be able to add friends and view which friends that you have added.
Start by creating an empty list of strings called list_of_friends and make that variable global
Create a function called add_friend which will ask the user for the friend's name and append it to the list of friends
Create a second function called view_friends which will print out all the friends in the list using a range based loop
Create a third function called print_menu that prints the three options:
1: Add
2: View
3: Exit
The menu,controlled from the main function shall get user input to the variable choice to run the menu
The menu shall use a do-while loop until the user selects 3, then it should break the loop and the program will end
The print_menu shall appear after all input (placed in the beginning of the do-while loop)
If the user selects 1, it should call the add_friend-function
Else if the user selects 2, it should call the view_friends-function
No need to have check for invalid input
this is where I am so far!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <list>
using namespace std;
list <string> list_of_friends;
void add_friend()
{
string name;
cout<<"enter a name";
cin>>name;
list_of_friends.push_front(name);
}
void view_friends()
{
int i;
for(i=0; i<3; i++)
{
cout<<i;
}
}
void print_menu()
{
char ch=0;
string menu_string= "--- Select ---\n"
"1:add\n"
"2:View\n"
"3: Exit\n";
do
{
cout<<menu_string;
}
while((ch=cin.get()) !='3');
do
{
add_friend;
}
while((ch=cin.get()) =='1');
do
{
view_friends;
}
while((ch=cin.get()) =='2');
}
int main()
{
print_menu();
return 0;
}
|