# Create a Program to Implement Nodes Area in C++ Assignment Solution

July 15, 2024
Harry F.
C++
Harry F. Grimmett, with a master’s in computer science from the University of Kent, is a C++ homework helper, boasting six years of field experience.
Key Topics
• Instructions
• Requirements and Specifications
Tip of the day
News

## Instructions

Objective

Write a C++ assignment program to implement nodes area.

## Requirements and Specifications

```#include #include "area_node.h" using namespace std; #define NUM_TO_PRINT_PER_LINE 5 //----------------------------------------------------------------------- // DO NOT MODIFY THIS PRINT FUNCTION // BIG-O RUN TIME OF THIS FUNCTION: O(n) void AreaNode::print ( ) { NumberNode* temp = head; for ( int x = 0; x < size ( ) && temp != NULL; x += NUM_TO_PRINT_PER_LINE ) { cout << " " << flush; for ( int y = 0; y < NUM_TO_PRINT_PER_LINE && temp != NULL; y ++, temp = temp->next ) { cout << temp->prefix << "-" << flush << temp->suffix << ", " << flush; } cout << endl; } } //----------------------------------------------------------------------- // BIG-O RUN TIME OF THIS FUNCTION: O(n) int AreaNode::size ( ) { int count = 0; NumberNode *current = head; while (current != NULL) { count++; current = current->next; } return count; } //----------------------------------------------------------------------- // Constructor AreaNode::AreaNode(int areaCode) { this->areaCode = areaCode; next = NULL; head = NULL; } // Returns true if the areaNode list is empty, false if the list isn't empty // BIG-O: O(1) bool AreaNode::isEmpty() { return head == NULL; } // Remove a phone number from the areaNode list. // Prefix - the prefix of the number to be removed // Suffix - the suffix of the number to be removed // BIG-O: O(n) void AreaNode::removeNumber(int prefix, int suffix) { NumberNode *previous = NULL; NumberNode *current = head; while (current != NULL) { if (current->prefix == prefix && current->suffix == suffix) { if (current == head) head = head->next; else previous->next = current->next; delete current; return; } previous = current; current = current->next; } cout << "Error: Phone number does not exist" << endl; } // Insert a phone number into the areaNode list. // Prefix - the prefix of the number to be inserted // Suffix - the suffix of the number to be inserted // BIG-O: O(1) void AreaNode::insertNumber(int prefix, int suffix) { if (search(prefix, suffix) != NULL) return; NumberNode *number = new NumberNode(prefix, suffix); number->next = head; head = number; } // Search a phone number in the areaNode list. // Return the pointer to the node if the phone number is found and NULL // if the phone number is not found // Prefix - the prefix of the number to search for // Suffix - the suffix of the number to search for // BIG-O: O(n) NumberNode *AreaNode::search(int prefix, int suffix) { NumberNode *current = head; while (current != NULL) { if (current->prefix == prefix && current->suffix == suffix) return current; current = current->next; } return NULL; } // Return the total number of phone numbers that belong to a specified prefix // Prefix - the prefix in which to count phone numbers in // BIG-O: O(n) int AreaNode::numPrefixNumbers(int prefix) { int count = 0; NumberNode *current = head; while (current != NULL) { if (current->prefix == prefix) count++; current = current->next; } return count; } // Delete all number nodes // BIG-O: O(n) AreaNode::~AreaNode() { NumberNode *current = head; while (current != NULL) { NumberNode *next = current->next; delete current; current = next; } } ```