C++ :: Item Search Based On 2 Values For Index?

Apr 4, 2013

I have to be more code specific (I usually try to abstract my code). As you can see I use a lot Qt classes... however they work very similar to standard libraries, so it should be not a problem to look at this question.

class FrameManager {
QList<FRAME> frameData;
public:
int frameID(int grpno, int imgno);
};

[Code] ....

Now I know the example search only the ID and doesn't allow the access of the actual data... this is not the question.

The problem is... I will need to define an AnimationManager class that will collect sequence of frames (identified by the unique couple of value) in animations... so it will need to use a massive search of item from the couple of value (and not ID, unluckly)

I fear if I use an approach similar to the one written in the example (search from the start to the end until the element is found) can be very unefficient.

In the same time the AnimationManager should always know if frame exist or not (if not exist an invisible image will be shown) and if in the meantime changed.

Another problem is that I cannot order the data sequence inside FrameManager (becouse it is expected to mantain the original order, even when it is chaotic).

I tried to take a look around QMap (or std::map) but it is not clear at all how the optimiziation works and how I can use it in my case

I tried also to take a look at the "hash" concept, but for me it is too complex to understand deeply.

So... I am feeling like I am entrapped... I am unable to find a good "exit"...

View 8 Replies


ADVERTISEMENT

C++ :: How To Search For An Item In The Array

Jun 29, 2014

If the item is in the array. Count how many times it is stored in the array and what are their respective array locations.

How can I add this output in my program.

Here's my code...

int array[15]={28,3,16,4,3,16,5,8,4,12,5,4,8,21,40};
int x=0;
int done=0;
int item;

cout<<"Input an item to be searched:";
cin>>item;

[Code] ....

This should be the output:

Item to be searched: 4
number of occurence : 3
array locations : 3 8 11

View 3 Replies View Related

C/C++ :: Find Non-key Item In Binary Search Tree

Apr 16, 2014

I am creating a menu-driven program which creates a small database using a binary search tree. I am having issues with the last method I need for the program. The way it is coded now only gives me blank data when I print it. Here is the exact wording for the requirements for this method:

"Output a complete report to the text file named BillionaireReports.txt in increasing order by billionaire rank, that contains all data fro each record stored in the BST. Note: this is not a simple traversal. You may assume that the rank is never less than 1 and never greater that 500. Do NOT copy the data into another BST, into an array, into a linked list, or into any other type of data structure. Retrieve the data directly from the binary search tree which is stored in order by name."

Here is the method in question:

void BillionaireDatabase::displayRankReport() {
int i = 1;
for(i; i <=500; i++) {
billionaireDatabaseBST.contains(Billionaire& anItem);

[Code] ....

I know how to sort the database by the key, but I'm not sure how to sort by something that is not the key.

Here are the functions I have available via the BST (these were written by the professor)

//------------------------------------------------------------
// Constructor and Destructor Section.
//------------------------------------------------------------
BinarySearchTree();
BinarySearchTree(const ItemType& rootItem);
BinarySearchTree(const BinarySearchTree<ItemType>& tree);
virtual ~BinarySearchTree();

[Code] ....

View 3 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 Sharp :: How To Make Search Based On Categories

Nov 6, 2012

I have three tables (company,department and employee). Company table has two rows (CompanyID, CompanyName). Department table has four rows (DeptID, DeptName, CompanyID, EmpID). Employee table has three rows (EmpID, EmpName, EmpAddress).

I want to search by Departments For example I want to have one Checkbox named Department if I checked Department it should show me all the available departments in the Company so if i select a particular department it should show me all the employees that they belong to the department that has been selected.

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 :: Order Values Of Int Array Only Between Two Index Numbers

Mar 16, 2013

I have 2 arrays, one of doubles and other of integers, the doubles have the result of division of two numbers and the array with the ints have numbers that will refer to another array, but it is not important for this problem.

An example:
doubles array: (12,44;12,44;7,22; 12,44)
ints array: ( 4 , 2 , 3 , 1 )

now using my quicksort function i will organize the array of doubles from the higher to the lower, and the ints array will follow the order of the doubles array, the result is :

doubles array: (12,44;12,44;12,44; 7,22)
ints array: ( 4 , 2 , 1 , 1 )

Well, when i have values in the doubles array that are equal, i need to check the ints array and order the ints values, but only the ints that in the doubles array are equals, the final result will be:

doubles array: (12,44;12,44;12,44; 7,22)
ints array: ( 1 , 2 , 4 , 1 )

How i can order the ints array only between an interval that is given by the interval of numbers that are equals in the doubles array?

View 4 Replies View Related

C++ :: For Loop To Find Index Values - Reference List

Mar 18, 2013

im using a for loop to find the index values of the tied high scores and store them into string list then reference list in the second for loop to output it to screen however it isnt letting me use an array with index i as an index its self.

void printHighest(Student s[], int length){
int index;
string list[10];//you're never going to have more than 10 people with a tieing highscore.
index = findMax(s, length);

[Code] ....

For the time being I simply removed the idea of string list and just put the contents of the second for loop into the if statement above it. However, I am still curious as to if I can reference an index of an array in an index of another array.

View 1 Replies View Related

C/C++ :: Sorting A File Based On ASCII Values?

Sep 1, 2014

New file_sorter.c:

#include <stdio.h>
#include <stdlib.h>
#include "sort.h"
#include <string.h>

[Code].....

My issue is now a segmentation fault in my sorting algorithm. In my assignment I was suppose to implement quick and insertion sort for the file, and organised strictly by ASCII values. We were allowed to look up generic algorithms for the sorts, but we have to convert them to comparing char arrays.

I haven't started trying to configure quick sort yet, but I'll supply the generic algorithm as well. keep in mind that the first line in the file contains the number of lines in the file. I'll try not to disappear this time!

sort.c :
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>

[Code]....

View 4 Replies View Related

C++ :: Incrementing Values In Vector Based On Variable Input

Mar 24, 2014

I'm trying to increment the values in a vector, not the vector size, based on variable input. Basically I have a vector of size 10, and all of its values are initialized at zero. The program counts the frequency of numbers 0-9 in a four digit user input. This is what I have (I want it to work so badly but the compiler says that I'm using a pointer to a function used in arithmetic):

for (int i=0; i < num_slots; ++i) {
++guess_frequency[guess[i]];
}

I just want to know if you can increment values within a vector:

E.g.
change
0 0 0 0 0 0 0 0 0 0
to
1 0 0 0 2 0 0 1 0 0

View 6 Replies View Related

C++ :: Sorting Some Data Based On Values Of A String Of Bits

Apr 1, 2014

I have a problem I am working on where I need to sort some data based on the values of a string of bits. The strings look like this,

010000001110000000

there are 18 bits, 1 means a feature is present, 0 means the feature is absent.

Each of these string has 4 on bits. I need to sort them such that I have the longest possible runs with 3 of the same on bits. It doesn't matter which 3 bits are on, I am just looking to order them in blocks with the longest possible runs. As a second step, the ordered blocks will be sorted by size large>small.

The following data is ordered like I need it to be.

Code:
// block 1, run of 12, keys 1,2,11 are identical (key 12 is also identical)
011000000001100000
011000000001100000
011000000001100000
011000000001100000

[Code] .....

This is the sort order that I am looking for. I need to be able to take a list of the bit strings in any particular order and sort them into the order above. The algorithm would need to recognize that there are 4 on keys and then look for groupings of three common on keys.

This is more of an algorithm question than one about specific implementation in code. I generally assume that most programming problems have been solved one way or another, so I don't know much about analyzing and manipulating strings of bits.

Is there a standard method for this kind of pattern recognition?

View 14 Replies View Related

C++ :: Create Matrix Of Data That Add Values Based On Reading Get From DVM

Apr 22, 2012

Ok I'm trying to create matrix of data that I can add values to based on a reading that I will get from a DVM. I'm using a 3d vector to do this. I need to keep track of the serial number, the day and within day I need to take two readings at different temps, this will continue for 7 days.

The rows of my 3d vector will be the days, the colums will be the serial numbers the depth will be the reading at the different temps.

What I need to do is compare the first element (days) and when it is greater then or equal to 4 I will perform calculations of the readings. So all I want to do is compare the first element of the vector, How do I do this?

Here is what I got

Code:
#include <vector>
typedef std::vector<double> Double1D;
typedef std::vector<Double1D> Double2D;
typedef std::vector<Double2D> Double3D;
#define HEIGHT 5
#define WIDTH 3

[Code]....

View 7 Replies View Related

C :: Search Table And Replace Values In Text File

Feb 3, 2015

I have to develop a C program that reads a very complex txt file (output of a calculation code, so full of mixed text and numerical tables), search for a specific table in it and individuate/print or replace a specific value with assigned position in the table.

View 2 Replies View Related

C/C++ :: Take Values From One Array And Searches For Their Index Position In Another Array

Dec 9, 2014

My program takes the values from one array and searches for their index position in another array (linear search algorithm). This is an example of the issue im having(its not part of the actual code below)

a[]={1,2,3,4,5,6}
Arr[]={1,2,2,3,4,5}

If it finds 1 in arr, it returns 0, which is fine but if it finds 2 in arr it return 1 and 1 instead of 1 and 2.

for (int q=0; q=size2;q++) {
int rs=secfunc(array1;size1;array2[q])
if(rs>=0) {
cout<<rs << "";

[Code] .....

View 4 Replies View Related

Visual C++ :: Enable / Disable Menu Item 2 In OnUpdate Handler Of Menu Item 1?

Sep 15, 2014

I have two menu items. When item 1 is disabled, I want item 2 to be disabled as well. In the OnUpdate handler of menu item 1, I have tried to use "t_pMenu = pCmdUI->m_pMenu;", "t_pMenu = pCmdUI->m_pSubMenu;" and "t_pMenu = pCmdUI->m_pParentMenu;" but I always get NULL t_pMenu. How can I achieve this purpose?

Code:
void CDummyView::OnUpdateMenuItem1(CCmdUI* pCmdUI)
{
if(m_bShowMenuItem1) {
pCmdUI->Enable(TRUE);

[Code]....

View 14 Replies View Related

C++ :: Search And Find The Shortest Queue And Search After Some Condition?

Mar 7, 2013

I am trying to implement a Task scheduler where i have n number of tasks. The Idea behind my task scheduler is that in a loop of queues of a vector, task should get enqueued to the shortest queue among the loop of queues, which is done by the following code.

#include <vector>
#include <queue>
std::vector<std::queue<int> > q
int min_index = 0;
task t // implemented in the other part of the program

[Code] ....

Next i am trying to extend this paradigm to reduce the overhead time of the scheduler, Instead of searching the shortest queue every time, search after some condition ie. search the shortest queue after 5 tasks gets enqueued to the shortest queue.

i need to do something like this

#include <vector>
#include <queue>
std::vector<std::queue<int> > q
task t // implemented in the other part of the program
while(q[min_index].size()!=q[min_index].size()+5) // check whether current min_index queue's size is increased 5 more times if not goto enqueue

[code].....

View 1 Replies View Related

C++ :: Binary Search And Sequential Search Algorithm

Sep 16, 2013

Write a program to find the number of comparisons using the binary search and sequential search algorithms

//main.cpp
#include <cstdlib>
#include <iostream>
#include "orderedArrayListType.h"
using namespace std;
int main() {
cout << "." << endl;

[code]....

View 4 Replies View Related

C++ :: Binary Search Or Linear Search For 3D Array

Oct 7, 2014

inputting a search array. I tried putting a binary search but I can't get it to work. everything else works up until I put the value I am searching for in the array, then it just crashes.

How it suppose to work: input 2 coordinates with a value each then it calculates the distance between them then it suppose to let user search the coordinates for a value and state if found which coordinate it is at.

#include "stdafx.h"
#include <iostream>
#include <iomanip> //for setprecision
#include <math.h>

[Code].....

View 3 Replies View Related

C :: Returning Value For Item To Variables?

Mar 4, 2014

What the code below is not doing is returning a value for item to my variables (item1, item2, etc..) I'm not sure how I can make a function prototype that will ask for input and basically recycle after going through the program to a new value for each item. I also need to input individual tax for each item. I will also post it in this message:

double tax, item,salesTax;
double cost(double);
double CalcSalesTax(double);
main(){
double total,item1, item2, item3, item4, item5, tax1, tax2, tax3,tax4,tax5;

[Code].....

View 13 Replies View Related

C :: Removing Item From A Queue

Aug 17, 2014

I'm having a problem with removing an item from a queue. At first in the debugger I got SIGTRAP but I don't get it anymore but the problem still exists. When you try to remove an item from the queue the first nothing happens. Here's the code below compile it and you see what I'm talking about.

Code:

#include <stdio.h>
#include <stdlib.h>
struct Node {
char let;
struct Node *nextNode;
};

[code]....

View 12 Replies View Related

C# :: Get Item From List In Another Class

Jan 15, 2014

How can I get the items from a list into textboxes. I am doing an windows form application in visual studio.

I have the first form with a couple of textboxes.

I want the inputs be saved in a list. And then displayed in another form. How to move on. The class with the list looks like this:

public class Casecs {
public List<caseInformation> fallInformation = new List<caseInformation>();
public class caseInformation {
public string caseId { get; set; }
public string phoneNumber { get; set; }
public string description { get; set; }
}

Then the form with the inputs in textboxes looks like this:

Casecs Casecs = new Casecs();
Casecs.fallInformation.Add(new ERIS.Casecs.caseInformation {
caseId = txtCaseId.Text,
phoneNumber = txtPhonenumber.Text,
message = txtMessage.Text
});

Then where I am stuck a form with some textboxes where I want the list items to be displayed:

public partial class btnDispatch : Form {
public btnDispatch() { }
public btnDispatch(List<Casecs.caseInformation> fallInformation) {
InitializeComponent();

View 7 Replies View Related

C# :: WPF Menu Item Not Clicking?

Nov 10, 2014

I have made a menuitem using the combo box, but when I add items in like in the image below:

[URL]

My problem is that when I move my mouse over the item it displays this darker box around the text:

[URL]

This stops me from clicking it and the code from being executed.

View 2 Replies View Related

C# :: Run SQL Query For Each Item In Listbox?

Aug 2, 2014

I have a C# WPF program that takes a SQL query and populates a column from an Oracle database into a listbox on the form. I would like to be able to compare all items populated in the listbox, and run a SQL query for each item, populating those values into a different listbox.

So far, I have this code:

string sql2 = "select unique apps.fnd_application_all_view.application_name, fnd_responsibility_vl.responsibility_name, fnd_form_functions_tl.user_function_name, fnd_form_functions.function_name, fnd_form_functions_tl.description, fnd_form_functions.type FROM fnd_compiled_menu_functions, fnd_form_functions, fnd_form_functions_tl, fnd_responsibility, fnd responsibility_vl, apps.fnd_application_all_view WHERE

[code]....

I would like to be able to basically take the "Responsibility_Name" value from the first listbox (lstResponsibilities), which is already populated, and use those values to in the "sql2" query to find the "Function_Name" and populate "Function_Name" in the second listbox (lstFunctions).

View 5 Replies View Related

C++ :: Erasing Item From A Vector

Oct 28, 2014

Here is the code,

vector<int> v;
v.push_back(4);
v.push_back(11);
v.push_back(34);
v.push_back(5);
v.push_back(14);
v.push_back(32);
vector<int>::iterator next;

[Code] ....

I got a debug assertion error. What might be wrong?

View 8 Replies View Related

C++ :: How To Display Item At Specific Tab Position

Nov 23, 2013

I used VB6 before to output file.

I set my output to file to tab(20) or tab(45) respectively.

In C++, how do I do this?

View 4 Replies View Related

C++ :: How To Insert Item Into Binary Tree

Jun 30, 2013

I am trying to write a function that inserts an item into this binary tree in C++.

template <typename T>
struct BTree {
T val;
BTree<T>* left;
BTree<T>* right;
BTree(T v, BTree<T>* l=nullptr, BTree<T>* r=nullptr) :
val(v), left(l), right(r) {}
};

Here's my attempt.

template <typename T>
void insert(BTree<T>* tree, T item) {
if (tree == nullptr) {
tree = new BTree<T>(item);
} else if (item < tree->val) {
insert(tree->left, item);
} else {
insert(tree->right, item);
} }

I think this function may not be working because I am modifying `tree`, which is a local variable. How do I actually modify the current pointer that `tree` represents, not just `nullptr`?

View 2 Replies View Related







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