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

a. The Palmertown Elementary School has 30 classrooms. The children in the schoo

ID: 3683381 • Letter: A

Question

a. The Palmertown Elementary School has 30 classrooms. The children in the school donate used books to sell at an annual fundraising book fair. Write a program that accepts each teacher’s name and the number of books donated by that teacher’s classroom. Display the names of the four teachers whose classrooms donated the most books.

b. Modify the book donation program so that, besides the teacher’s name and number of books donated, the program also accepts the number of students in each classroom. Display the names of the teachers whose classrooms had the four highest ratios of book donations per student.

Explanation / Answer

#include<iostream>

using namespace std;

// function to sort 3 arrays based on number of books donated by classroom
void selection_sort (int bookNum[], string name[], int studentNum[], int size);

int main(){
  
   // declaring three array
   string name[30]; // store teachers name
   int bookNum[30]; // store number of books donated
   int studentnum[30]; // store number of students in classroom
  
   // getting user input for teacher's name , number of books donated by classroom, and number od students in calssroom
   for(int i=0; i<30; i++){
       cout<<"Enter teacher's name for classroom "<<(i+1);
       cin>>name[i];
       cout<<"Enter number of books donated by classroom "<<(i+1);
       cin>>bookNum[i];
       cout<<"Enter number of students in classroom "<<(i+1);
       cin>>studentnum[i];
   }
  
   //sorting three arrays based on number of books donated by classroom to find largest 4
   selection_sort(bookNum, name, studentnum, 30);
  
   //printing last 4 records
   cout<<"Teacher's Name: "<<name[29]<<", Number of books donated by classroom: "
           <<bookNum[29]<<", Number of students in classromm: "<<studentnum[29]<<endl;
   cout<<"Teacher's Name: "<<name[28]<<", Number of books donated by classroom: "
           <<bookNum[28]<<", Number of students in classromm: "<<studentnum[28]<<endl;
   cout<<"Teacher's Name: "<<name[27]<<", Number of books donated by classroo: "
           <<bookNum[27]<<", Number of students in classromm: "<<studentnum[27]<<endl;
   cout<<"Teacher's Name: "<<name[26]<<", Number of books donated by classroom: "
           <<bookNum[26]<<", Number of students in classromm: "<<studentnum[26]<<endl;
          
   return 0;
}

//function to sort
void selection_sort(int bookNum[], string name[], int studentNum[], int size)
{
int min_ele_loc;
for (int i = 0; i < size; ++i)
{
//Find minimum element in the unsorted array
//Assume it's the first element
min_ele_loc = i;

//Loop through the array to find it
for (int j = i + 1; j < 10; ++j)
{
if (bookNum[j] < bookNum[min_ele_loc])
{
//Found new minimum position, if present
min_ele_loc = j;
}
}

//Swap the values
   int temp = bookNum[i];
   bookNum[i] = bookNum[min_ele_loc];
   bookNum[min_ele_loc] = temp;
  
   string tempName = name[i];
   name[i] = name[min_ele_loc];
   name[min_ele_loc] = tempName;
  
   int tempStdNo = studentNum[i];
   studentNum[i] = studentNum[min_ele_loc];
   studentNum[min_ele_loc] = tempStdNo;
}  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote