How do you use header files on a program?
I need to separate my program into header files/need to use header files for this program.Their needs to be 2-3 files one of which is the menu. thanks!
#include
#include
#include
using namespace std;
const int maxrecs = 5;
struct Teletype
{
string name;
string phoneNo;
Teletype *nextaddr;
};
void display(Teletype *);
void populate(Teletype *);
void modify(Teletype *head, string name);
void insertAtMid(Teletype *, string, string);
void deleteAtMid(Teletype *, string);
int find(Teletype *, string);
bool is_phone_no(string);
int main()
{
Teletype *list, *current;
string name;
string phoneNo;
int menu;
list = new Teletype; //new reserves space and returns the adress to the list
current = list;
for (int i = 0; i < maxrecs - 1; i++)
{
populate(current);
current->nextaddr = new Teletype;
current = current->nextaddr;
}
populate(current);
current->nextaddr = NULL;
cout << "The contents of the linked list is: " <<
endl;
display(list);
cout << "\nPlease select a number from the menu: "
<< endl;
cout << "(1)Insert new Structure on the linked list."
<< endl;
cout << "(2)Modify an existing structure in the Linked list."
<< endl;
cout << "(3)Delete an existing structure in the Linked list."
<< endl;
cout << "(4)Find an existing Structure from the Linked list."
<< endl;
cout << "(5)Exit the program." << endl;
cin >> menu;
switch (menu)
{
case 1: cout << "Enter Name and number" << endl;
cin >> name >> phoneNo;
insertAtMid(list, name, phoneNo);
cout << "The contents of the link list after inserting: "
<< endl;
display(list);
break;
case 2: cout << "\nName of the person you need to modify:
";
cin >> name;
modify(list, name);
display(list);
break;
case 3: cout << endl;
cout << "Enter Name " << endl;
cin >> name;
deleteAtMid(list, name);
cout << endl;
cout << "The contents of the linked list after deleting is: "
<< endl;
display(list);
break;
case 4: cout << endl<< endl;
cout << "Enter a name (last, first): ";
getline(cin, name); // getline because of the namespace
if (!find(list, name))
{
cout << "The name is not in the current phone list" <<
endl;
}
break;
case 5: break;
}
return 0;
}
void insertAtMid(Teletype *head, string name, string
phone)
{
Teletype *tmp = new Teletype();
tmp->name = name;
tmp->phoneNo = phone;
tmp->nextaddr = head->nextaddr;
head->nextaddr = tmp;
}
void deleteAtMid(Teletype *head, string name)
{
while (head->nextaddr != NULL)
{
if (head->nextaddr->name == name)
{
Teletype *del = head->nextaddr;
head->nextaddr = head->nextaddr->nextaddr;
delete del;
}
head = head->nextaddr;
}
}
void display(Teletype *contents)
{
while (contents != NULL)
{
cout << endl
<< setw(30) << contents->name << setw(20)
<< contents->phoneNo;
contents = contents->nextaddr;
}
}
int find(Teletype *contents, string name)
{
int found = 0;
while (contents != NULL)
{
if (contents->name == name)
{
found = 1;
cout << setw(30) << contents->name << setw(20)
<< contents->phoneNo;
break;
}
else
{
contents = contents->nextaddr;
}
}
cout << endl;
return found;
}
void modify(Teletype *head, string name)
{
string phone;
while (head->nextaddr != NULL)
{
if (head->nextaddr->name == name)
{
cout << "Enter new name and phoneNumber: ";
cin >> name >> phone;
head->nextaddr->name = name;
head->nextaddr->phoneNo = phone;
return;
}
head = head->nextaddr;
}
cout << "No suchrecord found\n";
}
bool is_phone_no(string phoneNo)
{
for (auto it = phoneNo.begin(); it != phoneNo.end(); it++)
{
if (*it > '9' || *it < '0')
return false;
}
return true;
}
void populate(Teletype *record)
{
cout << "Enter a name: ";
getline(cin, record->name);
string phoneNo;
while (true)
{
cout << "Enter the phone number: ";
getline(cin, phoneNo);
try
{
if (!is_phone_no(phoneNo))
{
throw "Exception caught! Invalid phone number\n";
}
record->phoneNo = phoneNo;
break;
}
catch (const char *e)
{
cout << e;
}
}
return;
}
In: Computer Science
Please answer method getListSize, getLast, countElement and mainly method replaceAll.
/**
* This class maintains an arbitrary length list of integers.
*
* In this version:
* 1. The size of the list is *VARIABLE* after the object is
created.
* 2. The code assumes there is at least one element in the
list.
*
* This class introduces the use of structural recursion.
*
* @author Raymond Lister
* @version May 2016
*
*/
public class ListOfNVersion03PartA
{
private int thisNumber; // the number stored in this node
private ListOfNVersion03PartA next; // forms a linked list of
objects
private final int nodeID; // a unique ID for each object in the list
private static int nodeCount = 0; // the number of list objects that have been created
/**
* @param num the value to be stored in this object
*/
public ListOfNVersion03PartA(int num)
{
thisNumber = num;
next = null;
++nodeCount;
nodeID = nodeCount;
} // constructor(int num)
/**
* @param num the multiple values to be stored in the list, in that
order
*/
public ListOfNVersion03PartA(int [] num)
{
this(num[0]); // in this context, "this" invokes the other
constructor
for (int i=1 ; i insertLast(num[i]);
} // constructor(int [] num)
/**
* @return the number of elements stored in this list
*/
public int getListSize()
{
return 999;
} // method getListSize
/**
* @return the last element in the list
*/
public int getLast()
{
return 999;
} // method getLast
/**
* prints this object
*/
public void printNode()
{
System.out.print("[" + nodeID + "," + thisNumber + "]->");
} // method printListNode
/**
* prints the tail of a list
*/
private void printListTail()
{
printNode();
if ( next != null )
next.printListTail();
} // method printListTail
/**
* prints the contents of the list, in order from first to
last
*/
public void printList()
{
printNode();
if ( next != null )
next.printListTail();
} // method printList
/**
* This method is NOT examinable in this test.
*
* prints the contents of the list, in order from first to last,
and
* then moves the cursor to the next line
*/
public void printlnList()
{
printList();
System.out.println();
} // method printlnList
/**
* @return the number of times the element occurs in the list
*
* @param element the element to be counted
*/
public int countElement(int element)
{
return 999;
} // method countElement
/**
* @return the number of times the replacement was made
*
* @param replaceThis the element to be replaced
* @param withThis the replacement
*/
public int replaceAll(int replaceThis, int withThis)
{
return 999;
} // method replaceAll
/**
* @return a reference to the first object in the list that contains
the parameter value, or null if it is not found
*
* @param findThis the value to be found
*/
public ListOfNVersion03PartA findUnSorted(int findThis)
{
// This algorithm is known as "linear search"
if ( thisNumber == findThis )
return this;
if ( next != null )
return next.findUnSorted(findThis);
return null;
} // method findUnSorted
/**
* @return the reference to the object containing the smallest
element in the list
*/
public ListOfNVersion03PartA minRef()
{
// add and/or modify code to complete the method
ListOfNVersion03PartA minOfTail;
if ( next == null )
return this;
minOfTail = next.minRef();
if ( thisNumber <= minOfTail.thisNumber )
return this;
else
return minOfTail;
} // method minRef
/**
* Inserts an element in the last position. The pre-existing
elements in the
* list are unaffected.
*
* @param newElement the element to be inserted
*/
public void insertLast(int newElement)
{
if ( next == null )
next = new ListOfNVersion03PartA(newElement);
else
next.insertLast(newElement);
} // method insertLast
/**
* Inserts an element into a sorted list. NOTE: The pre-existing
elements in the
* list are sorted and the list remains sorted (ascending
order).
*
* @param newElement the element to be inserted
*/
public void insertSorted(int newElement)
{
System.out.println("This method is NOT part of the lab
test");
System.out.println("It will probbaly be part of the
assignment");
if ( next == null )
{
// insert some code here
}
else
{
// insert some code here
}
} // method insertLast
public static void main(String[] args)
{
int [] a = {2,3,5,2};
ListOfNVersion03PartA list = new ListOfNVersion03PartA(a);
list.printlnList();
int m = list.getListSize();
System.out.println("Size is: " + m);
int n = list.getLast();
System.out.println("Last element is: " + n);
list.printlnList();
int c1 = list.countElement(2);
int c2 = list.countElement(3);
int c3 = list.countElement(4);
System.out.println("Number of elements with a value of 2 found: " +
c1);
System.out.println("Number of elements with a value of 2 found: " +
c2);
System.out.println("Number of elements with a value of 2 found: " +
c3);
int ra1 = list.replaceAll(2,1);
System.out.println("Number of replacements of value 2 with 1 is: "
+ ra1);
list.printlnList();
int ra2 = list.replaceAll(3,4);
System.out.println("Number of replacements of value 3 with 4 is: "
+ ra2);
list.printlnList();
int ra3 = list.replaceAll(7,8);
System.out.println("Number of replacements of value 7 with 8 is: "
+ ra3);
list.printlnList();
list.findUnSorted(2);
list.findUnSorted(1).printNode();
System.out.println("");
list.findUnSorted(5).printNode();
System.out.println("");
list.minRef().printNode();
System.out.println("");
list.insertLast(4);
list.printlnList();
}
} // class ListOfNVersion03PartA
In: Computer Science
Should universities require students to take physical education
classes?
Describe the advantages and disadvantages
Discuss that and give your opinion (at least two pharagrah).
In: Finance
briefly explain how essentialism in philosophy of education will influence the following:
i selection of courses
ii teaching methods
iii involvement of students in classroom
In: Nursing
Describe the relevant legislation that affects rehabilitation and return to work programs. (100–200 words)
(Students should develop a presentation and discuss this topic in class.)
In: Finance
Describe the relevant legislation that affects rehabilitation and return to work programs. (100–200 words)
(Students should develop a presentation and discuss this topic in class.)
In: Economics
(1) You are presenting to a group of high school students on the dangers of substance abuse. Describes treatment options based on theoretical models and current research
In: Psychology
Lisa needs to construct a systematic random sample of students who are currently taking statistics. Convey to her how to construct a sample, step-by-step.
In: Statistics and Probability
The subject of the report is the collapse Virgin airlines. Students should focus on two questions: • What were the main causes of the crisis? • What was the resolution of the crisis?
In: Finance
How has the Coronavirus impacted students educational lives within the university sector, discuss? please I need 1500 words on his topic
In: Economics