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

Please convert this following C++ program into C. Thank you for the help Contact

ID: 3818646 • Letter: P

Question

Please convert this following C++ program into C.

Thank you for the help

Contacts.cpp

#include <iostream>
#include "Contacts.h"
using namespace std;
ContactNode::ContactNode(){
nextNodePtr=NULL;
}
ContactNode::ContactNode(string name, string phoneNum){
contactName=name;
contactPhoneNum=phoneNum;
}

void ContactNode::InsertAfter(ContactNode *nextNode){
ContactNode *temp;
if(nextNodePtr==NULL)
nextNodePtr=nextNode;
else{
temp=nextNodePtr;
while(temp!=NULL){
temp=temp->GetNext();
}
temp=nextNode;
  
}
}

string ContactNode::GetName(){
return contactName;
}

string ContactNode::GetPhoneNumber(){
return contactPhoneNum;
}

ContactNode* ContactNode::GetNext(){
return nextNodePtr;
}

void ContactNode::PrintContactNode(){
ContactNode *temp;
cout<<"Contact Name: "<<GetName()<<endl;
cout<<"Phone number: "<<GetPhoneNumber()<<endl<<endl;
if(nextNodePtr!=NULL)
GetNext()->PrintContactNode();
}

Contacts.h

#ifndef Contact_H
#define Contact_H
#include<string>
using namespace std;
class ContactNode{
public:
ContactNode(); //constructor
ContactNode(string name, string phone);
void InsertAfter(ContactNode*);
  
string GetName();
string GetPhoneNumber();
ContactNode* GetNext();
  
void PrintContactNode();
private:
string contactName;
string contactPhoneNum;
ContactNode* nextNodePtr;
};
#endif

Main.cpp

#include <iostream>
#include "Contacts.cpp"
using namespace std;

int main(){
ContactNode contactList;
string name;
string phoneNum;
for(int i=0;i<3;i++){
cout<<"Enter name: ";
cin>>name;
cout<<"Enter phone number: ";
cin>>phoneNum;
  
  
contactList.InsertAfter(new ContactNode(name,phoneNum));
}
cout<<endl<<endl<<"CONTACT LIST"<<endl<<endl;
contactList.PrintContactNode();
return 0;
}

Explanation / Answer

ContactNode();
ContactNode(string name, string phone);
void InsertAfter(ContactNode*);
  
string GetName();
string GetPhoneNumber();
ContactNode* GetNext();
  
void PrintContactNode();

Main.cpp

#include <stdio.h>
#include "Contacts.c"

int main(){
ContactNode contactList;
string name;
string phoneNum;
for(int i=0;i<3;i++){
printf("Enter name: ");
scanf("%s",&name);
printf("Enter phone number: ");
scanf("%s",&phoneNum);;
  
  
contactList.InsertAfter(new ContactNode(name,phoneNum));
}
printf(" CONTACT LIST );
contactList.PrintContactNode();
return 0;
}

Contacts.h

#ifndef Contact_H
#define Contact_H
#include<string.h>

struct ContactNode{


string contactName;
string contactPhoneNum;
ContactNode* nextNodePtr;
};
#endif

#include <stdio.h>
#include "Contacts.h"

ContactNode(){
nextNodePtr=NULL;
}
ContactNode(string name, string phoneNum){
contactName=name;
contactPhoneNum=phoneNum;
}

void InsertAfter(ContactNode *nextNode){
ContactNode *temp;
if(nextNodePtr==NULL)
nextNodePtr=nextNode;
else{
temp=nextNodePtr;
while(temp!=NULL){
temp=temp->GetNext();
}
temp=nextNode;
  
}
}

string GetName(){
return contactName;
}

string GetPhoneNumber(){
return contactPhoneNum;
}

ContactNode* GetNext(){
return nextNodePtr;
}

void PrintContactNode(){
ContactNode *temp;
printf("Contact Name");

GetName();
printf(" Phone number: ");

GetPhoneNumber();
if(nextNodePtr!=NULL)
GetNext()->PrintContactNode();
}

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