240711 arrays are built into the core c vectors are

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: to the core C++; Vectors are in the standard template library. 24/07/11 14 Review ì Write a C++ function named showOdd() which accepts an array of int and outputs all odd elements. Arrays of objects 24/07/11 15 24/07/11 16 Array of objects ì Can create arrays of objects. int main () { const int NUM_CARS = 2; // Use default constructor Car myCars[NUM_CARS]; cout << myCars[0].getMake() << endl; // Call set method myCars[0].setMake("Porsche"); cout << myCars[0].getMake() << endl; // Use 1 parameter constructor. Car myCars2 = {"Ferrari", "Pinto"}; cout << myCars2[0].getMake() << endl; cout << myCars2[1].getMake() << endl; return 0; } class Car { public: Car() {make = "--none--";} Car(string newMake); void setMake(string newMake); string getMake(); }; : none...
View Full Document

This note was uploaded on 10/09/2012 for the course CMPT 125 taught by Professor Diana during the Spring '08 term at Simon Fraser.

Ask a homework question - tutors are online