A) Assume the existence of a class named Window with functions named close and f
ID: 3552481 • Letter: A
Question
A) Assume the existence of a class named Window with functions named close and freeResources, both of which accept no parameters and return no value . Write a destructor for the class that invokes close followed by freeResources.
B) Assume a class Window with accessor methods getWidth that accepts no parameters and return an integer . Assume further an array of 3 Window elements named winarr, has been declared and initialized . Write a sequence of statements that prints out the width of the widest window in the array .
Explanation / Answer
A) Destructor
--------------------
Window::~Window()
{
close();
freeResources();
}
B) Code Snippet
------------------------------
int widest = 0;
for (int i = 0; i<3, i++){
cout<<"Width of "<<i+1<<" th element = <<winarr[i].getWidth()<<endl;
if(widest > winarr[i].getWidth())
widest = winarr[i].getWidth();
cout<<"Widest window has width = " <<widest<<endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.