Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

9.11 C++ Combine the modified Time class of Exercise 9.7 and the modified Date c

ID: 3820828 • Letter: 9

Question

9.11 C++ Combine the modified Time class of Exercise 9.7 and the modified Date class of Exercise 9.8 into one class called DateAndTime. (In Chapter 11, we'll discuss inheritance, which will enable us to accomplish this task quickly without modifying the existing class definitions.) Modify the tick function to call the nextDay function if the time increments into the next day. Modify functions printStandard and printUniversal to output the date and time. Write a program to test the new class DateAndTime. Specifically, test incrementing the time into the next day. (Returning Error Indicators from Class Time's set Functions) Modify the set functions in the Time class of Figs. 9.4-9.5 to return appropriate error values if an attempt is made to set a data member of an object of class Time to an invalid value. Write a program that tests your new version of class Time. Display error messages when ret functions return error values. (Rectangle Class) Create a class Rectangle with attributes length and width, each of which defaults to 1. Provide member functions that calculate the perimeter and the area of the rectangle. Also, provide set and get functions for the length and width attributes. The set functions should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0. (Enhancing Class Rectangle) Create a more sophisticated Rectangle class than the one you created in Exercise 9.11. This class stores only the Cartesian coordinates of the four comers of the rectangle. The constructor calls a set function that accepts four sets of coordinates and verifies that each of these is in the first quadrant with no single x- or y-coordinate larger than 20.0. The set function also verifies that the supplied coordinates do, in fact, specify a rectangle. Provide member functions that calculate the length, width, perimeter and area. The length is the larger of the two dimensions. Include a predicate function square that determines whether the rectangle is a square. (Enhancing Class Rectangle) Modify class Rectangle from Exercise 9.12 to include a draw function that displays the rectangle inside a 25-by-25 box enclosing the portion of the first quadrant in which the rectangle resides. Include a setFillCharacter function to specify the character out of which the body of the rectangle will be drawn. Include a setPerimeterCharacter function to specify

Explanation / Answer

#include <iostream.h>

using namespace std;

class Rectangle

{

public:

Rectangle(float L,float W);

float getLength() {return length;}

void setLength(float L);

float getWidth() {return width;}

void setWidth(float W);

double perimeter(void){return (length*2 +width*2);}

double area(void) {return (length*width);}

private:

float L,W,length,width;

};

Rectangle::rectangle(float L,float W)

{

length=L;

width=W;
}

void Rectangle::setWidth(float W)

{

if((W<0.0) || (W>20.0))

{

width=1.0;

}

else

{

width=W;

}

return;

}

float getWidth()

{

return W;

}

void Rectangle::setLength(float L)

{

if((L<0.0) || (L>20.0))

{

length=1.0;

}

else

{

length=L;

}

return;

}

float getLength()

{

return L;

}

void Rectangle::get(float F,float W)

{

}

double Rectangle::perimeter(Float L,float W)

{

perimeter=(2*L)+(2*W);

cout<<"The perimeter of the rectangle is :"<<perimeter<<endl;

}

double Rectangle::area(float L,float W)

{

area=L*W;

cout<<"The area of the rectangle is :"<<area<<endl;

}

int main()

{

rectangle MyRectangle;

cout<<"Please enter the length of the rectangle:"<<endl;

cin>>MyRectangle.getlength>>endl;

cout<<"Please enter the width of the rectangle:"<<endl;

cin>>MyRectangle.getwidth>>endl;

return 0;

}