C++ :: Sorting Numerical Array Error

Nov 25, 2013

Why this wont run? I'm getting the cant convert int* to const char error but i do not know why?

I'm trying to create a program that creates an array of 100 ints between 0 and 250 and then sorts them using a separate function, I've gotten this far

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <cstring>

using namespace std;
void quicksort (int *items, int len);

[Code] ....

View 3 Replies


ADVERTISEMENT

C++ ::  Sorting Array To Numerical Order?

Nov 25, 2014

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.

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <cctype>

[Code].....

View 8 Replies View Related

C :: Program To Accept Only Numerical Values And Gives Error If Character Or Symbol Entered

Nov 11, 2013

How can i make my program to accept only numerical values and gives a error notice if a character or a symbol is entered???

View 4 Replies View Related

C++ :: How To Put Values Of Array In Numerical Order

May 20, 2014

im trying to make a statistics program and i have an array holding all the users numbers. The array has 10 elements and i was wondering how i could put these elements in order from smallest to largest.

View 18 Replies View Related

C++ :: Implementing Template Operator - Numerical Array

Jun 19, 2012

I what to implement to my Template operator * . There is <Template> Array which purpose is container like vector for classes. There is class Point, each object of contain two coordinate x and y.

So,
1. I wanna fill Array with objects from Point class
2. Multiply each objects from this vector to a factor
3. And print all this bunch of objects ()...

Compile error :
1>------ Build started: Project: HP_4.2b_Ex2, Configuration: Release Win32 ------
1> main.cpp
1>main.cpp(21): error C2440: 'initializing' : cannot convert from 'Point' to 'Array<Type>'

[Code] ....

And pop -up helper tell that : Error: no suitable user defined conversion from "Point " to Array<Point> exist

Code:
//array.h
#ifndef Array_H
#define Array_H
template <class Type> //Remove the "=double" default parameter.
class Array {
protected:
int m_size;
Type* m_data; //m_data should be a pointer, since you want to allocate data to it

[Code] ....

View 6 Replies View Related

Visual C++ :: Writing A Function That Sort Elements Of Array In Numerical Order?

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

C++ :: Output Sorting Error Using Pointer Notation

Aug 6, 2012

My code compiled well(After long Messing up with my head). But, i still not satisfied of my output as i expected. My code ought to sort the object of person comparing their salary. But, its not.

Code:
#include <iostream>
#include <string>
using namespace std;
class person {
protected :
string name;
float salary;

[Code] ....

It doesn't sort the object of class person rather than it prints out the stored value as it is.

View 3 Replies View Related

C :: Merge Sorting The Linked Lists - Runtime Error

Aug 10, 2013

The following program throws runtime error.

Code:
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;

[Code] .....

View 3 Replies View Related

C :: Routines Library For Numerical Tasks

Jan 13, 2014

I am looking for C-libraries that would do numerical tasks with special emphasis on numerical differentiation of arbitrary order, numerical integration (Monte Carlo etc.) and interpolation. I would be grateful if you can provide me with some resources. By the way I already have Numerical Recipes but would like to have another resource at hand.

View 11 Replies View Related

C :: How To Make Function Which Gives Back Two Numerical Values

Nov 3, 2014

How make function which gives back two numerical values. I think needs using structure. now i try found my c book.

View 3 Replies View Related

C++ :: Floating Point Numbers / Numerical Analysis

Oct 30, 2013

I have the problem of trying to find the smallest natural number that makes two consecutive terms in single precision floating point notation in the riemann zeta function equal. So basically the riemann function of 2 is given by:

sum of 1/(k^2) from k=1 until infinity, so : 1/(1^2) + 1/(2^2) + 1/(3^2) + ...... until infinity.

Now the question asks to stop at the smallest natural number n, at which the sum 1/1^2 + 1/2^2 + ......+ 1/(n^2) is equal to the sum 1/1^2 + 1/2^2 + ..... + 1/((n+1)^2) in single precision floating point notation.

Now well the obvious way to look for n would be on this way:

float i = 1.0;
float n = 1/(i);
float n1 = 1/(i+1.0);
while ( n != n1){
i += 1.0;
n = 1/i;
n1 = 1/(i+1.0);}

But first of all this is obviously completely inefficient and I dont think it will yield a valid answer for any float variable, i.e. I dont think the sum until 1/n^2 and 1/(n+1)^2 will ever differ. I tried it out with the largest possible value of a variable of type float and the values were still seen as unequal in C++. How to do this? Will C++ find a value for n for which the condition holds? Is the compiler or my hardware important for this, i.e. would I get different results on a different pc?

View 2 Replies View Related

C/C++ :: Infinite Loop If Non-numerical Character Entered

Jul 28, 2014

it will produce the answer above..when user enter a nonnumerical character it will force the user to reenter again

do {
cout<<"Min of the secret number : ";
cin>>min;
}while(cin>>min);
cout<<"Max of the secret number : ";
cin>>max;

this is my coding but it will auto jump out when i enter non-numeric character

View 7 Replies View Related

C :: Sorting Array Of Integers Between Two Positions Of Array

Apr 18, 2013

I am trying to create a code to sort an array of integer, but only between two positions of the array, not the all array.

like this:

array: 1 2 5 4 7 2 9 8
index: 0 1 2 3 4 5 6 7

i want to sort the array per exemple between the the index 2 and 5.the result is... array: 1 2 2 4 5 7 9 8

View 2 Replies View Related

C++ :: How To Create A Large Matrix To Be Solved Using Numerical Methods

Jun 24, 2013

I am having a problem on how will I create a large matrix to be solved using numerical methods. Say I have a 500 x 500 matrix and want to find these 500 equations. How will I do it? To be exact, here is a sample problem

| -2 1 . . . . . . . || x1 | |h^2|
| 1 -2 1 . . . . . . || x2 | |h^2|
| 0 1 -2 1 . . . . . || . | | . |
| 0 0 1 -2 1 . . . . || . | = | . |
| . . . . . . . . . 1 || . | | . |
| . . . . . . . . 1 -2||x500| |h^2|

Where h = 1/(n + 1)

Solutions on finding would be gauss elimination, Successive overrelaxation, Jacobi Iteration, biconjugate gradient method and Thomas algorithm. I want to compare the accuracy, with tolerance of 10^-6

View 2 Replies View Related

C++ :: Number Of Characters / Operators / Uppercase Letters And Numerical Digits

May 5, 2014

I have to code a simple program who determining the number of Characters (A character could be any alphabets, digits, punctuation marks, or special , Operators ( Operators are those symbols that are used in mathematica expression, such as,'+', '*', '/', '-', and so on.), Uppercase letters (Uppercase characters are those from A..Z) and Numerical digits ( A digit is any of the Hindu-Arabic numerals from 0..9). Why the output is wrong!

#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std ;
int main() {
char text;

[Code] .....

This is my input file This is a possible factorial function in a programming language called LISP

(defun factorial (n)
(if (< n 2)
1
(* n (factorial (1- n)))))

This is my output:

The number of characters = 113
The number of operators = 3
The number of numerical digits = 3
Uppercase letters = 5

I think that "characters" is wrong, but I do not know why !

View 4 Replies View Related

C++ :: Sorting Values In Array?

Feb 8, 2015

I tried sorting arr2 from lowest to highest value, but it only gives me 4 values and then the rest are zero.

Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << fixed << setprecision(1);

[code].....

View 1 Replies View Related

C :: Selection Sorting A 2D Array

Feb 13, 2013

Selection sorting a 2D array . Let's say i have an array like

1 2 3 4 //4 elements
1 2 // 2 elements
1 2 3 4 5 //5 elements
1 2 3 //3 elements
1 //1 element

And I want to do a selection sort it in descending order which the row with 5 elements will come first then 4 then 3 and so on. So that it would look like this

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Code:
void selectionSortDescending(int list[MAX_ROW], int size){
int temp;
int walk;
int curr;
int large; // index of the largest element

for (walk = 0; walk < size - 1; walk++)

[Code] ....

View 7 Replies View Related

C :: Sorting Array Of Size 10

Nov 18, 2013

I am trying to sort an array of size 10. If I was given:

Code: int List[Size] = {29, 11,12,10,3,26,13,15,19,2};

I need the program to sort all the odd integers and put the even integers to the back of the array. Like so:

Index: 0 1 2 3 4 5 6 7 8 9
Value:29 11 3 13 15 19 12 10 26 2

And it returns the number of even integers in the List. In this case it returns 4. All I am given to start with is

Code:
int evensToRead(int* const List, const int Size){
//body
}

View 1 Replies View Related

C :: Sorting 2D Array By Column

Oct 24, 2013

i have a matrix containing a lot of points and each point has its coordinates x and y. That is a nx2 size array. I want to sort it according to the first column ascending, with x coordinates. For points that have the same x coord i would like to sort according to y coord. Here is what i did and i cannot get a good result.

Code:

#include <stdio.h>
#include <stdlib.h>
int main(){
int a[5][2] = {{1,0}, {4,2}, {2,4}, {8,6},{4,8}};
int temp=0;
int i=0;
int j=0;

[Code]...

View 4 Replies View Related

C++ :: Sorting A Structure Array

Jan 22, 2013

i need to print the names as they appear in the original file, print the info of the person with the highest distance, print the info sorted by ascending ID number, and print sorted by name alphabetically. the first two parts work fine but sorting by ID and Name dont work.

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string.h>
#include <math.h>

[code]....

View 1 Replies View Related

C++ :: 2D Array - Sorting Diagonally

Jan 3, 2014

I have a question about sorting a 2D array. Lets suppose I've got the following array:

2 5 7 4 8

3 11 14 5 2

6 3 12 9 1

7 15 11 4 2

8 16 13 5 1

I would like to sort this array diagonally to make it look as : [URL] ....

View 10 Replies View Related

C# :: Sorting 2 Dimensional Array By Value

Jan 9, 2014

Here is what I have, I have a 1D Array being added to a 2D Array and I need to Sort them by value value 3 in the 2D Array, while maintaining a specific amount. Here is what I have so far:

public static void CheckHS(string[] HS) {
try {
GeneralData.HighScores[10, 0] = "11";
GeneralData.HighScores[10, 1] = HS[1];
GeneralData.HighScores[10, 2] = HS[2];
GeneralData.HighScores[10, 3] = HS[3];
//Need Sort Data - Bubble Sort?
}//end Try
catch (Exception ex) { MessageBox.Show(ex.Message); }
}

I am thinking bubble sorting but I remember reading about something faster. Unfortunately I can't find it on the web. The idea is that there will be always 10 Values and 4 Columns on the 2D Array. [The 11th Row being empty at the end of it.

View 14 Replies View Related

C/C++ :: Sorting 2D Array Diagonally?

Jan 3, 2014

How to sort a 2D array diagonally? Lets suppose I've got the following array:

2  5  7  4 8
3  11 14 5 2
6  3  12 9 1
7  15 11 4 2
8  16 13 5 1 

I want to create a function that sort them diagonally like this: [URL] .....

View 7 Replies View Related

C :: Sorting Elements In 2D Array By Their Index

Jun 17, 2013

I need to sort the elements in a 2d array by their index (starting from 1) for example:

Code:
1 5 3
4 7 8
4 10 2

10 is the biggest element and its index is 32, after 10 comes 8 with index 23 etc etc...

Looking for examples for two orders ... By descending and ascending order...

View 5 Replies View Related

C++ :: Linked List Or Sorting An Array?

Feb 2, 2015

I have an algorithm and I want to make it as efficient as possible. Basically it just involves putting numbers in order. I have two options, but which one would be more efficient:

1. Using a doubly linked list. Every time a user wants to add a new number, the algorithm will start searching the correct place for the number from the beginning of the list. This is efficient per se, but once there are about a million numbers and a number has to be put in at the end of the list, the algorithm must go through all the 999 999 numbers before it.

2. Using a container to store all the numbers first, then sorting the numbers. In this case, adding all the numbers is fast, but the actual sorting will take a long time.

Which option would be more efficient? I was thinking of using maybe merge sort or quick sort in option 2. Yes, I'm aware I could just use vector and sort, but that's not my goal here.

View 4 Replies View Related

C++ :: Sorting String Array Alphabetically

Nov 7, 2014

I wish to sort a string array alphabetically and im not sure if i am doing it right. for example:

string a[5]; //initial array
string b[5]; //sorted array
int index = 0; //index of b array

for (int i = 0; i < 5; i++){
for (int j = 0; j < 5; j++){
int c = 0;

[Code] ....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved