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

(DEV C++) Part I: Create and p rint out the two arrays : (Be sure to do this fir

ID: 3688621 • Letter: #

Question

(DEV C++)

Part I:

Create and print out the two arrays: (Be sure to do this first)  You are allowed to hard code these arrays into your program. You can also put the data into a file and read the information into the program. The data is as follows:

Anne130

Bob250

Ralph305

Tim225

Barbara85

Jane160

Steve180

Tom200

Mike165

Shirley155

Pam125

Frank120

Part II:  The elevators in our building have an 1100 lb. load limit. Determine which people in the list above get on the elevator. Print their names, weights, total weight, and how many got on.

Part III:  Rearrange these people in descendingsequence by weight and print the two arrays. Determine again how many may ride the elevator, printing out their names, weights, total weight and the number of how many people got on.

Part IV:  Rearrange these people in ascendingsequence by name (USE A DIFFERENT SORTALGORITHM THAN THE ONE YOU USED IN PART III) and print the two arrays. Determine again how many may ride the elevator, printing out their names, weights, total weight and the number of how many people got on.

Part V:  Have the program determine which method allowed the most people to get on the elevator.  The program should compare the three different counts of how many people got on the elevator.

This program should include:

Make sure all methods are writen to handle n elements, not just 12. You can pass 12 from main to n in the method/function.

Turn in: The assignment sheet, algorithm for main, source code, output and Academic Honor Promise.

EXTRA CREDIT: Read the data from a file and put the results on an output file. Print the output file using Notepad or some other editor.

Explanation / Answer

Answer -

#include <iostream>
#include <string>
#include <iomanip>
//#include <array>
using namespace std;

int asc_list_elevator(string name1[],int weight1[],int len1)
{
int lift_limit=1100,temp_total=0,count=0;
for(int p=0;p<len1-1;p++) // Loop for Pass
{
int min = p;
for(int i=p+1;i<len1;i++)
{
if(weight1[i]<weight1[min])
{
min = i;
}
}
int temp=weight1[p]; // Interchange Values
weight1[p]=weight1[min];
weight1[min]=temp;
  
string temp1=name1[p]; // Interchange Values
name1[p]=name1[min];
name1[min]=temp1;
}
cout<<" ---------SELECTION SORT ASCENDING ORDER INPUT-----------";
for(int i=0;i<len1;i++)
{
cout<<setw(10)<<" Name :"<<name1[i]<<" weight : "<<weight1[i];
}
cout<<" ---------OUTPUT FOR ASCENDING ORDER INPUT-----------";
for(int j=0;j<len1;j++)
{
if((temp_total+weight1[j])<=lift_limit)
{
temp_total=temp_total+weight1[j];
cout<<setw(10)<<" Name :"<<name1[j]<<" weight : "<<weight1[j];
count++;
}
}
cout<<" --->Total weight :"<<temp_total<<" Person count : "<<count;
return count;
}

int desc_list_elevator(string name1[],int weight1[],int len1)
{
int lift_limit=1100,temp_total=0,count=0;
for(int p=0;p<len1-1;p++) // Loop for Pass
{
for(int i=0;i<len1-1;i++)
{
if(weight1[i]<weight1[i+1])
{
int temp=weight1[i]; // Interchange Values
weight1[i]=weight1[i+1];
weight1[i+1]=temp;
  
string temp1=name1[i]; // Interchange Values
name1[i]=name1[i+1];
name1[i+1]=temp1;
}
}
}
cout<<" ---------BUBBLE SORT DESCENDING ORDER INPUT-----------";
for(int i=0;i<len1;i++)
{
cout<<setw(10)<<" Name :"<<name1[i]<<" weight : "<<weight1[i];
}
cout<<" ---------OUTPUT FOR DESCENDING ORDER INPUT-----------";
for(int j=0;j<len1;j++)
{
if((temp_total+weight1[j])<=lift_limit)
{
temp_total=temp_total+weight1[j];
cout<<setw(10)<<" Name :"<<name1[j]<<" weight : "<<weight1[j];
count++;
}
}
cout<<" --->Total weight :"<<temp_total<<" Person count : "<<count;
return count;
}

int list_elevator(string name1[],int weight1[],int len1)
{
int lift_limit=1100,temp_total=0,count=0;
cout<<" ---------OUTPUT FOR DIRECT GIVEN INPUT-----------";
for(int i=0;i<len1;i++)
{
if((temp_total+weight1[i])<=lift_limit)
{
temp_total=temp_total+weight1[i];
cout<<setw(10)<<" Name :"<<name1[i]<<" weight : "<<weight1[i];
count++;
}
}
cout<<" --->Total weight :"<<temp_total<<" Person count : "<<count;
return count;
}
int main()
{
string name[]={"Anne","Bob","Ralph","Tim","Barbara","Jane","Steve","Tom","Mike","Shirley","Pam","Frank"};
int weight[] ={130,250,305,225,85,160,180,200,165,155,125,120};
int count1,count2,count3,len;
len=(sizeof(weight)/sizeof(int));
for(int i=0;i<len;i++)
{
cout<<setw(10)<<" Name :"<<name[i]<<" weight : "<<weight[i];
}
count1=list_elevator(name,weight,len);
count2=desc_list_elevator(name,weight,len);
count3=asc_list_elevator(name,weight,len);
if(count1>count2&&count1>count3)
{
cout<<" Direct Input method is BEST with count of Person : "<<count1;
}
else if(count2>count1&&count2>count3)
{
cout<<" Descending Order Input method is BEST with count of Person : "<<count2;
}
else if(count3>count1&&count3>count2)
{
cout<<" Ascending Order Input method is BEST with count of Person : "<<count3;
}
return 0;
}