You have add more for anyone to be able to answer this, sorry
Answer:
Explanation:
The following code is written in Java and creates all the classes as requested with their variables, and methods. Each extending to the Person class if needed. Due to technical difficulties I have attached the code as a txt file below, as well as a picture with the test output of calling the Staff class.
Answer:
The correct answer is:
C. ndx = 0;
while (ndx < 3) {
ar[ndx] = 0;
ndx++;
}
Explanation:
The declaration given is:
int ar[3];
This means the array consists of three locations and is named as ar.
We know that the indexes are used to address the locations of an array and the index starts from 0 and goes upto to 1 less than the size of the array which means the indexes of array of 3 elements will start from 0 and end at 2.
Now in the given options we are using ndx variable to run the while loop.
So the code to assign zero to all elements of array will be
ndx = 0;
while(ndx<3)
{
ar[ndx] = 0;
ndx++;
}
Hence, the correct answer is:
C. ndx = 0;
while (ndx < 3) {
ar[ndx] = 0;
ndx++;
}
Answer:
- with(open("numbers.txt")) as file:
- data = file.readlines()
- runsum = 0
- largest = 0
-
- for x in data:
- if(int(x) > largest):
- largest = int(x)
- runsum += largest
-
- print(runsum)
Explanation:
The solution code is written in Python 3.
Firstly, open a filestream for numbers.txt (Line 1) and then use readlines method to get every row of data from the text files (Line 2).
Create a variable runsum to hold the running sum of number bigger than the maximum value read up to that iteration in a for loop (Line 3).
Use a for loop to traverse through the read data and then check if the current row of integer is bigger than the maximum value up to that point, set the current integer to largest variable and then add the largest to runsum (Line 6 - 9).
At last display the runsum to console terminal (Line 11).