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...

  • 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...

  • 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...

  • 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...

  • I need this done in C++ Can someone help me get my code from crashing. The...

    I need this done in C++ Can someone help me get my code from crashing. The code compiles but it can be easily crashed with user input. The rubric and code below Instructions: Write a program that scores the following data about a soccer player in a structure:            Player’s Name            Player’s Number            Points Scored by Player      The program should keep an array of 12 of these structures. Each element is for a different player on a...

  • 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...

  • Write in C++ please: Write a class named MyVector using the following UML diagram and class...

    Write in C++ please: Write a class named MyVector using the following UML diagram and class attribute descriptions. MyVector will use a linked listed instead of an array. Each Contact is a struct that will store a name and a phone number. Demonstrate your class in a program for storing Contacts. The program should present the user with a menu for adding, removing, and retrieving Contact info. MyVector Contact name: string phone: string next: Contact -head: Contact -tail: Contact -list_size:...

  • 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...

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