/* Filename: showcars.cpp Author: Br. David Carlson Date: July 7, 1998 Last Revised: November 26, 2001 This program contains hardcoded data on a few individual cars. The user can repeatedly look up all cars that fit any given price range. The results of each lookup are presented on the screen. Tested with: Microsoft Visual C++ 6.0 Microsoft Visual C++ .NET g++ under Linux */ #include "cars.h" #include // for using tolower function const int MaxCars = 6; typedef Car CarArrayType[MaxCars]; /* Given: CarArray An array of Car objects. NumCars The number of cars in CarArray, from index 0 onward. Task: To ask the user for the minimum and maximum price to consider and then to print the data on all cars in the array that fit that price range. Return: Nothing. */ void Lookup(CarArrayType CarArray, int NumCars) { int k; float UpperBound, LowerBound, Price; cout << "Enter lower bound on price of cars to look at: "; cin >> LowerBound; cout << "Enter upper bound on price of cars to look at: "; cin >> UpperBound; cin.get(); // get the newline that followed the UpperBound number cout << endl; for (k = 0; k < NumCars; k++) { Price = CarArray[k].GetPrice(); if ((LowerBound <= Price) && (Price <= UpperBound)) { CarArray[k].Print(); cout << "Press ENTER to continue"; cin.get(); cout << endl; } } } int main(void) { CarArrayType CarArray; char Reply; // One can assign one object into another of the same type PROVIDED // all of the data resides inside of the object: CarArray[0] = Car("Ford Mustang", 1995, 3456.99, 2, 150); CarArray[1] = Car("Chevy Nova", 1977, 1020.88, 4, 120); CarArray[2] = Car("Chevy Blazer", 1994, 3350.99, 2, 140); CarArray[3] = Car("Toyota Camry", 1996, 6380.99, 2, 100); CarArray[4] = Car("Honda Civic", 1993, 2895.55, 2, 100); CarArray[5] = Car("Ford Bronco", 1998, 12569.99, 2, 120); do { Lookup(CarArray, MaxCars); cout << endl << "Do another lookup (y/n)? "; cin >> Reply; cout << endl; } while (tolower(Reply) == 'y'); return 0; }