elearning.kctcs.edu In a Word document, complete the following. Include the head
ID: 3932800 • Letter: E
Question
elearning.kctcs.edu In a Word document, complete the following. Include the heading Programming Exercise, and type in the question number before you type in your answer 1. Programming Exercise 6 on page 366--write pseudocode. i. This problem requires you to use multiple parallel arrays. When you sort one of them, remember to move the elements within the other parallel arrays accordingly. i. In part b), calculate all of the ratios of book donations per student first in another parallel array and then work on finding the four highest of those ratios. Keep (i) above in mind here too.Explanation / Answer
a. main() {
input(teachers[30]);
input(noOfBooks[30]);
sort(noOfBooks);
print("4 teachers whose classroom donated the most books");
print(teachers[0]);
print(teachers[1]);
print(teachers[2]);
print(teachers[3]);
}
sort(noOfBooks) {
for (i = 0; i < 30; i++) {
for (j = 0; j < 29; j++) {
if (noOfBooks[j] < noOfBooks[j+1]) {
swap(noOfBooks[j], noOfBooks[j+1]);
swap(teaches[j], teachers[j+1]);
}
}
}
}
b. main() {
input(teachers[30]);
input(noOfBooks[30]);
input(noOfStudents[30]);
bookRatios[30];
for (i = 0; i < 30; i++)
bookRatios[i] = noOfBooks[i] / noOfStudents[i];
sort(bookRatios);
print("4 teachers whose classroom donated the most books");
print(teachers[0]);
print(teachers[1]);
print(teachers[2]);
print(teachers[3]);
}
sort(bookRatios) {
for (i = 0; i < 30; i++) {
for (j = 0; j < 29; j++) {
if (bookRatios[j] < bookRatios[j+1]) {
swap(bookRatios[j], bookRatios[j+1]);
swap(teaches[j], teachers[j+1]);
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.