C++ :: How To Sort And Print Out Object By Surname In Alphabetical Order
Oct 2, 2013
A link list problem, i need some how to sort and print out an object by surname in alphabetical order.
i have a try to do that by this code not working for swamping i should i go about that?
May another way of swapping using pointer instead?
void functions::printdata() {
for(node* temp1=head;temp1!=NULL;temp1=temp1->next) {
for(node* temp2=head;temp2!=NULL;temp2=temp2->next) {
[Code]...
View 1 Replies
ADVERTISEMENT
Apr 15, 2014
I have a text file containing the names and surnames of enrollment numbers and grades of students , looks like this:
RIKI Rikic E2345678 10
JUPI jupic E1232345 9
Etc ......)
I'm interested in sorting by name and surname, registration number and grade.My example:
struct student {
string name;
string surname;
string enrollment;
int grade;
};
and in the main program
int main () {
Student STUDENT;
/ / Code to read a text file that I wrote so I have ...
switch ()
case '1 ': / / sort by name
case 2: / / by surname
Case 3 / / by enrollment
Case 4 / / by grade
this sort we are not going very well .
View 1 Replies
View Related
Oct 14, 2013
How would you compare two strings in an if statement to determine which comes first in alphabetical order?
Try and keep it simple because i am currently new to the language
View 2 Replies
View Related
Oct 25, 2013
I am having problem with comparing first letter of every wordso that i can arrange them in array.
Code:
/*22/10/13 15:30
Arrange set of names in an array in alphabetical order
*/
#include<stdio.h>
main( ) {
int x,a,i=0,j;
char *temp, *str[]={
[Code] ....
I am getting unexpected output here :
Code:
himanshu
amit
nitin
saurabh
View 3 Replies
View Related
Apr 14, 2014
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
Here is my code:
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main() {
string NameArray[2500], filename; //declare array and file to open
[Code] ....
View 2 Replies
View Related
Nov 10, 2013
So I been working on this c++ project and I need to be able to take three seperate strings and send them to function to put them in alphabetical order through a-z and use the swap function to return them in order. I been searching for problems like this but I haven't fame across any. I can copy my code onto here as well as a more detailed description of what I'm needing to do onto here if needed.
View 4 Replies
View Related
Oct 26, 2013
I know there is a function in algorithm class called sort() but I need to sort ignoring the case of the alphabet
Is there any function that does that?
View 2 Replies
View Related
Nov 25, 2014
I'm trying to sort strings as alphabetical but somewhere i have error.
Code:
#include <stdio.h>
#include <string.h>
int main(){
char s[100][20];
int num;
char temp[20];
int i,j;
[Code]....
View 1 Replies
View Related
Jul 29, 2014
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main() {
const int arraySize=20;
[Code] ....
View 5 Replies
View Related
Mar 10, 2015
i have a list
ID | Location | Quantity
1 | 2 | 5
2 | 3 | 10
3 | 4 | 8
i want the order to be in ascending order by Quantity so it should produce this
ID | Location | Quantity
1 | 2 | 5
3 | 4 | 8
2 | 3 | 10
View 4 Replies
View Related
Sep 29, 2013
Trying to sort matrix such that it has value in ascending order.
But outcome is coming :
Code:
Matrix after sorting :
2,2,2,2,
2,2,2,2,
2,2,2,2,
2,2,2,2,
Can't find whats wrong.
[Code]....
View 2 Replies
View Related
Feb 19, 2014
Write a program that orders three double numbers by increasing value. The program should include a function named sort3 that takes three double * arguments (pointer to double). The function prototype is void sort3(double *x, double *y, double *z); The function should reorder the values pointed to by its arguments so that after the call sort3(&x, &y, &z); the numbers satisfy . Your program should input data and print results using the following format:
Enter three numbers: 4.7 1.4 3.2
The ordered sequence is: 1.4 3.2 4.7
And here is my program: C code - 32 lines - codepad
I am getting a lot of errors when I run it through GCC. I can only use pointers.
View 4 Replies
View Related
Jan 22, 2014
so my program reads a file type which looks like this...
Michelle 71
Marcie 99
David 42
Rebecca 83
Jonathan 79
Matthew 77
Rose 7
Melanie 75
Kimberly 73
Roger 74
Scott 76
Bradley 77
Drextell 10
Heidi 70
Alan 68
Pearl 13
Jeanne 43
Heber 55
Here is whats in the header of the class
class StudentStat {
private:
int Size;
[Code].....
So as of right now the names are stored in a Names string array and the scores are saved in a Score int array. So my question is where do I begin with my bubble sort? I need it to put the scores in descending order so from greatest score to lowest but I need the Names in the string array to still be connected to the number from the list. Never done a bubble sort before so not sure where to begin.
View 1 Replies
View Related
Jun 20, 2014
I am having trouble sorting out a list of names in c. I have code for sorting the names, but when I go to print them out they still are in the same order as they were at the beginning so something isnt right. So the function that I need is the sort_data function.
Code:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX_STRING_LEN 25
void insert_data(char **strings, const char* filename, int size);
void allocate(char ***strings, int size);
[Code] ....
The list that I am reading in is as follows:
matt
susan
mark
david
aden
phil
erik
john
caden
mycah
So I need to get this list in alphabetical order, but when I run my code and print out this list after I run the sort function, they are still in this order.
View 5 Replies
View Related
Feb 1, 2014
I'm stuck again on a homework problem. I enter 9 8 7 6 5 4 3 2 1 in to the program when it asks me to. I print out the array (just before the bubble sort routine) and I get the numbers in descending order just as expected. So going into bubble sort routine, the numbers are correct.
I should get 1 2 3 4 5 6 7 8 9 as output.
But I get 1 2 3 4 4 5 6 7 8
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int max_size = 20; // max size of array of numbers
int numbers[max_size]; // array for numbers
[Code] .....
View 4 Replies
View Related
Sep 25, 2014
So I try to sort an array with qsort and then save the new order, so this means if I have a list like:
4 3 7 2
[0] [1] [2] [3],
after sorting it becomes:
2 3 4 7
[3] [1] [0] [2] <== this is what I want to have!
Code:
void qsort_my(int *a, int l, int r, int *array_order) {
int j;
if( l < r ) {
j = split( a, l, r, array_order);
qsort_my( a, l, j-1, array_order);
qsort_my( a, j+1, r, array_order);
[Code]...
But my problem is that the list gets sorted, but the indexes do strange stuff. When I run with this list:
4 8 14 1 2 1 22 12 2 14
Pos: 0 1 2 3 4 5 6 7 8 9
I get:
1 1 2 2 4 8 12 14 14 22
Pos: 1 0 1 0 0 5 7 6 5 6
And with some printfs I noticed, the first two calls of split it is fine but then strange things start to happen, what I do wrong?
View 6 Replies
View Related
Jul 27, 2014
I am pretty much new in C++ programming and i have to do stack exercises. Writing a simple code of sorting the elements in ascending order in a stack.
View 6 Replies
View Related
Feb 17, 2013
Question: What is the efficiency and big O of the selection sort algorithm when the input happens to already be in nondecreasing order?
Answer: Not sure... since the input is in nondecreasing order, such that example 0, 1, 1, 2, 3, 4, 4, 5 then there will be no swap, Just comparisons of emelemts. So it is big O of n
View 2 Replies
View Related
Jan 25, 2014
So I need to read in a .txt file and sort it by SSN in ascending order. How to start this but here's what I have so far:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct Information {
char name[25];
long SSN;
[Code] .....
Also here is the contents of the .txt file:
Matthews,Jocob
459237148
19
3930 4th Blvd, Yourcity, NJ 88710
......
and so on.
View 1 Replies
View Related
Apr 18, 2013
At the line number 65 that's my sort method first i sum up all the value in the nodes after that i want to sort the Nodes In ascending order but the method is not working ...
#include <iostream>
#include <conio.h>
using namespace std;
// Node Class
[Code] ....
View 3 Replies
View Related
Jan 24, 2014
I'm trying to write a program to sort 2 ints on ascending/descending order, using function pointers. here is my code so far:
Code:
#include <stdio.h>
#include <stdlib.h>
int min_el(int a,int b);
[code]....
View 6 Replies
View Related
Jan 8, 2013
Assignment:
1. Choose what to enter NUMBER or LETTER.
2. Choose type of sorting ASCENDING or DESCENDING.
#include<iostream.h>
#include<conio.h>
main() {
int x,y,z;
cout<<"choose Number or letter
1.number
2.Letter";
[Code] ....
View 9 Replies
View Related
Mar 20, 2014
I have a pre-declared array which sorts strings to it's alphabetic order and want to change it so it reads from stdin.
char *array[] = {"aaa", "ccc", "bbb", "ddd"}
I tried doing something like this:
for (i = 0; i < length; i++)
scanf("%s", &array[i]);
I just can't bring it to work. Another thing is, the input is a a bunch of strings separated by commas and ends with a period. Since I have to make a working C model which gets translated to assembly language later on I can't use functions like strtok.
View 6 Replies
View Related
Oct 29, 2014
I am trying to write a program which will sort an array of numbers into ascending order, here is my code
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int array[]={1, 5, 17, 3, 75, 4, 4, 23, 5, 12, 34, 34, 805, 345, 435, 234, 6, 47, 4, 9, 0, 56, 32, 78};
[Code] .....
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.
View 2 Replies
View Related
Mar 24, 2013
I am supposed to make a program that take a list of integers from the user and to delete the smallest part of it in order to make it sorted in non decreasing order ..
example : input : 1 2 3 4 5 8 7 6 7 8 9
output : 1 2 3 4 5 6 7 8 9 ( delete : 8 7 )
I need a code that use a technique similar to the merge function to achieve linear time ..
this code works but it is in quadratic time :
int main () {
cout<<"Enter a list of numnbers ending with the sentinel -999:"<<endl;
int A[1000];
int n = 0;
int x;
cin>>x;
while(x!=-999)
[Code] ....
View 4 Replies
View Related
Oct 17, 2014
I have to write a function called sortMe that sorts the elements of an array in numerical order from highest to lowest values (descending order) or vice versa (ascending order).
The assignment asks to: NOT re-arrange elements in the array; instead, it uses a second array, an array of indexes for the elements in the original array and then sortMe 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.
Header of the function sortMe must be as shown below:
void sortMe(int array[],int sortedIndexes [], 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.
Declare and initialize the array array.
Declare the array sortedIndexes but do not initialize it. You are going to play with the array sortedIndexes in the function sortMe.
EXAMPLE:
int array[5]={3, 5,-1,10,0};
int sortedIndexes[5];
sortMe(array,sortedIndexes, 5, 'a');
After the function call, the elements of the array sortedIndexes should be: 2,4,0,1,3.
notice that the function does not e-arrange the elements in the array.
Code:
#include <iostream>
using namespace std;
void sortMe(int[], int, char);
void main() {
int arr[6] = { 14, -5, 5, 0, 22, -99 };
[code]...
how to use the other array.
View 5 Replies
View Related