cs202 Fill Car array spr2008

cs202 Fill Car array spr2008 - tot = 0 for(k = 0 k<...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
An Array Of Objects int main() { Car Fleet[10]; //any other declaration. string myowner, mycartype; int mymileage, mypassengers, k, pos, lpos, numCars, cnt, tot; pos = 0; cout << "please enter a owner or q to quit" ; cin >> myowner; while (myowner != "q" { Fleet[pos].setOwner(myowner); cout << "please enter the car type" ; cin >> mycartype; cout << "please enter the mileage" ; cin >> mymileage; cout << "please enter the number of passengers" ; cin >> mypassengers; Fleet[pos].setcarType(mycartype); Fleet[pos].setMileage(mymileage); Fleet[pos].setPassengers(mypassengers); cout << "please enter a owner or q to quit" ; cin >> myowner; pos ++; } numCars = pos; // we could use numCars to start with and eliminate pos //13a ===================================================================== cnt = 0; for (k = 0 ; k < numCars; k++) { if (Fleet[k].getcarType() == "Buick" ) cnt++; } cout << "There are " << cnt << "buick owner(s)." << endl; //13b =====================================================================
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: tot = 0; for (k = 0 ; k < numCars; k++) { tot = tot + Fleet[k].getMileage(); } cout << "The average miles = " << tot/numCars << endl; //13c ===================================================================== lpos = 0; for (k = 0 ; k < numCars; k++) { if (Fleet[k].getMileage() > Fleet[lpos].getMileage()) lpos = k; } cout << Fleet[lpos].getOwner()<< " had the most miles with " << Fleet[lpos].getMileage() << " miles." << endl; //13d ===================================================================== for (k = 0 ; k < numCars; k++) { Fleet[k].Display(); } //13 bonus ================================================================ cout << "List of owners that can carry 4 or more passengers" << endl; cout << "==================================================" << endl; for (k = 0 ; k < numCars; k++) { if (Fleet[k].getPassengers() >= 4) cout << Fleet[k].getOwner() << endl; } return 0; }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online