(In C)
8.12 LAB: Warm up: Contacts
You will be building a linked list. Make sure to keep track of both the head and tail nodes.
(1) Create three files to submit.
(2) Build the ContactNode struct per the following specifications:
Ex. of PrintContactNode() output:
Name: Roxanne Hughes Phone number: 443-555-2864
(3) In main(), prompt the user for three contacts and output the
user's input. Create three ContactNodes and use the nodes to build
a linked list. (2 pts)
Ex:
Person 1 Enter name: Roxanne Hughes Enter phone number: 443-555-2864 You entered: Roxanne Hughes, 443-555-2864 Person 2 Enter name: Juan Alberto Jr. Enter phone number: 410-555-9385 You entered: Juan Alberto Jr., 410-555-9385 Person 3 Enter name: Rachel Phillips Enter phone number: 310-555-6610 You entered: Rachel Phillips, 310-555-6610
(4) Output the linked list. (2 pts)
Ex:
CONTACT LIST Name: Roxanne Hughes Phone number: 443-555-2864 Name: Juan Alberto Jr. Phone number: 410-555-9385 Name: Rachel Phillips Phone number: 310-555-6610
-----------------------------------------------------------------------
Given templates:
Current file: main.c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "ContactNode.h"
int main(void) {
/* Type code here */
return 0;
}
Current file: ContactNode.c
/* Type code here */
Current file: ContactNode.h
/* Type code here */
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
//main.c
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include "ContactNode.h"
int main(int argc, char* argv[])
{
ContactNode* person[3] = {NULL, NULL, NULL};
for(int i=0; i<=2; i++)
{
ContactNode temp;
printf("Person %d\n", i+1);
printf("Enter name:\n");
fgets(temp.contactName, 50, stdin);
temp.contactName[strlen(temp.contactName)-1]='\0';
printf("Enter phone number:\n");
fgets(temp.contactPhoneNum, 50, stdin);
temp.contactPhoneNum[strlen(temp.contactPhoneNum)-1]='\0';
printf("You entered: %s, %s\n\n", temp.contactName,
temp.contactPhoneNum);
person[i]=(ContactNode*)malloc(sizeof(ContactNode));
*person[i]=CreateContactNode(person[i], temp.contactName,
temp.contactPhoneNum, NULL);
}
InsertContactAfter(person[0], person[1]);
InsertContactAfter(person[1], person[2]);
printf("CONTACT LIST\n");
PrintContactNode(person[0]);
PrintContactNode(person[1]);
PrintContactNode(person[2]);
return 0;
}
//ContactNode.h
#ifndef CONTACTNODE
#define CONTACTNODE
#define NUM = 3
#include <string.h>
typedef struct ContactNode
{
char contactName[50];
char contactPhoneNum[50];
struct ContactNode* nextNodePtr;
}ContactNode;
ContactNode CreateContactNode(struct ContactNode* contact, char
name[], char number[], ContactNode* address);
void InsertContactAfter(ContactNode* contact, ContactNode*
nextcontact);
ContactNode* GetNextContact(ContactNode* contact);
void PrintContactNode(const ContactNode* contact);
#endif
//ContactNode.c
#include <stdio.h>
#include <stdlib.h>
#include "ContactNode.h"
ContactNode CreateContactNode(struct ContactNode* contact, char
name[50], char number[50], ContactNode* address)
{
strcpy(contact->contactName, name);
strcpy(contact->contactPhoneNum, number);
contact->nextNodePtr=address;
return *contact;
}
void InsertContactAfter(ContactNode* contact, ContactNode*
nextcontact)
{
ContactNode* tmpNext = NULL;
tmpNext = contact->nextNodePtr;
contact->nextNodePtr = nextcontact;
nextcontact->nextNodePtr = tmpNext;
return;
}
ContactNode* GetNextContact(ContactNode* contact)
{
return contact->nextNodePtr;
}
void PrintContactNode(const ContactNode* contact)
{
printf("Name: %s\n", contact->contactName);
// printf("Phone number: %s\n\n",
contact->contactPhoneNum);//same as above
return;
}
Kindly revert for any queries
Thanks.
(In C) 8.12 LAB: Warm up: Contacts You will be building a linked list. Make sure...
20.6 Lab: Contacts You will be building a linked list. Make sure to keep track of both the head and tail nodes (1) Create three files to submit. ContactNode.h-Class declaration ContactNode.cpp- Class definition main.cpp-main0 function (2) Build the ContactNode class per the following specifications Parameterized constructor. Parameters are name followed by phone number Public member functions InsertAfter0 (2 pts) GetName0 -Accessor(1 pt) GetPhoneNumber- Accessor (1 pt) GetNext0-Accessor (1 pt) PrintContactNode Private data members string contactName string contactPhoneNum ContactNode* nextNodePtr Ex....
Hello I need some help with my CC+ project. My current project erasing the first two phone numbers and only printing the 3rd phone number out in the list. Any idea on how to correct. Here is the error. Contacts.h #ifndef Contact_H #define Contact_H #include<string> using namespace std; class ContactNode{ public: ContactNode(); ContactNode(string name, string phone); void InsertAfter(ContactNode*); string GetName(); string GetPhoneNumber(); ContactNode* GetNext(); void PrintContactNode(); private: string contactName; string contactPhoneNum; ContactNode* nextNodePtr; }; #endif Contacts.cpp #include <iostream> #include "Contacts.h"...
Declare and define TtuStudentNode in TtuStudentNode.h and TtuStudentNode.cpp file. TtuStudentNode has its unique string variable "studentEmail" which contains email address. TtuStudentNode has its unique function member GetEmail() which returns the string variable "studentEmail". TtuStudentNode has its overriding "PrintContactNode()" which has the following definition. void TtuStudentNode::PrintContactNode() { cout << "Name: " << this->contactName << endl; cout << "Phone number: " << this->contactPhoneNum << endl; cout << "Email : " << this->studentEmail << endl; return; } ContactNode.h needs to have the function...
Ch 8 Program: Playlist (Java)You will be building a linked list. Make sure to keep track of both the head and tail nodes.(1) Create two files to submit.SongEntry.java - Class declarationPlaylist.java - Contains main() methodBuild the SongEntry class per the following specifications. Note: Some methods can initially be method stubs (empty methods), to be completed in later steps.Private fieldsString uniqueID - Initialized to "none" in default constructorstring songName - Initialized to "none" in default constructorstring artistName - Initialized to "none"...