Question

Declare and define TtuStudentNode in TtuStudentNode.h and TtuStudentNode.cpp file. TtuStudentNode has its unique string variable "studentEmail" which contains email address. TtuStudentNode ha...

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 has the same name PrintContactNode (Polymorphism). So in the ContactNode.h file, PrintContactNode() member function needs to be defined as follows. Here, "virtual" needs to be placed to implement polymorphism.
virtual void PrintContactNode();

(2) Modify the main function in 24.1 of zybook, to link the three StudentNode at the end of the existing node.

  • In the main function, six ContactNode pointers should be declared as follows:
    ContactNode *headContact = 0;
    ContactNode *nextContact1 = 0;
    ContactNode *nextContact2 = 0;

    ContactNode *nextContact3 = 0;
    ContactNode *nextContact4 = 0;
    ContactNode *nextContact5 = 0;
  • In the main function, three among the six ContactNode pointer declared above need to be assigned with normal "ContactNode" objects having "name and phone number". The other three need to be assigned with "TtuStudentNode" objects having "name, phone number, and email address" as follows:
headContact = new ContactNode(fullName, phoneNum);
nextContact1 = new ContactNode(fullName, phoneNum);
nextContact2 = new ContactNode(fullName, phoneNum);

nextContact4 = new TtuStudentNode(fullName, phoneNum, email);
nextContact4 = new TtuStudentNode(fullName, phoneNum, email);
nextContact5 = new TtuStudentNode(fullName, phoneNum, email);

(3) Print the linked list which has five nodes. Print should be exactly the same as follows:

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

Name: John Smith 
Phone number: 111-222-3333
Email: [email protected]

Name: Julie Park
Phone number: 444-555-6666
Email: [email protected]

Name: Moe Xu
Phone number: 144-555-6766
Email: [email protected]

My Code so Far:

//Main.cpp

#include <iostream>
#include <string>
#include <fstream>
#include "Contacts.h"

using namespace std;

#define MAX 3

int main()
{
   //Create a link list pointer.
   ContactNode* contactList = nullptr;

   //Define the variables.
   string name;
   string phoneNum;
   string line;
   string fileName = "myoutput.txt";

   fstream file;

   file.open(fileName, ios::app);

   //Prompt the user to enter the data.
   for (int i = 0; i < MAX; i++)
   {
       cout << "\nPerson " << i + 1 << endl;
       cout << "Enter name: " << endl;
       getline(cin, name);
       cout << "Enter phone number: " << endl;
       cin >> phoneNum;
       cout << "\nYou entered: " << name << ", " << phoneNum << endl;

       file << name << "\n";
       file << phoneNum;

       if (i != MAX - 1)
           file << "\n";

       cin.ignore();
   }

   file.close();

   file.open(fileName, ios::in);

   while (!file.eof())
   {
       getline(file, name);
       getline(file, phoneNum);

       ContactNode* t;
       //Create new node and add data.
       t = new ContactNode(name, phoneNum);

       if (contactList == nullptr)
       {
           contactList = t;
       }
       //Insert the node in link list.
       else
       {
           contactList->InsertAfter(t);
       }
   }

   file.close();

   //Display the message.
   cout << endl << endl << "CONTACT LIST :" << endl << endl;
   //Call the function to display the link list data.
   contactList->PrintContactNode();

   return 0;
}

//ContactNode.h

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

//Define the default constructor.
ContactNode::ContactNode()
{
   nextNodePtr = nullptr;
}

//Define the parametrized constructor.
ContactNode::ContactNode(string name, string phoneNum)
{
   contactName = name;
   contactPhoneNum = phoneNum;
   nextNodePtr = nullptr;
}

//Define the function to insert the node.
void ContactNode::InsertAfter(ContactNode* nextNode)
{
   ContactNode* t;
   if (nextNodePtr == nullptr)
       nextNodePtr = nextNode;
   else
   {
       t = nextNodePtr;
       while (t->GetNext() != nullptr)
       {
           t = t->GetNext();
       }
       t->InsertAfter(nextNode);
   }
}

//Define the function returning name.
string ContactNode::GetName()
{
   return contactName;
}

//Define the function returning contactPhoneNum.
string ContactNode::GetPhoneNumber()
{
   return contactPhoneNum;
}

//Define the function returning nextNode.
ContactNode* ContactNode::GetNext()
{
   return nextNodePtr;
}

//Define the function to print the link list data.
void ContactNode::PrintContactNode()
{
   //Print the record of the first node.
   cout << "Name: " << GetName() << endl;
   cout << "Phone number: " << GetPhoneNumber() << endl << endl;
   ContactNode* t = GetNext();

   //Print the record of the successive nodes.
   while (t != nullptr)
   {
       cout << "Name: " << t->GetName() << endl;
       cout << "Phone number: " << t->GetPhoneNumber() << endl << endl;
       t = t->GetNext();
   }
}

//ContactNode.cpp

#ifndef Contact_H
#define Contact_H

#include<string>
using namespace std;

//Define the class.
class ContactNode
{
public:
   //Define the constructor.
   ContactNode();
   ContactNode(string name, string phone);
   //Define the function to insert the records.
   void InsertAfter(ContactNode*);
   //Define the accessor.
   string GetName();
   string GetPhoneNumber();
   ContactNode* GetNext();
   //Define the function to print the link list data.
   void PrintContactNode();
   //Define the data members.
private:
   string contactName;
   string contactPhoneNum;
   ContactNode* nextNodePtr;
};
#endif

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ContactNode.h

#ifndef Contact_H
#define Contact_H
#include<string>
using namespace std;
//Define the class.
class ContactNode
{
public:
//Define the constructor.
ContactNode();
ContactNode(string name, string phone);
//Define the function to insert the records.
void InsertAfter(ContactNode*);
//Define the accessor.
string GetName();
string GetPhoneNumber();
ContactNode* GetNext();
//Define the function to print the link list data.
virtual void PrintContactNode();
//Define the data members.
private:
string contactName;
string contactPhoneNum;
ContactNode* nextNodePtr;
};
#endif

ContactNode.cpp

#include <iostream>
#include "ContactNode.h"
using namespace std;
//Define the default constructor.
ContactNode::ContactNode()
{
nextNodePtr = nullptr;
}
//Define the parametrized constructor.
ContactNode::ContactNode(string name, string phoneNum)
{
contactName = name;
contactPhoneNum = phoneNum;
nextNodePtr = nullptr;
}
//Define the function to insert the node.
void ContactNode::InsertAfter(ContactNode* nextNode)
{
ContactNode* t;
if (nextNodePtr == nullptr)
nextNodePtr = nextNode;
else
{
t = nextNodePtr;
while (t->GetNext() != nullptr)
   {
t = t->GetNext();
}
t->InsertAfter(nextNode);
}
}
//Define the function returning name.
string ContactNode::GetName()
{
return contactName;
}
//Define the function returning contactPhoneNum.
string ContactNode::GetPhoneNumber()
{
return contactPhoneNum;
}
//Define the function returning nextNode.
ContactNode* ContactNode::GetNext()
{
return nextNodePtr;
}
//Define the function to print the link list data.
void ContactNode::PrintContactNode()
{
//Print the record of the first node.
cout << "Name: " << GetName() << endl;
cout << "Phone number: " << GetPhoneNumber() << endl << endl;
ContactNode* t = GetNext();
//Print the record of the successive nodes.
while (t != nullptr)
{
cout << "Name: " << t->GetName() << endl;
cout << "Phone number: " << t->GetPhoneNumber() << endl << endl;
t = t->GetNext();
}
}

TtuStudentNode.h

#include "ContactNode.h"

class TtuStudentNode : public ContactNode
{
   string studentEmail;
   public:
       TtuStudentNode(string name, string phone, string email);
       string GetEmail(){ return studentEmail; }
       void PrintContactNode();
};

TtuStudentNode.cpp

#include "TtuStudentNode.h"

void TtuStudentNode::PrintContactNode() {
cout << "Name: " << this->GetName() << endl;
cout << "Phone number: " << this->GetPhoneNumber() << endl;
cout << "Email : " << this->studentEmail << endl << endl;
return;
}

TtuStudentNode::TtuStudentNode(string name, string phone, string email): ContactNode(name, phone)
{
   this->studentEmail=email;
}

Main.cpp

#include <iostream>
#include <string>
#include <fstream>
#include "ContactNode.cpp"
#include "TtuStudentNode.cpp"
using namespace std;
#define MAX 3
int main()
{
   ContactNode *headContact = 0;
   ContactNode *nextContact1 = 0;
   ContactNode *nextContact2 = 0;

   ContactNode *nextContact3 = 0;
   ContactNode *nextContact4 = 0;
   ContactNode *nextContact5 = 0;
  
   headContact = new ContactNode("Roxanne Hughes", "443-555-2864");
   nextContact1 = new ContactNode("Juan Alberto Jr.", "410-555-9385");
   nextContact2 = new ContactNode("Rachel Phillips", "310-555-6610");

   nextContact3 = new TtuStudentNode("John Smith", "111-222-3333", "[email protected]");
   nextContact4 = new TtuStudentNode("Julie Park", "444-555-6666", "[email protected]");
   nextContact5 = new TtuStudentNode("Moe Xu", "144-555-6766", "[email protected]");
  
   headContact->InsertAfter(nextContact1);
   nextContact1->InsertAfter(nextContact2);
  
   headContact->PrintContactNode();
   nextContact3->PrintContactNode();
   nextContact4->PrintContactNode();
   nextContact5->PrintContactNode();
  
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Declare and define TtuStudentNode in TtuStudentNode.h and TtuStudentNode.cpp file. TtuStudentNode has its unique string variable "studentEmail" which contains email address. TtuStudentNode ha...
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
  • Hello I need some help with my CC+ project. My current project erasing the first two...

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

  • USING THIS CODE: #include <iostream> #include <string> using namespace std; class Contact { //this class cannot...

    USING THIS CODE: #include <iostream> #include <string> using namespace std; class Contact { //this class cannot be viewed from outside of the private class. //only the class functions within the class can access private members. private: string name; string email; string phone; //the public class is accessible from anywhere outside of the class //however can only be within the program. public: string getName() const { return name; } void setName(string name) { this->name = name; } string getEmail() const {...

  • //header files #ifndef Contact_H // header files should always have this to avoid #define Contact_H   ...

    //header files #ifndef Contact_H // header files should always have this to avoid #define Contact_H    // multiple inclusion in other files #include <string> // this is the only programming assignment which will use this statement. // normally "using namespace std" is looked down upon because it // introduces many common keywords that could be accidentally used, but // it identifies useful types such as string and would normally be used // std::string or std::vector. using namespace std; class Contact...

  • Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string...

    Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string +Contact()                     //default constructor sets all attribute strings to “unknown”; no other constructor +setName(string name) : void +setPhone(string pn) : void +setEmail(string em) : void +getName() : string +getPhone() : string +getEmail() : string +printContact() : void         //print out the name, phone numbers and email address Create New Project Name your project: CIS247_Lab7_YourLastName. For this exercise, you may use a header file or one file...

  • linked list operation /*************************************************************************************** This function creates a new node with the information give as a...

    linked list operation /*************************************************************************************** This function creates a new node with the information give as a parameter and looks for the right place to insert it in order to keep the list organized ****************************************************************************************/ void insertNode(string first_name, string last_name, string phoneNumber) { ContactNode *newNode; ContactNode *nodePtr; ContactNode *previousNode = nullptr; newNode = new ContactNode; /***** assign new contact info to the new node here *****/ if (!head) // head points to nullptr meaning list is empty { head = newNode;...

  • Given the following class definition in the file Classroom.h, which XXX and YYY complete the corresponding.cpp...

    Given the following class definition in the file Classroom.h, which XXX and YYY complete the corresponding.cpp file? #ifndef CLASSROOM_H #define CLASSROOM_H class Classroom public: void SetNumber(int n); void Printo const; private: int num; }; Tendif #include <iostream using namespace std; XXX void Class Room:: Set Number(int n) { nun: cout << "Number of Class Rooms: << num << endl; include "Classroom.hr vold Classroom: Print( const sinclude "Classroom.cpp" vold Classroom. Print() const #include "Classroom.h" void Class Room::Print) const #include "Classroom.cpp" void...

  • employee.h ---------- #include <stdio.h> #include <iostream> #include <fstream> class Employee { private: int employeeNum; std::string name;...

    employee.h ---------- #include <stdio.h> #include <iostream> #include <fstream> class Employee { private: int employeeNum; std::string name; std::string address; std::string phoneNum; double hrWage, hrWorked; public: Employee(int en, std::string n, std::string a, std::string pn, double hw, double hwo); std::string getName(); void setName(std::string n); int getENum(); std::string getAdd(); void setAdd(std::string a); std::string getPhone(); void setPhone(std::string p); double getWage(); void setWage(double w); double getHours(); void setHours(double h); double calcPay(double a, double b); static Employee read(std::ifstream& in); void write(std::ofstream& out); }; employee.cpp ---------- //employee.cpp #include...

  • How to turn this file into a main.cpp, a header which contains the function declaration, and...

    How to turn this file into a main.cpp, a header which contains the function declaration, and a implementation fiel containing the function definition ? #include<iostream> #include<string> #include<iomanip> using namespace std; #define NUM 1 #define MULT 4 void getPi(int iter); int main() {    int it;    cout << "Enter the number of iterations needed to find PI: ";    cin >> it;    while (it < 1) {        cout << "Error!!! Iteration input should be positive." << endl;...

  • Requirements I have already build a hpp file for the class architecture, and your job is to imple...

    Requirements I have already build a hpp file for the class architecture, and your job is to implement the specific functions. In order to prevent name conflicts, I have already declared a namespace for payment system. There will be some more details: // username should be a combination of letters and numbers and the length should be in [6,20] // correct: ["Alice1995", "Heart2you", "love2you", "5201314"] // incorrect: ["222@_@222", "12306", "abc12?"] std::string username; // password should be a combination of letters...

  • After the header, each line of the database file rebase210.txt contains the name of a restriction...

    After the header, each line of the database file rebase210.txt contains the name of a restriction enzyme and possible DNA sites the enzyme may cut (cut location is indicated by a ‘) in the following format: enzyme_acronym/recognition_sequence/…/recognition_sequence// For instance the first few lines of rebase210.txt are: AanI/TTA'TAA// AarI/CACCTGCNNNN'NNNN/'NNNNNNNNGCAGGTG// AasI/GACNNNN'NNGTC// AatII/GACGT'C// AbsI/CC'TCGAGG// AccI/GT'MKAC// AccII/CG'CG// AccIII/T'CCGGA// Acc16I/TGC'GCA// Acc36I/ACCTGCNNNN'NNNN/'NNNNNNNNGCAGGT// … That means that each line contains one enzyme acronym associated with one or more recognition sequences. For example on line 2:The enzyme acronym...

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
ADVERTISEMENT