Lab 9 - necessary Also make any adjustments needed for the...

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

View Full Document Right Arrow Icon
CSCI 101: Fundamentals of Computer Programming Spring 2009 Lab 9: Object Composition and Functions Object A is composed of Object B when Object B is contained in Object A, usually in the form of Object B being an attribute of Object A; and the destruction of Object A entails the destruction of Object B. For example, a Car object may be composed of an Engine object where the Engine can be an attribute of the Car and once the Car object is destroyed so is its Engine. Another example can be a Country that is composed of States. 1) Download files named states.h, state.cpp, country.h, country.cpp and countrydriver.cpp from BB to your computer and transfer them to your UNIX account. 2) Log into your UNIX account and compile and run the program. > g++ states.cpp country.cpp countrydriver.cpp 3) Open the file and review them. 4) Modify the State class to include state capitol and state abbreviation as well. Add all the necessary setters and getters, and modify other functions as
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: necessary. Also make any adjustments needed for the country to have access to state information. 5) Add functions to the driver program to allow user input data for a state, and edit the information for an existing state. (use pass by reference) Exercise 1. Create a line segment class that is composed of two objects of a point class 2. The point class has two private attributes for an x-coordinate value and a y coordinate value. (Create appropriate setters and getters for the attributes) 3. Use the two point objects to compute the length of the line segment using the distance formula: ( distance = a square of ( ( X 2 – X 1 ) 2 + (Y 2 - Y 1 ) 2 ) 4. Demonstrate these methods on at least two line segment objects. 5. Create a sum function and average function that is called in your main to compute the sum and average of the lengths of your line segment objects...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online