C :: How To Display Order Of Persons Before And After Sorting By Age
Nov 15, 2013
This program I am trying to write has a structure of persons with a first name last name and age for each.
What I need it to do it display the order of the persons before sorting and then display the persons after sorting by age.
So far I have written the overall program but am stuck at the most important step...which is defining the functions that will be doing all of the work.
For sort_by_age I want use bubble sorting by writing the function myself and for print_person_info I am confused on how to print data out of the struct.
Code:
#include <stdio.h>
struct person
{
char first_name[20];
char last_name[20];
int age;
};
void print_person_info(struct person clone);
void sort_by_age(int n, struct person a[]);
I have a code right here that i worked on with my teacher. I can say that he did most of the work. Basically i'm sorting elements in a dictionary order.
Code: #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXWORD 50 // max word size void swap(char **p, char **q) // Q1: Why do I need a double pointer?
I need to find the Mean, median, mode, and make a histogram of a 99 value array. How ever my sorting function is not sorting the array at all how can I fix this.
What kind of code should i use for sorting numbers in both ascending and descending order? I don't know how to use bubble sorting either, is there another easy way to sort this out?
I am trying to read information in from a file, each line of which contains a name in the form 'last, first middle'. I can successfully open the file and read it into an array that is roughly 2500 string in size. The problem comes when I try to sort the array into alphabetical order. I am using a sorting algorithm that we were instructed to use, found in our book. It is shown in the code. I would add the file that needs to be opened, but it is a few thousand lines long.
The error I am getting is: Unhandled exception at 0x00A28628 in PeopleSearch.exe: 0xC0000005: Access violation reading location 0x00CC400C.
and I know it has to do with the sorting algorithm from using break points and running the program with that section commented out. I am stumped to why it is giving this error, as it seems that it is trying to access the array outside of the bounds of the array, but it shouldn't be
I have two vectors of float that I need to sort in reverse order. reverse() seems to work for one of them, but not the other. I have toggled between sort() and reverse(). for one vector, the expected behavior is seen and the order reverses. For the other, there is no change in order.
This is very simple code, so it's hard to imagine what is going wrong.
You can see that the order of the first vector did not change. Am I right in suspecting that the numbers are too similar for what ever method reverse() uses to determine the difference between values?
I have a vector which contains vectors containing 7 integers each. I'd like to sort these vectors based on the value of the first integer (int IOT), in ascending order. I know this type of question can be found everywhere, but I'm lost as to why this doesn't compile.
#include <fstream> #include <iostream> #include <vector> #include <string> #include <algorithm> #include <stdio.h> #include <math.h> #include <windows.h> using namespace std; class orders { public: int IOT; // Incoming Order Time
The assignment is to read in a text file of passenger names (first and last initial), seats (A1, B1, C1, D1, A2, etc.), and ticket prices. The output is specified to be a table of passengers and their seats sorted by seat order, and I also have to print the minimum and maximum ticket prices along with the owner of each ticket, along with the average of all ticket prices. My arrays are all reading in correctly, and the minimum, maximum, and average ticket prices were all easy to find. My problem is the sorting.
We were introduced to arrays a couple weeks ago and this is our first time doing any sorting. We are supposed to use a bubble sort, and while I think I gather how to use a bubble sort, it's not working in my program (so obviously I don't really know how to use it). I have tried several different things, and sometimes a few seats/names will switch around (never the way I want them to) and sometimes nothing will happen at all.
New to programming, not trying to get homework done for me, need to bubble sort airplane passengers and seats by seat order (A1, B1, C1, D1, A2, etc).
My input looks like this:
A Z A1 555.55
repeat with different initials, seats, and prices however many times the user sees fit.
I have a 1D character array for the columns(A - D), a 1D integer array for rows (1 to maximum integer), 1D float array for prices, and 2D array for name initals.
I am writing a function called swap that sorts the elements of an array in order from highest to lowest values where they descend and ascend. A particular thing about this function is that swap does NOT re-arrange elements in the array so it just uses a second array of indexes for the elements in the original array and then swap sorts the second array based on the values in the original array. A sorted version of the original array can then be produced with these sorted indexes. You can declare and initialize the original array without any user input.
For example, int arr[10] = {1, 5, 22, 14, 6, -5, 7, 9, 12, 15 };
Header of the function swap must be as shown below: void swap(int array[],int swapedIndexes [], int size, char mode) When mode is 'a', the function sorts the array in the ascending order, and when mode is 'd', the function sorts it in the descending order. int swappedIndexes[5];swap(array,swappedInde… 5, 'a');
So far I have this code that randomly generates arrays of 10 elements and I found the max and min, but I am confused on what to do about the swapping part? Also, how to make the numbers ascend or descend in numerical order?? Here is what i have done so far:
#include<ctime> #include <iostream> using namespace std; int min(int [],int); void max(int [],int , int &); void main() { srand(time(0)); //1-declare
This compiles fine but when I run the .exe for the first time an error message comes up saying program has stopped working. If I run the program again without recompiling it seems to work as expected.
I'm trying to use a priority queue sorting in reverse order to take a vector or 2d array. The problem is that I want to sort by the vector/array cell value but keep the reference to the vector/array index of the value. I don't know quite howto keep them both related so when I pop. I can find the corresponding cell.
I'm doing a project where I have to store information gathered (temperature and the time it was taken in seconds) in two separate vectors. After an unknown amount of data has been entered, and the end-of-file has been reached, I have to display the highest temperature and the time(s) it occured (bear in mind that the highest temperature may be recorded more than once). The output of that part should be as follows:
Highest temperature: 51 Recorded at time(s): 22:45 2:27
Something like that. The time should also be converted to hours and minutes. To the point: I've done some research on bubble sorting, but they only use it for arrays.