constructor #2 The new fruit's name, amount, weight, etc. are arguments. Calls the individual setters (below) to validate and set the variable. set_name Accept a string argument and copies it into the name variable set_amount Accepts an int argument and copies it into amount variable, but ONLY if >= 0 set_weight Accept a float argument and copies it into the weight variable if valid set_price Accepts a double argument and copies it into the price, if reasonable Retrieval of data is done with getters: Member Function/Method Description get_name Returns the value in name get_amount Returns the value of rooms get_weight Returns the value of square_feet get_prie Returns the list_price of the house Provide two constructors: one for a “default” object, and one for an object where all the initial values are provided. Provide setters that validate new values and changes data members if OK. Provide getters. One of the getters should be a show / display / print / cout getter that shows all information about the object. Another getter should show some combination of data members, such as: get_price_per_sqft, which performs a calculation and then produces a result: get_price_per_sqft() returns list_price / square_feet. After the class is working, create at least 5 different, separate instances of the class, such as: fruit1, fruit2, ... fruit5. Create 3 instances with all valid data and 2 instances with some (attempted) invalid data. . (apple, orange, banana, grapes, avocado) Setters should NOT change existing valid member values to invalid values. If given invalid data in a setter, reject it. Do not change the value. Modify the program to ask: "How many objects do you want?". Loop as many times specified by the user (5 is enough for testing) to create that many objects. You can use 5 individual variables, or you can use an array or vector. Submit one .cpp file. Do not create the class in a separate file. |
|
|
|
|
|
|
|
|
This program creates at least 5 separate, co-existing instances of a custom designed object. Information about each object is displayed. Each constructor, setter and getter is tested at least once. Name: Apple Quantity: 0 Name: Orange Quantity: 0 Name: Banana Quantity: 0 Name: Avocado Quantity: 0 Name: Grapes Quantity: 0 This ends the class design, implementation, test program. Goodbye! |
|
|
|
|
|
|
|
|
This program creates at least 5 separate, co-existing instances of a custom designed object. Information about each object is displayed. Each constructor, setter and getter is tested at least once. Name: Apple Quantity: 4 Weight: 4.56 Price: $4 Did you purchase? true Name: Orange Quantity: 7 Weight: 2.65 Price: $5 Did you purchase? true Name: Negative Quantity: 0 Weight: 2.65 Price: $5 Did you purchase? true And then it can be done this way ... Name: Banana Quantity: 4 Weight: 2.34 Price: $2 Did you purchase?: true Name: Avocado Quantity: 0 Weight: 2.59 Price: $6 Did you purchase?: true Name: Grape Quantity: 6 Weight: 2.59 Price: $6 Did you purchase?: false This ends the class design, implementation, test program. Goodbye! Now for the object/memory cleanup via the destructor Fruit object deleted. Fruit object deleted. Fruit object deleted. Fruit object deleted. Fruit object deleted. Fruit object deleted. Program ended with exit code: 0 |
|
|
void set_Quantity(int q) { if (q >= 0) quantity = q; } |
|
|
|
|