Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the code for the following Business Card function // Allocates memory and initializes nodePtr->next to NULL. // Pre: None // Post: Allocated nodePtr with

Write the code for the following Business Card function

// Allocates memory and initializes nodePtr->next to NULL. // Pre: None // Post: Allocated nodePtr with ->next set to NULL. Returns NodePtr. NodePtr CreateNode();

// Adds data to an existing node // Pre: Valid NodePtr w/ allocated memory // Post: NodePtr contains valid info or set to nullptr if no info void FillNodeInfo(NodePtr);

// Prints out list // Pre: Valid nodeptr void PrintList(NodePtr);

// Inserts node into list in sorted location // Pre: Valid pointer for list and prefilled NodePtr // Post: Sorted list void InsertNode(NodePtr&, NodePtr);

program

// Program to store information read from business cards into a sorted linked list // and save out to a file. #include  #include "buscard.h" using namespace std; // Adds data to an existing node // Pre: Valid NodePtr w/ allocated memory // Post: NodePtr contains valid info or set to nullptr if no info void GetNodeInfo(NodePtr &np); // Fills in the info for a customer // Pre: Valid CustomerType variable // Post: CustomerType filled with info entered by user void FillCustomerInfo(CustomerType &cust); // Allocates memory and initializes nodePtr->next to NULL // Pre: None // Post: Allocated nodePtr with ->next set to NULL NodePtr CreateNode(); // Inserts node into list in sorted location // Pre: Valid pointer for list and prefilled NodePtr // Post: Sorted list void AddNode(NodePtr &head, NodePtr np); // Prints out list // Pre: Valid nodeptr void PrintList(NodePtr np); // Save data to file // Pre: Valid nodeptr void SaveFile(NodePtr np); // Takes a string, making the first letter uppercase and remainder lowercase // Pre: Valid string passed as argument // Post: Returns a normalized string string NormalizeString(string str); int main() { NodePtr headPtr = nullptr; // Pointer to entire list NodePtr newPtr = nullptr; // Pointer for new nodes being added // Loop until user is finished entering Business Cards newPtr = CreateNode(); GetNodeInfo(newPtr); AddNode(headPtr, newPtr); // Save File SaveFile(headPtr); return 0; } NodePtr CreateNode() { cout << "In GetNode" << endl; NodePtr newNode = new NodeType; return newNode; } void GetNodeInfo(NodePtr& np) { cout << "In GetNodeInfo" << endl; FillCustomerInfo(np->customer); } void FillCustomerInfo(CustomerType &cust){ cout << "In FillCustomerInfo" << endl; // Prompt user for info // Normalize first and last name entered cust.lastName = NormalizeString(cust.lastName); cust.firstName = NormalizeString(cust.firstName); } void AddNode(NodePtr& head, NodePtr np) { cout << "In InsertNode" << endl; } void PrintList(NodePtr np) { cout << "In PrintList" << endl; } void SaveFile(NodePtr np) { cout << "In SaveFile" << endl; } string NormalizeString(string str){ cout << "In NormalizeString" << endl; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions