Lists - UAH CPE 212 Fundamentals of Software Engineering...

Info iconThis preview shows pages 1–8. 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

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: UAH CPE 212 Fundamentals of Software Engineering Agenda Class 10 List ADT • The List • Key Concepts UAH CPE 212 Last Time • Templates – Function Templates – Class Templates • Capture Behavior • Syntax Issues UAH CPE 212 This Time • Example: The List – impose order • New Concepts – switch – toupper() function in ctype.h UAH CPE 212 List Class Declaration #ifndef LIST1_H #define LIST1_H #include <stdlib.h> // Provides size_t class List { public: // TYPEDEF and MEMBER CONSTANTS enum { CAPACITY = 30 }; // Or: static const size_t CAPACITY = 30; typedef double Item; // CONSTRUCTOR List( ); // MODIFICATION MEMBER FUNCTIONS void start( ); void advance( ); void insert(const Item& entry); void attach(const Item& entry); void remove_current( ); // CONSTANT MEMBER FUNCTIONS size_t size( ) const; bool is_item( ) const; Item current( ) const; private: Item data[CAPACITY]; size_t used; size_t current_index; }; #endif UAH CPE 212 List Class Definitions What is new since the bag class? Void Start() Pre bag exists post bag is initialized void advance() pre start called post current selects next Item Item current() const //List::Item in .cxx pre is_item true post returns current item in list void insert() pre size<CAPACITY post new item inserted before current void attach() pre size<CAPACITY post new item inserted after current void remove_current() pre is item returns true post current item removed UAH CPE 212 List Class Utilization // FILE: listtest.cxx // An interactive test program for the new List ADT. #include <ctype.h> // Provides toupper #include <iostream.h> // Provides cout and cin #include <stdlib.h> // Provides EXIT_SUCCESS and size_t #include "list1.h" // With Item defined as double // PROTOTYPES for functions used by this test program: void print_menu( ); // Postcondition: A menu of choices for this program has been written to cout. char get_user_command( ); // Postcondition: The user has been prompted to enter a one character command. // The next character has been read (skipping blanks and newline characters), // and this character has been returned. void show_list(List display); // Postcondition: The items on display have been printed to cout (one per line). double get_number( ); // Postcondition: The user has been prompted to enter a real number. The // number has been read, echoed to the screen, and returned by the function. UAH CPE 212 List Utilization 2 int main( ) { List test; // A List that we'll perform tests on char choice; // A command character entered by the user cout << "I have initialized an empty List of real numbers." << endl do { print_menu( ); choice = toupper(get_user_command( )); switch (choice) { case '!': test.start( ); break; case '+': test.advance( ); break; case '?': if (test.is_item( )) cout << "There is an item." << endl; else cout << "There is no current item." << endl; break; case 'C': if (test.is_item( )) cout << "Current item is: " << test.current( ) << endl; else cout << "There is no current item." << endl;cout << "There is no current item....
View Full Document

This note was uploaded on 06/09/2008 for the course CPE 212 taught by Professor Skipper during the Spring '07 term at University of Alabama in Huntsville.

Page1 / 20

Lists - UAH CPE 212 Fundamentals of Software Engineering...

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

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