Question
I just need an algorithm for this please! I have C++ code for it but I dont know how to creat an algorithm ..
CSE 1311-Project 4 Part I: Create and print out the two arrays: (Be sure to do this first) You are allowed to hard code these
Part II The elevators in our building have an 1100 lb. load limit. Determine which people in the list above get on the elevat
CSE 1311-Project 4 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: 150 250 Anne Bob Ralph 305 Tim Barbara85 Jane Steve 210 Tom Mike Shiley 155 Pam Frank 160 180 165 130 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 asscending sequence 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 descending sequence by name (USE A DIFFERENT SORT ALGORITHM 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 in each of the scenarios above with the weight array as given, with the weight array in ascenging order, with the name array in descending order This program should include: 2 different sort functions
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 asscending sequence 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 descending sequence by name (USE A DIFFERENT SORT ALGORITHM 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 in each of the scenarios above - with the weight array as given, with the weight array in ascenging order, with the name array in descending order 2 different sort functions a function to determine how many people get on the elevator (will be called 3 times) .a print function which prints both arrays (include a size parameter and it can be called 6 times) 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 Honesty 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
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Algorithm step 1:Declare the function name ascendinglist_elevator () step 2:delcare the variable limit,count and temp value istep 5:print total weight and peron count step 6:create the function descendinglist_elevator (string namel [,int weight_1[1,istep 10:delcare the variable liftlimit,tempvalue and count step 11: check the condition t。display the t tal we ight and count

code

solution

#include <iostream> #include <string> #include <10manip> //#include <array> using namespace std; int ascendinglist_elevator (coutくくsetw (10)<<\nName <<weight_1[i] :くくname 1 [i]<< weight : cout<< nn-OUTPUT FOR ASCENDING ORDER for (int j=0;jclengint tempvalue-weight_1[i]; weight 1[il-weight 1[i+1] weight-1 [i+1 ] =tempvalue ; string tempvalue1-namel [i]; name 1 [ =nameint list_elevator (string name1 [1,int weight_1[1,int leng1) int liftlinit-1100, tempvalue-total=0, cnt=0; cout<< nn-OUTPUTcoutくくsetw(10)<<\nName :<<name [i]<< weight <<weight [i]; : cnt 1-11stelevator (name, weight, len) ; cnt2-descendinglist_

output

Name :Anne weight 150 Name :Bob weight 250 Name Ralph weight: 305 Name :Tim weight 250 Name :Barbara weight 85 Name :Jane weiBUBBLE SORT DESCENDING ORDER Name Ralph weight: 305 Name :Bob weight 250 Name :Tim weight : 250 Name :Tom weight : 210 Name :Name :Mike weight: 165 Name :Steve weight: 180 Name Tom weight 210 Name Tim weight250 Name :Bob weight 250 Name :Ralph weight

copyable code

#include <string>

#include <iomanip>

//#include <array>

using namespace std;

int ascendinglist_elevator(string name1[],int weight_1[],int leng1)

{

int liftlimit=1100,tempvalue_total=0,cnt=0;

for(int p=0;p<leng1-1;p++)

{

int minimum = p;

for(int i=p+1;i<leng1;i++)

{

if(weight_1[i]<weight_1[minimum])

{

minimum = i;

}

}

int tempvalue=weight_1[p];

weight_1[p]=weight_1[minimum];

weight_1[minimum]=tempvalue;

  

string tempvalue1=name1[p];

name1[p]=name1[minimum];

name1[minimum]=tempvalue1;

}

cout<<"\n\n--SELECTION SORT ASCENDING ORDER ";

for(int i=0;i<leng1;i++)

{

cout<<setw(10)<<"\nName :"<<name1[i]<<" weight : "<<weight_1[i];

}

cout<<"\n\n-OUTPUT FOR ASCENDING ORDER ";

for(int j=0;j<leng1;j++)

{

if((tempvalue_total+weight_1[j])<=liftlimit)

{

tempvalue_total=tempvalue_total+weight_1[j];

cout<<setw(10)<<"\nName :"<<name1[j]<<" weight : "<<weight_1[j];

cnt++;

}

}

cout<<"\n--->Total weight :"<<tempvalue_total<<" Person cnt : "<<cnt;

return cnt;

}

int descendinglist_elevator(string name1[],int weight_1[],int leng1)

{

int liftlimit=1100,tempvalue_total=0,cnt=0;

for(int p=0;p<leng1-1;p++)

{

for(int i=0;i<leng1-1;i++)

{

if(weight_1[i]<weight_1[i+1])

{

int tempvalue=weight_1[i];

weight_1[i]=weight_1[i+1];

weight_1[i+1]=tempvalue;

  

string tempvalue1=name1[i];

name1[i]=name1[i+1];

name1[i+1]=tempvalue1;

}

}

}

cout<<"\n\nBUBBLE SORT DESCENDING ORDER";

for(int i=0;i<leng1;i++)

{

cout<<setw(10)<<"\nName :"<<name1[i]<<" weight : "<<weight_1[i];

}

cout<<"\n\nOUTPUT FOR DESCENDING ORDER INPUT-";

for(int j=0;j<leng1;j++)

{

if((tempvalue_total+weight_1[j])<=liftlimit)

{

tempvalue_total=tempvalue_total+weight_1[j];

cout<<setw(10)<<"\nName :"<<name1[j]<<" weight : "<<weight_1[j];

cnt++;

}

}

cout<<"\n--->Total weight :"<<tempvalue_total<<" Person cnt : "<<cnt;

return cnt;

}

int list_elevator(string name1[],int weight_1[],int leng1)

{

int liftlimit=1100,tempvalue_total=0,cnt=0;

cout<<"\n\n-OUTPUT FOR DIRECT GIVEN INPUT-";

for(int i=0;i<leng1;i++)

{

if((tempvalue_total+weight_1[i])<=liftlimit)

{

tempvalue_total=tempvalue_total+weight_1[i];

cout<<setw(10)<<"\nName :"<<name1[i]<<" weight : "<<weight_1[i];

cnt++;

}

}

cout<<"\n--->Total weight :"<<tempvalue_total<<" Person cnt : "<<cnt;

return cnt;

}

int main()

{

string name[]={"Anne","Bob","Ralph","Tim","Barbara","Jane","Steve","Tom","Mike","Shirley","Pam","Frank"};

int weight[] ={150,250,305,250,85,160,180,210,165,155,125,130};

int cnt1,cnt2,cnt3,len;

len=(sizeof(weight)/sizeof(int));

for(int i=0;i<len;i++)

{

cout<<setw(10)<<"\nName :"<<name[i]<<" weight : "<<weight[i];

}

cnt1=list_elevator(name,weight,len);

cnt2=descendinglist_elevator(name,weight,len);

cnt3=ascendinglist_elevator(name,weight,len);

if(cnt1>cnt2&&cnt1>cnt3)

{

cout<<"\n\nDirect Input method is BEST "<<cnt1;

}

else if(cnt2>cnt1&&cnt2>cnt3)

{

cout<<"\n\nDescending Order Input method is BEST : "<<cnt2;

}

else if(cnt3>cnt1&&cnt3>cnt2)

{

cout<<"\n\nAscending Order Input method is BEST with cnt of Person : "<<cnt3;

}

return 0;

}

Add a comment
Know the answer?
Add Answer to:
I just need an algorithm for this please! I have C++ code for it but I dont know how to creat an ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please) I need...

    ( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please) I need the answer quickly, please :((((((.. pleaaasssee heeelp mmmeeee// i need all answers, UNIQUE ANSWER please Q3: Write a Java program that allows the following: 1.Create an array list of 20 integers. The 20 integers are generated randomly with possible values from 0 to 10. 2.Print the content of the array list. 3.Find how many of these values are multiple of 3. Show a screenshot...

  • MATLAB question: I have written a code to solve for a metals resitance. Here is the...

    MATLAB question: I have written a code to solve for a metals resitance. Here is the problem statement: Part 1 (Algorithms) – due Friday: Think about how you might solve the problem of calculating the resistance of a given group of metals depending on the type of metal, the length of the wire and the area of the wire (if given the diameter only – so you must calculate the area). Write instructions (an algorithm) for a script that behaves...

  • Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the...

    Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the original high score program,: Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look exactly like this: Enter the name for score #1: Suzy Enter the score for...

  • How would I change the following C code to implement the following functions: CODE: #include <stdio.h>...

    How would I change the following C code to implement the following functions: CODE: #include <stdio.h> #include <stdlib.h> int main(int argc, char * argv[]) { if (argc != 2) printf("Invalid input!\n"); else { FILE * f = fopen (argv[1], "r"); if (f != NULL) { printf("File opened successfully.\n"); char line[256]; while (fgets(line, sizeof(line), f)) { printf("%s", line); } fclose(f); } else { printf("File cannot be opened!"); } } return 0; } QUESTION: Add a function that uses fscanf like this:...

  • c++ can use if else, loop,function ,array,file i.o. Can not use swtich, global variables etc..   Please...

    c++ can use if else, loop,function ,array,file i.o. Can not use swtich, global variables etc..   Please do all parts. previously I post 3 time for part1 ,2 and 3 but I can't make it into one complete program code. I even try to post a questions ask and post the 3 parts of code for experts to put it together. But experts said it's not enough information. please help... Thank you ! Program Objectives: Allow students to create arrays Allow...

  • Need help with program. I'm stuck Objectives: In this assignment, we will practice manipulating lists of...

    Need help with program. I'm stuck Objectives: In this assignment, we will practice manipulating lists of data and arranging items in an ascending/descending order. you will also explore storing lists/arrays using different sorting algorithms including, the selection sort, bubble sort, and insertion sort algorithm. Comparison between the three algorithms are made based on the number of comparisons and item assignments (basic operations) each algorithms executes. Background: Ordering the elements of a list is a problem that occurs in many computer...

  • Need C programming help. I've started to work on the program, however I struggle when using...

    Need C programming help. I've started to work on the program, however I struggle when using files and pointers. Any help is appreciated as I am having a hard time comleting this code. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LINE 100 #define MAX_NAME 30 int countLinesInFile(FILE* fPtr); int findPlayerByName(char** names, char* target, int size); int findMVP(int* goals, int* assists, int size); void printPlayers(int* goals, int* assists, char** names, int size); void allocateMemory(int** goals, int** assists, char*** names, int size);...

  • Please need help, programming in C - Part A You will need to create a struct...

    Please need help, programming in C - Part A You will need to create a struct called Team that contains a string buffer for the team name. After you've defined 8 teams, you will place pointers to all 8 into an array called leaguel], defined the following way: Team leaguel8]. This must be an aray of pointers to teams, not an array of Teams Write a function called game) that takes pointers to two teams, then randomly and numerically determines...

  • C++ language I need to update this code with the following: ask the user for how...

    C++ language I need to update this code with the following: ask the user for how many structures they would like. Once you get the number, allocate an array of pointers. Once they have been created, proceed to loop through and get the data as usual, and display it back to the screen. struct record {    int age;    string name; }; int check(record r[], int n, string nm) {    for (int i = 0; i < n;...

  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT