error in program due today!!

Apr 12, 2016 at 2:25am
Assume a class Window with accessor method getWidth that accepts no parameters and returns 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 .( this question is from myprograminglab)Thank you !!

1
2
3
4
5
6
7
8
int maxVal = winarr[0].getWidth();
for(int i = 1; i < WINARR_SIZE; i++) 
{
   if(winarr[i].getWidth() > maxVal)
      maxVal = winarr[i].getWidth();
}
cout << "The widest width of the windows is: "
	<< maxVal << endl;

error:./CTest.cpp: In function ‘int main()’:
./CTest.cpp:14:21: error: ‘WINARR_SIZE’ was not declared in this scope
for(int i = 0; i < WINARR_SIZE; i++)
^
./CTest.cpp:16:31: error: ‘maxVal’ was not declared in this scope
if(winarr[i].getWidth() > maxVal)
^
./CTest.cpp:20:6: error: ‘maxVal’ was not declared in this scope
<< maxVal
^
./CTest.cpp:22:1: error: expected ‘;’ before ‘}’ token
}
error:./CTest.cpp: In function ‘int main()’:
./CTest.cpp:14:21: error: ‘WINARR_SIZE’ was not declared in this scope
for(int i = 0; i < WINARR_SIZE; i++)
^
./CTest.cpp:16:31: error: ‘maxVal’ was not declared in this scope
if(winarr[i].getWidth() > maxVal)
^
./CTest.cpp:20:6: error: ‘maxVal’ was not declared in this scope
<< maxVal
^
./CTest.cpp:22:1: error: expected ‘;’ before ‘}’ token
}
Last edited on Apr 12, 2016 at 2:26am
Apr 12, 2016 at 2:36am
You should post the whole code. Also make sure you actually have an int named WINARR_SIZE
Last edited on Apr 12, 2016 at 2:37am
Apr 12, 2016 at 2:40am
THis is a programing lab question usually only have to do the main program, but dont have to include header. Sometimes the whole program will not mark as correct

If follow the code above what will be the answer?? Thank you again!!

Assume a class Window with accessor method getWidth that accepts no parameters and returns 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 .
Topic archived. No new replies allowed.