CarranoChap3 - Carrano - CS 150 Carrano - CS 150 11 List...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Carrano - CS 150 Carrano - CS 150 11 List Abstract Data Types We have reached the point where we can customize our own versions of list types that do not encounter the problems we normally associate with traditional C++ arrays. Wed like to be able to do the following: Pass a list by value to a function! Have a function that returns a list! Assign a list a new value with an assignment statement! Insert a new element in the list at a particular location, and have the list make room for the new element! Remove an element from the list, and have the list adjust the subsequent elements so theres no gap between elements! Access a list element at a particular position without crashing if the index is inappropriate! Access the first element at position #1 and the last element at position #length! Carrano - CS 150 Carrano - CS 150 22 To Start Out: A New PhoneListing Class ///////////////////////////////////////////////////// // phoneListing.h // // The class definition for the PhoneListing class // ///////////////////////////////////////////////////// #ifndef PHONE_LISTING_H #include <iostream> #include <string> using namespace std; class PhoneListing { public: // Constructor PhoneListing(); PhoneListing(string newName, string newPhoneNumber); // Member functions void setName(string newName); void setPhoneNumber(string newPhoneNumber); // Overloaded operators PhoneListing& operator = (const PhoneListing &listing); bool operator == (PhoneListing listing); bool operator < (PhoneListing listing); bool operator <= (PhoneListing listing); bool operator > (PhoneListing listing); bool operator >= (PhoneListing listing); bool operator != (PhoneListing listing); Carrano - CS 150 Carrano - CS 150 33 phoneListing.h (Continued) // Accessor functions string getName() const; string getPhoneNumber() const; // Friend functions friend istream& operator >> (istream &sourceFileStream, PhoneListing &listing); friend ostream& operator << (ostream &destinationFileStream, const PhoneListing &listing); private: // Data members string name; string phoneNumber; }; #define PHONE_LISTING_H #endif Carrano - CS 150 Carrano - CS 150 44 phoneListing.cpp ////////////////////////////////////////////////////////// // phoneListing.cpp // // The class implementation for the PhoneListing class. // ////////////////////////////////////////////////////////// #include <iostream> #include <string> #include "phoneListing.h" using namespace std; // This default constructor sets up the data members with no values. // PhoneListing::PhoneListing() { } // This initializing constructor sets up the data members in the obvious way. // PhoneListing::PhoneListing(string newName, string newPhoneNumber) { name = newName; phoneNumber = newPhoneNumber; } // This member function sets the PhoneListing's name // // data member to the parameterized value. // void PhoneListing::setName(string newName) { name = newName; return; } Carrano -...
View Full Document

This note was uploaded on 08/26/2009 for the course CS 150 taught by Professor Klein during the Spring '08 term at Southern Illinois University Edwardsville.

Page1 / 32

CarranoChap3 - Carrano - CS 150 Carrano - CS 150 11 List...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online