icon

Usetutoringspotscode to get 8% OFF on your first order!

Programming

Programming Problem

Write the program described in questions 29 and 30 at the end of chapter 8 in the textbook (page 565 in the 7th Ed, page 584 in 8th Ed.) (7th edition textbook attached) But, use an array of pointersto Car objects.

Additional instructions and hints: Initialize the first thee Car objects using the overloaded constructor. Avoid memory leaks (use delete on all fobjects you create with new.) Use good programming style: Use named constants where appropriate. Initialize all pointers to NULL. Write explanatory comments where appropriate. Indent code consistently . Use appropriate casing (camelCase, PascalCase, UPPER_CASE.) Write the entire program in a single file. Don’t include user input.

Questions 29 and 30

(modified from the textbook version)

Use the following Car class declaration with questions 29 & 30. You will need to add getters to get the values for the three member variables.

class Car { string make, model; int year; double cost;

Constructors Car() { make = model = ; year = cost = 0; } Car( string mk, string md, int yr, double c) { make = mk; model = md; year = yr; cost = c;}

Getters To Do you need to add these };

29. Define an array named forSale that holds 35 Car objects. Initialize the objects in the first three elements with the data below. The rest of the elements should contain NULL pointers. Make Model Year Cost Ford Taurus 2006 $18,000 Honda Accord 2004 $8,000 Jeep Wrangler 2007 $21,000

30. Write a loop that will step through the array you defined in question 29, displaying the contents of each element that doesn’t contain a NULL pointer.

You can leave a response, or trackback from your own site.

Leave a Reply

Powered by WordPress | Designed by: Premium WordPress Themes | Thanks to Themes Gallery, Bromoney and Wordpress Themes