home study engineering computer science questions and an
home / study / engineering / computer science / questions and answers / this is c. create three files to submit. contacts.h ...
Question: This is C. Create three files to submit. Contacts....
Bookmark
This is C.
Create three files to submit.
Contacts.h - Struct definition, including the data members and related function declarations
Contacts.c - Related function definitions
main.c - main() function
(2) Build the ContactNode struct per the following specifications:
Data members
char contactName[50]
char contactPhoneNum[50]
struct ContactNode* nextNodePtr
Related functions
CreateContactNode() (2 pt)
InsertContactAfter() (2 pts)
Insert a new node after node
GetNextContact() (1 pt)
Return location pointed by nextNodePtr
PrintContactNode()
 Ex. of PrintContactNode() output:
 (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:
 (4) Output the linked list. (2 pts)
 
 Ex:
Solution
/* header */
#include <iostream>
 class Contracts
 {
 public:
    int totalcount;
    Contracts(void){totalcount =0;}
    ~Contracts(void);
    struct ContractNode
    {
        char contactName[50];
        char contactPhoneNum[50];
        struct ContactNode* nextNodePtr;
       
    };
    ContractNode cont[3];
    bool CreateContactNode() ;
    bool InsertContactAfter(int position);
    ContractNode GetNextContact();
    bool PrintContactNode();
   
 };
/*cpp */
#include \"StdAfx.h\"
 #include \"Contracts.h\"
 Contracts::Contracts(void)
 {
 }
 Contracts::~Contracts(void)
 {
 }
  
    bool Contracts::CreateContactNode() {
        for (int i =0; i <3 ;i++)
        {
            std::cout << \"Enter Full name: \";
             std::cin.get( cont[i].contactName,50);
            std::cout << \"Enter phone number: \";
             std::cin.get( cont[i].contactPhoneNum,50);
        }
    }
    bool Contracts::InsertContactAfter(int position){
        if ( position==4 )
        {
            std::cout << \"Cannot inserte after 3 \";
        }
        else
        {
       for (int i =0; i <3 ;i++)
        {
            if(i==position)
            {
                    std::cout << \"Enter Full name: \";
                    std::cin.get( cont[i].contactName,50);
                    std::cout << \"Enter phone number: \";
                    std::cin.get( cont[i].contactPhoneNum,50);
            }
        }
        return true;
        }
        return false;
    }
    Contracts::ContractNode Contracts::GetNextContact(){
        switch(totalcount)
        {
            case 0:
                return cont[0];
            break;
            case 1:
                return cont[1];
            break;
            case 2:
                return cont[2];
                std::cout<< \"This is last element\"<<std::endl;
break;
       };
        totalcount ++;
    }
         bool Contracts::PrintContactNode()
        {
            std::cout<< \"CONTRACT LIST\"<<std::endl;
            for (int i =0; i <3 ;i++)
            {
                std::cout << \"Name: \"<<cont[i].contactName <<std::endl;
                std::cout << \"Name: \"<< cont[i].contactPhoneNum<<std::endl;
            }
            return true;
        }
int main ()
 {
    Contracts cont ;
    std::cout <<\"Enter 3 Persons name and Phone number\";
   
    cont.CreateContactNode();
    cont.PrintContactNode();
return 0;
 }



