Question

CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE IF POSSIBLE!!General Description: Write a program that allows the user to enter data on their friends list. The list holds a maximum of 10 friends, but may have fewer. Each friend has a name, phone number, and email address. The program first asks the user to enter the number of friends (1-10). You are not required to validate the entry, but you may if you wish. Next the program asks the user to enter the three values for the correct number of friends. For each friend, print the friend number in a message, and indent the three questions underneath that. For all three values, there may be spaces in the answer. The program then neatly prints the entire list of friends with three columns: name, phone and email. Finally, the program asks the user to enter a search name, and searches the list for a matching name. When found, the program prints the found friends name, phone and email (exactly as in the report above). When not found, the program prints Not Found! End with the standard system pause. Specifications You should declare a structure for afriend (note: friend is a reserved word in C++, so use a different name for the structure). The structure should have three members, all string: name, phone and email. The main program should declare an array of afriend structures and use them to implement the program above. Hint: since the first question (number How many friends do you hae? (1-10) 4

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;

//Declaring a structure

struct afriend

{

string name;

int phone;

string email;

};

//function declaration

bool searchFnd(afriend friends[],string search,int SIZE);

int main()

{

//Declaring variables

int SIZE;

string search;

  

//Getting the input entered by the user

cout<<"How many friends do you have? (1-10):";

cin>>SIZE;

  

// Creating array dynamically

afriend* friends = new afriend[SIZE];

  

cin.ignore();

//Getting the input entered by the user

for(int i=0;i<SIZE;i++)

{

cout<<"For Friend #"<<i<<","<<endl;

cout<<"\tEnter name:";

getline(cin,friends[i].name);

cout<<"\tEnter phone:";

cin>>friends[i].phone;

cout<<"\tEnter email:";

cin>>friends[i].email;

cin.ignore();

}

cout<<endl;

//Displaying the output

cout<<"Your Friend List:"<<endl;

for(int i=0;i<SIZE;i++)

{

cout<<setw(20)<<left<<friends[i].name<<setw(10)<<friends[i].phone<<setw(20)<<friends[i].email<<endl;

}

//Getting the input entered by the user

cout<<"\nFriend Search :"<<endl;

cout<<"Enter friend name :";

getline(cin,search);

//calling the function

int index=searchFnd(friends,search,SIZE);

if(index!=-1)

{

cout<<setw(20)<<left<<friends[index].name<<setw(10)<<friends[index].phone<<setw(20)<<friends[index].email<<endl;

}

else

{

cout<<"Not Found"<<endl;

}

return 0;

}

/* This function will check whether

* the name is found in the Structure or not

*/

bool searchFnd(afriend friends[],string search,int SIZE)

{

for(int i=0;i<SIZE;i++)

{

if(friends[i].name.compare(search)==0)

return i;

}

return -1;

}

___________________________________

Output:

CUsers Harish\Documents StructAFriendNamePhoneEmailSearch.exe How many friends do you have? <1-104 For Friend #0 Enter name Sally Sue Enter phone :8760 Enter email:ssCuky.edu For Friend #1, Enter name Freddy Friday Enter phone:9090 Enter emai l:ffCuky.edu For Friend #2, Entername:Joan Jet Enter phone :1234 Enter email:jjeuky.edu For Friend #3, Enter name Carl Carrot Enter phone 8899 Enter email:carcarCuky.edu our Friend List: Sally Sue Freddy Friday Joan Jet Carl Carrot 8760 9090 1234 8899 ssCuky.edu ffeuky.edu jjCuky.edu carcarCuky.edu Friend Search: Enter friend name Joan Jet Freddy Friday 9090 ffCuky.edu Process exited after 66.31 seconds with return value Press any key to continue _

___________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • language:python VELYIEW Design a program that you can use to keep information on your family or...

    language:python VELYIEW Design a program that you can use to keep information on your family or friends. You may view the video demonstration of the program located in this module to see how the program should function. Instructions Your program should have the following classes: Base Class - Contact (First Name, Last Name, and Phone Number) Sub Class - Family (First Name, Last Name, Phone Number, and Relationship le. cousin, uncle, aunt, etc.) Sub Class - Friends (First Name, Last...

  • Write a program **(IN C)** that displays all the phone numbers in a file that match the area code...

    Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...

  • User Profiles Write a program that reads in a series of customer information -- including name,...

    User Profiles Write a program that reads in a series of customer information -- including name, gender, phone, email and password -- from a file and stores the information in an ArrayList of User objects. Once the information has been stored, the program should welcome a user and prompt him or her for an email and password The program should then use a linearSearch method to determine whether the user whose name and password entered match those of any of...

  • I need this code in C programming. Can anyone pls help me in this? Project 8,...

    I need this code in C programming. Can anyone pls help me in this? Project 8, Program Design A hotel owner would like to maintain a list of laundry service requests by the guests. Each request was stored with the room number, the guest's first name, last name, and number of items. The program laundry_list.ccontains the struct request declaration, function prototypes, and the main function. Complete the function definitions so it uses a dynamically allocated linked list to store the...

  • Can someone please code this problem in c++? Problem 1 You are to write a C++...

    Can someone please code this problem in c++? Problem 1 You are to write a C++ program to print the following design in the output window. (Note that * is an asterisk, which is commonly found above the 8 on a standard keyboard. On different terminal types, the asterisk may be rendered differently. You need not concern yourself with the appearance of the asterisk. When I run the program, as long as you have used the correct key on the...

  • Can you help me write a Python 3.7 code for this question? Write a program using...

    Can you help me write a Python 3.7 code for this question? Write a program using functions and mainline logic which prompts the user to enter a number, then generates that number of random integers and stores them in a list. It should then display the following data to back to the user: The list of integers The lowest number in the list The highest number in the list The total sum of all the numbers in the list The...

  • THIS IS IN THE JAVA SCRIPT CODE ALSO PLEASE SEND ME THE CODE TYPED THANK YOU....

    THIS IS IN THE JAVA SCRIPT CODE ALSO PLEASE SEND ME THE CODE TYPED THANK YOU. Program 1 Write an inheritance hierarchy of three-dimensional shapes. Make a top-level shape interface that has methods for getting information such as the volume and the surface area of a three-dimensional shape. Then make classes and subclasses that implement various shapes such as cube, cylinders and spheres. Place common behavior in superclasses whenever possible, and use abstract classes as appropriate. Add methods to the...

  • Write this in a C program please. Structures on Disk The Problem Your task is to...

    Write this in a C program please. Structures on Disk The Problem Your task is to write a program that stores and retrieves structures in a file on disk. The file of structures must remain on the disk once your program ends. You should be able to store structures to the file and retrieve from the file after restarting the program. The record that you will be writing to file has the following structure: struct contact {unsigned long phone_number; long...

  • C++ programming Phone Book Create a class that can be used for a Phone Book. The...

    C++ programming Phone Book Create a class that can be used for a Phone Book. The class should have attributes for the name and phone number. The constructor should accept a name and a phone number. You should have methods that allow the name to be retrieved, the phone number to be retrieved, and one to allow the phone number to be changed. Create a toString() method to allow the name and number to be printed. Write a program that...

  • Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to...

    Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to complete a partially completed Java program. The program should either print the name and price for a coffee add-in from the Jumpin’ Jive coffee shop or it should print the message: "Sorry, we do not carry that.". Read the problem description carefully before you begin. The data file provided for this lab includes the necessary variable declarations and input statements. You need to write...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT