Site hosted by Angelfire.com: Build your free website today!

 

Program 47
C++C++

Program 47

K. Dzwonkiewicz

Use an apvector for the following program:     

 

 

The apvector that you will use, call it pages, contains page numbers for a reading assignment.

The page numbers are in ascending order (that means increasing if you didn’t know), but may be in abbreviated form: the leading digits in a page number may be dropped if they are the same as the previous number.  For example, 413, 15, 21, 1001, 3 actually means 413, 415, 421, 1001, 1003.

 

Write a program with the function…

          Void ExpandNumbers (apvector<int>&pages)

that will read abbreviated numbers…from a file (called pro47.dat on my disk) store them to an apvector in expanded form.  The function is called to just print out the apvector with expanded numbers.

 

Sample run…

Reading the data{23,68,123,29,56,201,3,388,89,90,407,45,78,99}

Expanded to{23,68,123,129,156,201,203,388,389,390,407,445,478,499}

 

Hint:When you read, have a hold variable that is also assigned to this number.  When you do the second read, before you do the new hold, compare this read to the last hold.  If the new value is less, before you store it,…expand.

                         

 

Its not that I’m lazy,

It’s that I just don’t care.

            -Office Space