C++ :: Bubble Sorting With User Defined Amount Of Elements

Feb 25, 2014

I am writing some code to bubble sort a list of randoms numbers, 10 at the moment. I want to be able to user input the amount of elements that would be sorted. I think i'd have to use vector instead of arrays, but unsure how to do this. Or, how to be able to change the size of the array.

#include <iostream>
using namespace std;
#define SIZE 10

float numbers[SIZE];
int move_n;

[Code] ....

View 1 Replies


ADVERTISEMENT

C++ :: Sorting User Defined Amount Of Random Numbers In Ascending Order

Jan 30, 2013

I want to implement a function into the code below that sorts the user defined amount of random numbers and then sorts them in ascending order.

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <string>

using namespace std;
class IntegerArray {

[Code] ....

View 5 Replies View Related

C++ :: Store User Input In Array And Calculate Mean / Median And Mode - Bubble Sorting

Mar 26, 2014

I'm trying to make a c++ program of this but i don't know how to use the bubble sorting.

Write a C++ application that asks the user to enter 10 numbers. The program then stores those numbers in an Array. The program should display the Mean , Median, and Mode.

Mean is the average of the 10 numbers.
Median is the average of the 5th and the 6th numbers. (But you have to arrange the numbers in ascending order first using Bubble Sort before calculating the Median.)
Mode is the most frequent number among the 10 numbers.

View 5 Replies View Related

C++ :: Sorting Strings / Arrays In A User Defined Lexical Order?

May 7, 2013

I previously tried to put strings in an array, but i couldn't modify the first index in the string that is in the array. I changed my code later.

[URL]

Suggest a function that sorts the inputs vertically according to the order given by the user? I made this one

void order(string order, char index[][15]){
int counter=0,line=0,i=0,j=0;
for(i=0;i<=15-1;i++)
{for(j=0;j<=15-1;j++) {
if(index[j][i]==order[counter])

[code].....

View 1 Replies View Related

C++ :: Sorting Array Of 10 Elements Provided By User?

Jan 21, 2014

So I'm trying to sort an array of 10 elements provided by the user. For Example:

Person 1: 5
Person 2: 3
Person 3: 9
etc etc...

I want it to also pair the value with the person. So it should read:

person 3: 9
Person 1: 5
Person 2: 3

Sort the values in descending order.

I can sort the array, but I cant get the Person number to pair with the value...

View 4 Replies View Related

C++ :: Bubble Sorting Of Strings

Sep 20, 2013

I have to read data from a text file, load it into an array and then bubble sort it! Here is my code:

Code:
#include <iostream>
#include <string>
#include <fstream>

[Code]....

Basically what i am trying to do is that sort the names of 10,000 movies and then write those names to a text file. It gives an error in the nested loop by underlining arr and tells that no suitable conversion function from std::string to const char* exists.

View 5 Replies View Related

C++ :: Sorting Golfers Using Bubble Sort

Oct 29, 2013

I have to sort golfers using bubble sort. Here my code:

#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
void tellUser();
double calcAvg( int, int, int, int, int &);
void swap( int &num1, int &num2);

[Code] ....

View 2 Replies View Related

C++ :: Bubble Sorting With Function Templates

Jun 21, 2013

i'm new to C++ i came across this bubblesort program earlier relating to class templates i was wondering how to make this into simple function templates

#include<iostream>
#include<iomanip.h>
#include<conio.h>
#include<stdio.h>
using namespace std;
template <class t>
class bubble

[Code] ....

View 3 Replies View Related

C++ :: Sorting And Searching With Bubble Sort?

May 15, 2014

I'll make a program that consists of "sorting and searching." To cope with the task, it should contain this: Create a field containing 50 random numbers, sort them by a method sort according to Bubble sort and then out the field before and after sorting. [URL]

View 1 Replies View Related

C++ :: Bubble Sorting A Classed Array

May 8, 2014

I'm really struggling with bubble sorting a classed array(an inventory). I understand bubble sorting in theory and implementing it into a static array makes sense. When I get to doing it in a classed array then I struggle. I need to sort the weight by bubble sort (then selection sort for name, and insertion sort the cost; but I want to tackle one problem at a time.

Here is the code:

#include <iostream>
#include <iomanip>
#include <conio.h>
#include "Inventory.h"
#define MAX_REC 10
using namespace std;
//Class to hold inventory variables/funcitons

[Code] ......

View 6 Replies View Related

C++ :: Sorting Array With Double Bubble?

Feb 3, 2013

i wanted to sort an array with double bubble sort but it didnt work!

my code is this:

void doubleBubbleSort(int *array, int length) {
int i,j;
for(i=0; i<length--;i++) {
if(array[i]>array[i++])
for(j=i;j>=0&&(array[j]>array[j++]);j--)
std::swap(i,j);

[code].....

how to get time like 1.56 seconds,too!

View 3 Replies View Related

C++ :: Bubble Sorting Array In Ascending Order

Nov 18, 2014

I'd like to modify this code so that there is 1000 numbers instead of 100, and that they're sorted in ascending order instead of descending order.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
double* sort_array(double* sort) {
for (int a=1; a<100; a++) {

[code]....

View 2 Replies View Related

C++ :: Sorting With Selection / Insertion And Bubble Sort

May 4, 2014

This program using the selection, insertion, and bubble sorts. The program needs to be able to do the following:

1. Create an array of 1000 population records when the array object is instantiated. Call it unSorted.

2.Open the file called "Population.csv" (on the portal) and invoke a function that loads the population data into the array.

3.Create a second array of 1000 elements that will be used to sort the data using the different algorithms. Name is sortedArray.

4.Write a function that will copy unSorted into sortedArray and execute that function.

5.Using a function, display the unsorted array.

6.Invoke the insertionSort () function that will sort the sortedArray using the insertion sort algorithm. Sort the population data on the rank field in ascending order. Alternatively, you can sort in descending order on population.

7.Using the display function, display sortedArray.

8.Display the number of iterations it took to do the sort using this algorithm.

9.Repeat steps 4-8 for the selection and bubble sort algorithms.

Here is my code so far:

Code:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void loadArray (int unSorted[], int s);
void displayArray (const int num [], int size);

[Code] .....

Here is a few lines from the Population.csv file contents:

Code:
Alabama,Baldwin County,140415,389
Alabama,Blount County,51024,908
Alabama,Calhoun County,112249,477
Alabama,Colbert County,54984,858
Alabama,Cullman County,77483,653
Alabama,Dale County,49129,927
Alabama,Dallas County,46365,974
Alabama,DeKalb County,64452,753

I'm not sure how to load the data from the file into the array properly, I attempted this. I also don't know how to copy the unSorted into sortedArray.

View 14 Replies View Related

C :: Bubble Sorting Failed - Prints A Blank Record

Feb 19, 2014

Well still working on my project, now the bubble sorting failed. For some reason the first slot in the array is empty and when I attempt to enter a record to access, it just crashes or prints a blank record. Here is my code for the viewing of the record and a SS of the empty array slot.

Code:
void searchRec(void) {
void Printing(int *ver, int *max);
FILE *fPtr;
struct Students vStudnt;
int set;
int ver;
int i = 0;
int fin = 0;
int sel;
char order;

[Code]...

Well I don't see why there is a empty slot, why?

View 6 Replies View Related

C++ :: Sorting Randomized Array Of Integers Using Bubble Sort Algorithm?

Jun 26, 2013

This program is sorting a randomized array of integers using the bubblesort algorithm.

I am trying to modify n correct the source code,so that the swapping of two values will be done by a function called swap values() by using call-by-reference but function should have as arguments only the two array elements that must be exchanged. (Note: do not pass the whole array to the function!) .We consider an array with the first element containing the number of elements in the array, followed by 10 randomly initialized integers (elements).

The code must sort the 10 elements in ascending order.

Compile: g++ -Wall sorting.cpp -o sorting
*/
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
const int SIZE=10;

[Code] .....

View 1 Replies View Related

C++ :: Bubble Sorting Linked List That Creates 100 Random Integers?

Feb 1, 2015

I am relatively new to C++ and am trying to bubble sort my linked list that creates 100 random integers. Everything works, but I am unsure how to continue this to include a bubble sorting method.

#include "stdafx.h"
#include <iostream>
using namespace std;
class Node{
public:
int data; //set data

[Code] ....

View 1 Replies View Related

C++ :: Import A File Containing Words And Numbers To Linked List - Bubble Sorting

Feb 16, 2013

I have a code able to import a file containing words and numbers to a linked list, but I also need to sort this linked list alphabetically. I've done research on this involving bubble sorting, but no explanationcan achieve this objective.

Below is the code that can only put the file into linked list:

Code:
#include<iostream>
#include<conio.h>
#include"U:C++WordClass2WordClass2WordClass.cpp"
#include<fstream>
#include<vector>
#include<string>
using namespace std;

[Code] .....

View 5 Replies View Related

C++ :: Sorting Array Of Numbers Into Ascending Order - Bubble Sort Keeps Crashing

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

C++ :: Bubble Sorting Vectors - Display Highest Temperature And Occurrence Time

Feb 12, 2013

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.

View 3 Replies View Related

C++ :: Sorting Elements Of Matrix

Jan 11, 2014

I wrote a code to sort elements of a matrix which are in one row,but it doesn't run well .what should i do??

Code:

#include <cstdlib>
#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
int main() {
int i,j,p,q,c1,c2,r1,r2,k,temp=1;
char ans1,ans2,answer;

[Code] ....

View 3 Replies View Related

C++ :: Create A Program That Will Let User Input Amount In Form?

Jan 4, 2014

Figure this out using [TURBO C]

Create a program that will let the user input an amount in the form (367). The Program should determine the no. of coins for each dominations : 50,25,10,5,1. (using Turbo C)

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 :: Sorting Elements In Lexicographical Order

Jan 30, 2013

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?

[Code] ....

View 2 Replies View Related

C++ :: Sorting Array Of N Given Elements Using Recursion?

Dec 29, 2013

I need to sort an array of n given elements using recursion. What am i doing wrong here?

#include <iostream>
using namespace std;
int i=0, j=1, v[100], n;

[Code].....

View 2 Replies View Related

C# :: (Grid) Stop User From Clicking Past A Certain Amount Of Block

May 21, 2014

0
down vote
favorite

So, I'm attempting to create a grid on the screen, and to do so, I've implemented a multidimensional array of Rectangles. When the program starts, I use a for loop to increase the x and y coordinates to form the grid.

public Form1() {
InitializeComponent();
for (int x = 0; x < 12; x++) {
for (int y = 0; y < 12; y++) {

[Code] ....

My issue is trying to figure out when the user has clicked on a rectangle, and furthermore, which rectangle in the array that he/she has clicked on. As I will change the border to red when given the correct rectangle.

I'm using Visual Studio 2008, and here is my code so far.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

[Code] .....

I'm making this into a real game, with classes and all.

View 7 Replies View Related

C :: User Defined Array Size

Jul 23, 2014

The instructions call for the user to define the size of the array and all I have ever done is use a predefined size for the array and then let the user fill it. Here is what I have so far:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void Display (void);
void random (int *, int);
void Ascending (int *, int);
void Descending (int *, int);

[code]....

View 7 Replies View Related







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