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

Week 11 webcou 3223C-18Summer CO01>Assignments > Week 11 Week 11 Submit Assignme

ID: 3919087 • Letter: W

Question

Week 11 webcou 3223C-18Summer CO01>Assignments > Week 11 Week 11 Submit Assignment Due Sunday by 11:59pm Points 100 Submitting a file upload Available Jul 16t 12am - Jul 29 at 11:59pm 14 days ments ts Create a Code Blocks project named LinkedLists. This program will use a set of data structures into which the user will enter contact information. Globally declare a Contactinfo struct Create a function that asks for contact information and places the information into a struct. Contactinfo "getContactinfol void) Call getContactinfo ten times from a for loop, and each time add the new data structure to the end of the list (use a function named addContactinfoToListl Contactinfo 'info) to add the new data structure to the list).. Write a function that displays all of the data in the list. Submit your source code to the webcourse. uide

Explanation / Answer

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts. Thanks

//Code

#include<iostream>

using namespace std;

//declaring a struct and creating a global object

struct ContactInfo{

                string firstName;

                string lastName;

                string address;

                string city;

                ContactInfo *next;

} *head;

//method to prompt the user to enter details about a contact, return a ContactInfo object

ContactInfo *getContactInfo(){

                string first,last,address,city;

                cout<<"Enter first name: ";

                cin>>first;

                cout<<"Enter last name: ";

                cin>>last;

                cin.ignore();

                cout<<"Enter address: ";

                getline(cin,address);

                cout<<"Enter city: ";

                getline(cin,city);

                ContactInfo *info=new ContactInfo();

                info->firstName=first;

                info->lastName=last;

                info->address=address;

                info->city=city;

                info->next=NULL;

                return info;

}

//method to add a new contact info to the list

void addContactInfoToList(ContactInfo *info){

                if(head==NULL){

                                //first entry

                                head=info;

                }else{

                                ContactInfo *temp=head;

                                while(temp->next!=NULL){

                                                temp=temp->next;

                                }

                                temp->next=info; //adding at the end

                }

}

//method to print details of all contacts in the list

void printContactInfo(){

                cout<<"CONTACT LIST:"<<endl;

                ContactInfo *temp=head;

                                while(temp!=NULL){

                                                cout<<"First Name: "<<temp->firstName<<endl;

                                                cout<<"Last Name: "<<temp->lastName<<endl;

                                                cout<<"Address: "<<temp->address<<endl;

                                                cout<<"City: "<<temp->city<<endl;

                                                cout<<endl;

                                                temp=temp->next;

                                }

                               

}

//method to free up memory after everything. This is used for preventing memory leaks

void releaseMemory(){

                ContactInfo *temp=head;

                                while(temp!=NULL){

                                                ContactInfo *next=temp->next;

                                                delete temp;

                                                temp=next;

                                }

}

int main(){

                //adding 10 contact info to the list

                for(int i=0;i<10;i++){

                                ContactInfo *info=getContactInfo();

                                addContactInfoToList(info);

                                cout<<endl;

                }

                //printing the contact info

                printContactInfo();

                releaseMemory();

                return 0;

}

/*OUTPUT*/

Enter first name: Oliver

Enter last name: Queen

Enter address: ABCD

Enter city: Starling City

Enter first name: Thea

Enter last name: Queen

Enter address: ABCD

Enter city: Star city

Enter first name: Barry

Enter last name: Allen

Enter address: aaaddd

Enter city: central city

Enter first name: aaa

Enter last name: bbb

Enter address: ccc

Enter city: ddd

Enter first name: John

Enter last name: Diggle

Enter address: A

Enter city: C

Enter first name: Felcity

Enter last name: Smoak

Enter address: WWW

Enter city: UUU

Enter first name: Some

Enter last name: name

Enter address: ss

Enter city: rr

Enter first name: Laurel

Enter last name: Lance

Enter address: qww

Enter city: poolys

Enter first name: WEd

Enter last name: some

Enter address: some address

Enter city: some city

Enter first name: Henry

Enter last name: Allen

Enter address: WERRE

Enter city: Central city

CONTACT LIST:

First Name: Oliver

Last Name: Queen

Address: ABCD

City: Starling City

First Name: Thea

Last Name: Queen

Address: ABCD

City: Star city

First Name: Barry

Last Name: Allen

Address: aaaddd

City: central city

First Name: aaa

Last Name: bbb

Address: ccc

City: ddd

First Name: John

Last Name: Diggle

Address: A

City: C

First Name: Felcity

Last Name: Smoak

Address: WWW

City: UUU

First Name: Some

Last Name: name

Address: ss

City: rr

First Name: Laurel

Last Name: Lance

Address: qww

City: poolys

First Name: WEd

Last Name: some

Address: some address

City: some city

First Name: Henry

Last Name: Allen

Address: WERRE

City: Central city

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