C++ :: Sorting And Tracking Index Program

Oct 10, 2013

I have been learning c++ for about 1 month. So my problem is that suppose i have array[6]={10,-1,3,54,2,12}

I want to fill new array with {1,4,2,0,5,3}

because -1 is the lowest and its index is 1
2 is the lowest and its index is 4
3 is the lowest and its index is 2
10 is the lowest and its index is 0
12is the lowest and its index is 5
54 is the lowest and its index is 3

I want to sort from lowest to highest but using the index value. Here is what i have but the output i get is {1,4,2,4,5,5}
1,4,2 is right but then its wrong.

#include <iostream>
using namespace std;
void swap(int& v1, int& v2);
int main() {
const int size = 6;
int arry[6]={10,-1,3,54,2,12};
int sortedArry[6];

[Code] ....

View 1 Replies


ADVERTISEMENT

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++ :: Tracking Prices Of Some Asset Over Time

Feb 28, 2013

You are tracking the prices of some asset over time. The user will input a series of floating-point prices (e.g. 16.105 for sixteen dollars, ten and a half cents). When the user enters the price 0 (zero), output the overall minimum, mean, and maximum prices. Hint: there could be thousands or millions of prices to process, so do not try to store each one as it arrives, but keep a running total..

I've been using a while loop for user input, but I don't know how to get the last 0 that marks the end of the list to not be included in calculating the average.

View 4 Replies View Related

Visual C++ :: Toolbar Position Tracking

Apr 19, 2013

How to detect when mouse pointer entering on toolbar .

View 2 Replies View Related

C++ :: Back Tracking And Goto Functions

Apr 27, 2012

I have a project where I have to schedule 3 doctors for 28 days. Doc A, B, and C. The rules are:

1. They can't work back to back, but only on weekends. Example Doc. A can't work Monday and Tuesday, If Doc. A works Saturday, he must work Sunday also.
2. Doc. A and B work alternate weekends.
3. Doc. C can't work Tuesday or weekends.

I'm trying to base my project off of the 8 Queens program that uses backtracking and the goto function. Right now, I'm just trying to get my program to print this

100100100
010010010
001001001

Here is my goto Code

#include "stdafx.h"
#include <iostream>
#include<iostream>
using namespace std;
void print();
#define n 28 //28 day schedule
int a[n]={};

[Code] ....

If you look at my code you will notice that it prints out like this, where array c doesn't take in account for array a.

1010101010101
0101010101010
1010101010101

I need getting the program to modify a[], b[], and c[] when necessary. I should be able to change any array element to '1' and it will automatically fill in the schedule by itself. example

010001000101001
100100101010010
001010010000100

View 13 Replies View Related

C++ :: Tracking From What Class Functions Called At Runtime

Feb 23, 2015

Is there any way to track what functions from what class are called at runtime? What I mean is a list of functions or classes which have been called at runtime.

View 1 Replies View Related

C++ :: Program To Search Index File Using Command Line In Linux

Oct 28, 2014

I have code that creates an index file created from a data file of records.

#include <iostream>
#include <fstream>
#include <map>
#include <sstream>
#include <string>
#include <iomanip>
using namespace std;
class Record {

[Code]...

I now need to write a second program that allows the user to enter a command on the Linux command line such as

search 12382 prog5.idx

and returns the information for the record with that key. The code I included for the index file is correct and works properly, but how to write the second program.

Here is the index file created by the first program:

8: blank 0 $ 0.00
12165: Item16 30 $ 7.69
12345: Item06 45 $ 14.20
12382: Item09 62 $ 41.37
12434: Item04 21 $ 17.30
16541: Item12 21 $ 9.99
21212: Itme31 19 $ 8.35
34186: Item25 18 $ 17.75
41742: Item14 55 $ 12.36

The top line is a dummy record, the first number is the size of the file.

View 19 Replies View Related

C/C++ :: Program To Find Index Of Character In A String Gives Incorrect Output

Oct 28, 2014

I've been typed out a C program to let the user define the size of their string , and key in characters for this string , the program would then prompt the user for a character to search for in the string and return it's index value. Eg. Index of c in abc is 2. My code is as shown:

#include<stdio.h>
#define SIZE 20
int search(char x[SIZE+1] , int n , char s);
int main(void){
char x[SIZE+1] , s;
int n , index;

[Code] ....

However , after I key in my characters for the string , the program does not prompt me to input a character to look for, it just prints it out and returns some funny number. But the program works just fine is I move this portion to the top :

printf("Enter alphabet to find: ");
scanf("%c",&s);

View 1 Replies View Related

C++ :: Number Sorting Program - Getting Correct Numbers

May 10, 2014

I am a beginner at C++, the output is pretty self explanatory. I'm trying to make a number sorting program with other features, but the numbers are all wrong.

Code:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

[Code] .....

Input.DAT
Code:
376 389 450 735 600 576 612 700 450 628 778 389 667 500 475 550 687 791 829 344
549 476 400 587 535 657 789 583 340 764 422 826 566 436 565 834 533 423 837 701
847 521 746 356 582 465 493 593 425 421

I can't for the life of me figure out why the numbers are all messed up.

View 5 Replies View Related

C++ :: Stock Market Program - Sorting With Vectors

Sep 29, 2013

I'm writing a program of a stock market where i read from a file and sort with symbols and percent gain/loss. I have completed sorting with symbols but having trouble establishing the percent gain loss. First i designed and implemented the stock object. call the class stockType. main components of a stock are the stock symbol, stock price and number of shares. Second we have to create a list of stock objects. call the class to implement a list of stock objects stockListType. To store the list of stocks, i declared a vector and called the component type of this vector stockType. Because the company requires me to produce the list ordered by percent gain/loss, i need to sort the stock list by this component.

However, i'm not to physically sort the list by component percent gain/loss; instead i should provide a logic ordering with respect to this component. To do so i added a data member, a vector to hold the indices of the stock list ordered by the component percent gain/loss and i called this array indexByGain. I am going to use the array indexByGain to print the list. The elements of the array indexByGain will tell which component of the stock list to print next. I have trouble going about how to implement the function sortStockGain(). Below is my entire code and the txt file. I have sort symbols working but dont know how to implement the sort by gain.

Below is my entire code:

[#ifndef STOCKTYPE_H
#define STOCKTYPE_H

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
class stockType

[Code] ....

View 4 Replies View Related

C/C++ :: Sorting Program That Sorts Numbers From Least To Greatest

Jul 5, 2014

I have to write a program that sorts numbers from least to greatest. The way that it has to sort them is:

1) The program assigns the first number to be a minimum
2) If the next number is less than the minimum is now that number and they switch places. (We keep on looking if the number next to it is not smaller)
3) The program also gets the index of the minimum number
4) We keep on going until it is in order.

// Sort.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
void Sort(vector<int>&input);
int _tmain(int argc, _TCHAR* argv[]){
vector <int> input;

[Code] ....

View 4 Replies View Related

C :: Array Sorting Program That Works With Recursive Function

Mar 10, 2013

i want to write an array sorting program that works with recursive function.but i can not do it.

my algorithm

Recursive
find the min value
find the min value and save it
find the min value and save it and remove it from loop
put the rest in loop again
find the min value again
..
...

i didnt write the function because i dont know how will it work

Code:

#include<stdio.h>
#include<stdlib.h>
#define s 5
void main() {
int a[s]={25,3,2,4,1},c[s]; // c[s] for new sorting
int i,ek,j; //ek = min

[Code]....

View 7 Replies View Related

C :: Sorting A Linked List - Program Abruptly Terminates?

Nov 29, 2014

I was trying to implement sorting in a linked list. However, when i run the sortList() function the program abruptly terminates. Here's the complete code:

Code: /*
* {
* SingleLinkedList.c
*
* Created on: 28-Nov-2014

[Code].....

View 3 Replies View Related

C/C++ :: Sorting Algorithm Program - Split Given String On Commas

Feb 21, 2014

I'm currently trying to code a sorting algorithm program.

let's asume I have a string given: aa, aaa, bbb, bas, zya!

I first of all want to split the given string on commas and '!' tells the program the string ends here and is no part of the last word. lower and upper case is not important at the moment. trying to implement everything with standard libary

output should be like that ofc:
aa
aaa
bas
bbb
zya

I already looked into the bubble sort algorithm and I think it benefits my needs. Just wanted to know how I should start out with the string split.

View 2 Replies View Related

C++ :: Sorting Program That Uses Variables From Another Class - List Not Declared In This Scope

May 13, 2014

I've got this sorting program that uses variables from another class but I'm not sure why its not recognizing it. I'm getting an error length and list not declared in this scope.

#include <iostream>
#include "arrayListType.h"
using namespace std;
template<class elemType>
class orderedArrayListType: public arrayListType<elemType> {

[Code] ....

View 1 Replies View Related

C++ :: Hash Table Program - Sorting Pointer Table After All Of Values Entered

Nov 19, 2013

I am having an issue with my sort function. This is one part of the Hash table program. The main issue is that I am trying to sort the pointer table after all of the values have been entered. The ptr_sort function is not a class function and so I am therefore unable to use the class variables psize and pTable. Is there another way I should be trying this? it is a Vector should I use the sort() function from the vector class in STL?

#include "/home/onyuksel/courses/340/progs/13f/p9/util9.h"
#include "/home/onyuksel/courses/340/progs/13f/p9/hTable.h"

#ifndef H_TABLE1
#define H_TABLE1
void ptr_sort ( );

[Code] ....

View 1 Replies View Related

C :: Array Out Of Index

Apr 17, 2014

I was trying to debug a code which was behaving in an abnormal way

Code:

#define NOOFELEMENTS 32
unsigned char array[NOOFELEMENTS];
unsigned char array1[23];
init() {
for(i=0;i<=32;i++)
{
array[NOOFELEMENTS] = 0
}
}

I could trace the above one of the mistakes where the array initialization is crossing the array limits and writing into array[32] which is not available. My question does it overwrite into array1 as it is declared below array or it can write into any other location.

View 4 Replies View Related

C++ :: Input Value Get Index

Sep 9, 2014

I am trying to get the index of a value by inputting the value:

For example if i have

int arr[5]={22, 85, 58, 78, 69};

indexOfItem(arr, 78);

and have the output be:

the index of the item is: 3

View 3 Replies View Related

C++ :: Row And Column Index?

Dec 16, 2013

If i have current index and row/columns count how do i get on which row and on which column index is individually?

This is what i have tried, but column index is incorrect:

#include <iostream>
int main()
{
int rows = 5;
int colm = 6;
int inx = 12;
int rowInx = inx % rows;
int colInx = inx % colm;
std::cout << "row: " << rowInx << std::endl;
std::cout << "col: " << colInx << std::endl;
return 0;
}

View 4 Replies View Related

C# :: Index Out Of Bounds Error

Jun 27, 2014

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Chapter7Problem13

[Code] .....

I keep getting an out of bounds error in my code

I'm suppose to enter number of orders then enter those orders then calculate a discount and net price display the orders, discount, net price then the totals at the bottom ....

View 5 Replies View Related

C :: How To Get Index Of Structure Elements

Apr 9, 2013

I want to get the starting index of structure elements, whoz id are 0,1,2,3 Like in below code col_data[0] (starting id=0) col_data[3] (starting id=1) col_data[5] (starting id=2) col_data[8] (starting id=3) Code:

Code:

typedef struct gg{
int id;
int value;
}

[code]....

How can i skip remaining loop iterations when it get that index and will go back to loop again for getting next element index?

View 7 Replies View Related

C++ :: Determining Index To Place New Value

Dec 9, 2013

I need function to determine where to place new element in sorted array. I want to use binary search to find index where element should be placed, when push all others.

Prototype should be something like

int WhereToPlaceElement(ElementType hash); // uses private atribute ElType** elements

I have tried my best to write, but all tries ended in inf loops and reading invalid locations of array.

View 3 Replies View Related

C++ :: How To Use One Index To Iterate Between All The Values

Sep 6, 2013

How can I use one index to iterate between all the values

for example:

//I defined
vector<typeA> VA(XD,typeA());
vector<typeB> VB(XD,typeB());

//then the standard method to iterate is:
for(vector<typeA>::Size_type i=0; i<VA.size(); i++) {
VA[i].functionA();
VB[i].functionB();
}

the other way, use int,

//I defined
vector<typeA> VA(XD,typeA());
vector<typeB> VB(XD,typeB());

//then the standard method to iterate is:
for(int i=0; i<VA.size(); i++) {
VA[i].functionA();
VB[i].functionB();
}

none of above make me feel formal...

View 7 Replies View Related

C# :: Index Was Outside Bounds Of The Array

May 21, 2014

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mind_Puzzle {
public partial class Form1 : Form

[Code] .....

When i try to start it, it doesn't start or it gives an error on "UsedList[i] = false;".

The error: "An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Mind Puzzle.exe

View 1 Replies View Related

C# :: Array Index Management

Oct 27, 2014

I am suppose to make a value to attach to a array and then have it stop on the last one with an error if it were to go past (done more or less).

Problem is I am suppose to use a int to hold the value of the array and then add 1 each time but my question is, if you were to add another number to increase your current array slot, what would that look like as I image that going array[0] + 1 isn't going to make it array[1].

View 3 Replies View Related

C++ :: Return A Pointer To The Character At The Index Given

Nov 5, 2014

I need understanding the logic behind this function. The function is supposed to "Return a pointer to the character at the index given" . For example, what exactly are we declaring at "(char * const c, int index)"? where does "index" come from or equal to in the body of the function?

Code:
1
2
3
4
5
6
7
8

char * GetValueAtIndex(char * const c, int index)
{
int i = 0;
char *p = c;
while (i++ != index)
p++;
return p;
}

View 2 Replies View Related







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