const int SIZE = 6; main() { String filename; ifstream input; int num; double total = 0.0; int readings = 0; int a[SIZE]; // track most recent readings for(num=0; num < SIZE; num++){ a[num] = 0; } cout << "enter file name: "; cin >> filename; input.open(filename); int period = 0; while(input >> num){ total -= a[period]; // subtract last reading a[period] = num; // store this reading total += num; // add this reading period++; readings++; if (period == SIZE){ period = 0; } if (readings >= SIZE){ cout << total << endl; } } input.close(); } void NoDupes(int a[], int & numElts) //precondition: a is sorted: a[0] <= a[1] <= ... <= a[numElts - 1] //postcondition: duplicates in a removed, a still sorted { int lastNonDup = 0; // location of last non-duplicate int k; for(k=1; k < numElts; k++){ if (a[k] != a[lastNonDup]){ lastNonDup++; // new non-dup, update position a[lastNonDup] = a[k]; // not a duplicate, store it } } numElts = lastNonDup + 1; // potentially fewer elts, update } double CartWorth(const Grocery cart[], int numItems) // precondition: numItems = # of grocery items in cart // postcondition: returns total cost of all items in cart { double total = 0.0; int k; for(k=0; k < numItems; k++){ total += cart[k].price; } return total; } void ReadCart(Grocery cart[], int & numItems, istream & input) // precondition: input open for reading // postcondition: all entries in stream stored in cart, // numItems = # items in cart { String name,price,type; numItems = 0; while(name.GetLine(input,':') && price.GetLine(input,':') && type.GetLine(input)){ cart[numItems].brandname = name; cart[numItems].price = atof(price); cart[numItems].type = StringToKind(type); } }