code
solution
output
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;
}
I just need an algorithm for this please! I have C++ code for it but I dont know how to creat an ...
( 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 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 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> #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 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 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 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 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 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 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; // ----------------------------------------------------------------------- //...