// This is the test program for the extra credit portion // of Assignment 3, CS 146. The two // classes Apportioner1 and Apportioner2 are identical except // that the heap for Apportioner1 deletes the item with minimal // priority and reinserts it with a new priority, while // the heap for Apportioner2 simply moves it down in the heap. // The "process" function assumes that Apportioner1 and Apportioner2 // both inherit from a base class Apportioner. If this is not // true in your implementation, feel free to make two copies // of this function, whose first arguments are of classes // Apportioner1 in one case and Apportioner2 in the other. // Note that this argument is passed by nonconstant reference. #include "apportion.h" #include double arithmetic_mean(int n) { return n+0.5; } // This is actually off by a factor of two, // which will not affect relative priorities. double harmonic_mean(int n) { return ((double) n*(n+1))/(2*n+1); } double geometric_mean(int n) { return sqrt(n*(n+1)); } void process(Apportioner &a, int n, string infile, string outfile) { a.readInput(infile); a.apportion(n); a.printLog(n,outfile); a.printApportionment(); a.printComps(); a.clearComps(); a.clear(); } int main() { Apportioner1 a1=Apportioner1(arithmetic_mean,3); process(a1,10,"test3.txt","temp10a.txt"); a1=Apportioner1(arithmetic_mean,3); process(a1,12,"test3.txt","temp12a.txt"); a1=Apportioner1(arithmetic_mean,50); process(a1,435,"uspop.txt","temp435a.txt"); Apportioner2 a2=Apportioner2(arithmetic_mean,3); process(a2,10,"test3.txt","temp10b.txt"); a2=Apportioner2(arithmetic_mean,3); process(a2,12,"test3.txt","temp12b.txt"); a2=Apportioner2(arithmetic_mean,50); process(a2,435,"uspop.txt","temp435b.txt"); a1=Apportioner1(harmonic_mean,3); process(a1,10,"test3.txt","temp10c.txt"); a1=Apportioner1(harmonic_mean,3); process(a1,12,"test3.txt","temp12c.txt"); a1=Apportioner1(harmonic_mean,50); process(a1,435,"uspop.txt","temp435c.txt"); a2=Apportioner2(harmonic_mean,3); process(a2,10,"test3.txt","temp10d.txt"); a2=Apportioner2(harmonic_mean,3); process(a2,12,"test3.txt","temp12d.txt"); a2=Apportioner2(harmonic_mean,50); process(a2,435,"uspop.txt","temp435d.txt"); a1=Apportioner1(geometric_mean,3); process(a1,10,"test3.txt","temp10e.txt"); a1=Apportioner1(geometric_mean,3); process(a1,12,"test3.txt","temp12e.txt"); a1=Apportioner1(geometric_mean,50); process(a1,435,"uspop.txt","temp435e.txt"); a2=Apportioner2(geometric_mean,3); process(a2,10,"test3.txt","temp10f.txt"); a2=Apportioner2(geometric_mean,3); process(a2,12,"test3.txt","temp12f.txt"); a2=Apportioner2(geometric_mean,50); process(a2,435,"uspop.txt","temp435f.txt"); return 0; }