EECE3326_Jan13_2014 - Joining Vectors, Object Composition, Exceptions

3 Pages
Unlock Document

Electrical and Comp Engineering
EECE 2560
Waleed Meleis

Introduction to C++ 1/13 Joining Vectors vA: C A B K vB: M D E join( vA, vB) C A B K M E template void join ( vector &vA, const vector &vB ) { int sizeB = vB.size(); for (int i=0; i < sizeB; i++) vA.push_back ( vB[i]); // vB looks like it’s an array, but the brackets [] have been defined to behave for vectors } Object Composition //fancy name for objects that contain other objects //Example: We’d like to keep track of employee’s timecards. We’ll implement a timeCard class …. private: string workerID; time24 puncInTime; // here we are composing objects, i.e. time24 object is within the timeCard class time24 punchOutTime; double payrate; bool hasPurchased // has the employee punched out? // We want to initialize a new card like this: timeCard employee (id, payrate, inHour, inMinute) // we need to write a constructor that does this timeCard::timeCard (const string &ssno, double rate, int punchInHour, int punchInMinute) : punchInTime ( punchInHour, punchInMinute) // this is the ONLY way to call the constructor of a composed object workerID (ssno), payrate (rate), hasPunched(false) {} // before the opening bracket of a constructor, all composed objects are automatically initialized. —> it therefore generates additional work if we initialize composed objects in the body of the constructor void timeCard::punchOut ( const time24 &t) { punchOutTime = t; hasPunched = true; } void timeCard::writeSalaryInfo() { if (hasPunched == false) … //error handling time24 timeWorked = punchInTime.duration ( punchOutTime ) ; double hoursWorked = timeWorked.getHour() + time
More Less

Related notes for EECE 2560

Log In


Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.