Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that allows the user to input 2 words; the characters in each word will be loaded into a sorted linked list.

Write a C++ program that allows the user to input 2 words; the characters in each word will be loaded into a sorted linked list. Use a struct containing data of char variable letter and int variable occurrences plus the pointer to the next element of the list. Letters can be used more than once in the word but appear only once in the list with the occurrences field updated. Once the lists are created use the overloaded operator + to combine the lists together into one list. Use the following main to test your code: sortedListNode list1; sortedListNode list2; sortedListNode list3; cout << Enter first word: ; cin >> word1; cout << Enter second word: ; cin >> word2; list1 = fromString(word1); //word one to list cout << Letter list from word one: << endl; printlist(list1); //print list from word one list2 = fromString(word2); //word two to list cout << Letter list from word two: << endl; printlist(list2); //print list from word two list3 = list1 + list2; //operator combines lists cout << Letter list from both words:; printlist(list3); //print combined lists operator overloading example: class Money { public: Money(); Money(int d, int c); Money(int allc); int getDollars() const; int getCents() const; ... // note: NO method for operator< private: int dollar; int cent; }; // Definition of regular, non-member functions. // m1 < m2 // note: 2 arguments and NOT a method of Money:: bool operator<(const Money & m1, const Money & m2) { int thistotal = m1.getDollars() * 100 + m1.getCents(); int m2total = m2.getDollars() * 100 + m2.getCents(); return (thistotal < m2total); } int main() { Money m1(2, 98), m2(15, 2), m3; bool ans = m1 < m2; // uses non-member function operator< }

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

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

2. Identify issues/causes for the apparent conflict.

Answered: 1 week ago