lab6-Q1 - //printed when list is empty } int List::Length()...

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

View Full Document Right Arrow Icon
#include<iostream> #include<fstream> using namespace std; u const int MAX_ITEMS = 20; typedef int ItemType; t class List { public: void Store(ItemType item); //Pre:The list is not full. //Post:Item is in the list. void PrintList(); //Post:If the list is not empty, the elements are printed on the screen; otherwise // "The list is empty" is printed on the screen. int Length(); //Post:Return value is the number of items in the list. bool IsEmpty(); //Post:Returns true if list is empty; false otherwise. bool IsFull(); //Post:Returns true if there is no more room in the list; false otherwise. List(); //Constructor //Post:Empty list is created. private: int length; ItemType values[MAX_ITEMS]; }; } void List::Store(ItemType x) //each new value in int.txt is added in the next space in the array { values[length] = x; length++; } void List::PrintList() //the values in the list are printed { if(length>0) { for (int index=0; index < length; index++) cout<<values[index]<<endl; } else cout<<"The list is empty."<<endl;
Background image of page 1

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

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

Unformatted text preview: //printed when list is empty } int List::Length() //gives the length of the list { return length; } bool List::IsEmpty() //checks if the list is empty or not { if(length=0) return true; else return false; } bool List::IsFull() //checks if the list is full or not { return (length==MAX_ITEMS); } List::List() //constructor, sets length equal to 0 { length = 0; } void main() { List(); List UnsortedList; //creates an instance of class List int values[MAX_ITEMS]; fstream inData; inData.open(&quot;int.txt&quot;); //opens the file to be read / for(int count=0; count&lt;MAX_ITEMS; count++) //reads in the values and { //uses Store() to store the values inData&gt;&gt;values[count]; //into an UnsortedList if(!!inData) UnsortedList.Store(values[count]); } UnsortedList.PrintList(); //prints the values stored in the list to the screen system(&quot;pause&quot;); //pauses so that a screenshot of the .exe can be taken }...
View Full Document

This note was uploaded on 04/25/2010 for the course CECS CIS 200 taught by Professor Jieshen during the Winter '08 term at University of Michigan-Dearborn.

Page1 / 2

lab6-Q1 - //printed when list is empty } int List::Length()...

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

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