C++ :: How To Access Vector Of Queues In Two Functions

Jan 20, 2013

I have the following code which will find the minimum size queue among a vector of queues and the minimimum size queue will enqueue(push) the int

std::vector<std::queue<int> > q
void enqueue(){
int min_index = 1;
std::size_t size = q.size();
for( i=2; i<size; i++) //accessing loop of queues
if(q[min_index].size() > q[i].size())
min_index = i; // Now q[min_index] is the shortest queue
q[min_index].push(int)
}

Now my another paradigm is to do the dequeue(pop) operation in another function(shown below), bt i need to access all vector of queues declared in enqueue() function. how can i access the loop of queues given in the enqueue() function?

void dequeue(){
//q.pop operation , access all the queues in the loop of queues
}
willq[i].pop(int);

Access all the queues in the enqueue function and does the pop operation?

View 1 Replies


ADVERTISEMENT

C/C++ :: Access Derived Classes Functions On A Vector

Jan 19, 2014

I need to access the functions of the derived classes from a vector of objects of base classes (can't believe I wrote it). Here a Diagram for you to understand:

So as you see, I need the function Use() from the Usable class, to be able to be called from the vector like:

inventory.at(x)->Use()

View 14 Replies View Related

C++ :: How To Search The Loop Of Queues Of Vector

Feb 14, 2013

i have a paradigm where a integer before gets enqueued to a queue, the loop of queues in a vector is searched and integer is enqueued to a queue which has minimum size among the queues. the following code shows the operation.

#include <vector>
#include <queue>
std::vector<std::queue<int> > q
int min_index = 0;
std::size_t size = q.size();
for( i=0; i<size; i++){ //accessing loop of queues
if(q[min_index].size() > q[i].size())
min_index = i; // Now q[min_index] is the shortest queue}
q[min_index].push(int)

next i am trying to extend my paradigm with that the condition the integers should be enqueued to the shortest queue until it becomes maximum size among the queues.

do{
q[min_index].push(int)
} while(q[min_index].size > queue sizes in the vector loop except this queue )

how to search the loop of queues of vector in the while ()

View 13 Replies View Related

C++ :: Increase Sizes Of Queue In A Vector Of Queues And Find Shortest Queue

Feb 20, 2013

I have a paradigm in a loop of queues of a vector,if a condition is true,increase sizes of the queue of that particular queue in the loop of queues, if condition is false, the queuesize is left as such in loop of queues. After this operation i need to search the queue sizes of all queues and enqueue in the shortest queue.

I want to do something like the code given below

#include <vector>
#include <queue>
int min_index = 0;
std::vector<std::queue<int> > q
std::size_t size = q.size();

[Code] ....

How to implement this logic?

will q[i].size=q[i].size+5 increase the queuesize by 5 for the ith queue?

View 12 Replies View Related

C/C++ :: How To Access Linked List Functions From Stack Class Without Functions

Mar 20, 2014

I'm a little confused by my programming assignment this week. I've been working at it Wednesday and I've made progress but I'm still confused as to how I'm supposed to do this. The class I made is called Stack, and it's derived from a template class called StackADT. We also utilize a class called unorderedLinkedList, which is derived from a class called linkedList.

We're supposed to implement all of the virtual functions from stackADT in the Stack class. The Stack data is stored in a an unorderedLinkedList, so what I'm confused by is how to implement a few of the Stack functions because there are no functions in unorderedLinkedList which we could call to manipulate the data.

As you can see from my attached code, I'm really confused by how I'm supposed to implement the pop() and top() functions, and I also think my initializeList() function is wrong. We don't have any similar functions in unorderedLinkedList to call, so I'm at a loss of how i'd access my unorderedLinkedList. My initial thought was to call the similar functions in the class that unorderedLinkedList was derived from, linkedList, but I'm unsure of this is what we're supposed to do, or if theres actually a way to access my unorderedLinkedList without having to use the functions from the base class.

NOTE: We're not allowed to modify stackADT, unorderedLinkedList, and linkedList.

Stack.h

#include "stackADT.h"
#include "unorderedLinkedList.h"
template<class Type>
class Stack: public stackADT<Type>{
template <class T>
struct nodeType
{
T info;
nodeType<T> *link;

[Code]...

View 3 Replies View Related

C++ :: How To Write Functions To Access Various Fields

Sep 16, 2013

Question: How can we write functions to access various fields?

Example: A phone number -- it has an area code, exchange & subscriber -> (123)-456-7890

How can we write a function to access the various fields of a phone number both in a particular class & in the main?

View 5 Replies View Related

C++ :: Get Access To Functions Of A Derived Class

Jul 11, 2013

I have a big problem with searching a solution for getting access on getters and setters of the derived classes of an interface.

Interface:

class IfParam
{
public:
IfParam();
};

Now I have a derived class for each needed datatype. E.g.

class Int32Param: public IfParam
{
public:
Int32Param();
Int32Param(IfParam* l_param);
int getValue();
void setValue(int l_value);
private:

[Code]...

My Problem now ist getting access to the getters/setters over the interface. I wish I could initialize the Params like this:

IfParam* param = new Int32Param();
param.setValue(12);

IfParam* param = new StringParam();
param.setValue("String");

But to have access to the getter/setter I have to declaire the functions in the interface as generic functions. But how? I tried to use temlates, but then i have to declaire IfParam as IfParam<int>. Thats a problem because in my original program I do not know which TypeParam the IfParam interface will be initialized with when I create the pointer.

View 7 Replies View Related

C/C++ :: Limit Access To Class Member Functions

Feb 28, 2014

Suppose I make a class, something like having the constructor being invoked first makes sense, I don't have a problem with that. But, how could I limit access to functions until certain functions are called? Perhaps this isn't built into the language so you can't. And maybe this problem never comes up. For example if you have a set() and get() functions, if they are both public functions, there doesn't seem to be a way for the compiler at least now if set() never gets called you shouldn't call get(). I just see this as error prone if you need to use libraries, you have to know not to do it from documentation instead of something the compiler can check.

View 11 Replies View Related

C Sharp :: How To Access Functions Between Two Child Forms

Oct 14, 2014

How can I access a function in a child form from another child form of a same owner?

View 1 Replies View Related

C++ :: How To Access Element Of Point3f Vector

Aug 4, 2013

How to access an element of the point3f vector. E.g. :

int main() {
vector<Point3f> a;
a.push_back(Point3f(0,0,0);
a.push_back(Point3f(0,0,1);

//print first x,y,z element
cout<<a[0]<<endl;

[Code] ...

But it doesn't work firstly because it says can't use typename i.e. <float>

View 8 Replies View Related

C++ :: Nested Class Vector Index Access?

Mar 22, 2014

Is it possible to pass the vector index '4' to the Height() function without passing it as a parameter of the function.

Basically, I'm trying to eliminate using 4 twice... what I'd LIKE the statement below to look like is this:

gx.Cell[4].Height();

The only way I can figure out how to get it to work is like this...

class grid{
public:
class CELL{
public:
int Height(int index); //returns the height of this cell

[Code] .....

View 8 Replies View Related

C++ :: Hash Tables And Queues

Jun 3, 2013

For my homework I need to create a hash table with a size of 7. I also need to create a queue that holds 3 names maximum for each table position

View 1 Replies View Related

C++ :: Calling Functions - Vector Of Pointers

Mar 27, 2013

I have a vector of pointers inside a seperate Exam class.

vector <Question* > question_list

The Question class is my base class in which I have derived sub classes for the different types of questions (MultipleChoice, LongAnswer, etc.). I am using my vector to hold the different types of questions.

in each of those classes I have virtual "write" functions in both the base and the derived classes, that write to a file differing for each type of question.

My problem now is calling the write function from a Exam function. I've tried several methods, such as:

for (size_t i = 0; i < question_list.size(); i++) {
question_list[i].write(testfile.c_str());
}

but it comes with two errors: "error C2228:left of '.write' must have class/struct/union" along with "IntelliSense: expression must have class type"

I have made a write function for the exam class as well but am not sure what it should include since the Exam class is not a derived class of the Question class.

View 15 Replies View Related

C++ :: Accessing Class Functions In A Vector?

Jul 24, 2013

How I can use class functions in a vector. I have 2 classes:

Gamemode class
bullets class

Inside the Gamemode class I declared: vector<bullets> Bullet and bullets * b.

If the user presses the shoot button a new bullets class will be added to the Bullet vector:

b = new bullets;
Bullet.push_back(b)

Bow I'd like to check all objects in the Bullet vector for the collision() function inside the bullets class.

I already set up a for loop which counts from 0 to the end of the vector:

for( int i=0;i<Bullet.size;i++)
{
}

My idea was to do something like:

if(Bullet[i].collision()) then erase Bullet[i]

But that doesn't work...

View 2 Replies View Related

C :: Ferry Loading Using Two Queues - Can't Enter In Data After First Set Is Scanned

Feb 25, 2014

I'm trying to solve the ferry loading problem using two queues. My problem is I can't enter in data after the first set is scanned in, I'm assuming there is a problem with my loop, such that the scan function doesn't get called after one iteration. In the example I marked the data I can't enter. An example correct input would be:

correct input:
1 - can enter data20 4 - can enter data
380 left - can enter data
720 left - can't enter data
1340 right - can't enter data
1040 left - can't enter data

correct output: 3

my incorrect output: 1

Code:

#include <stdio.h>
#include <stdlib.h>
#include "my_linked_list.h"
#include "my_linked_list.c"
#include "status.h"

[Code] ....

View 6 Replies View Related

C++ :: Queues Program Suddenly Stops Working When Input Value

Feb 22, 2013

I'm having troubles with this program I made. Put it simply, it's a basic program using Queues. Whenever I try to input a value, my compiler(Dev C) suddenly stops working. The .exe file crashes and I've no way on how I can execute my program.

Code :
#include<iostream>
using namespace std;
int *queue;
int rear, front, queueSize;
void enqueue();
void dequeue();
void display();

[Code] ....

View 1 Replies View Related

C++ :: Adding Additional Functions To STL Vector Class

Jan 30, 2013

How would I add my own function to the vector class?

View 3 Replies View Related

C++ :: Do Static Functions Have Access To Non Static Data Members Of A Class

Apr 17, 2013

From my book:

"A static function might have this prototype:

static void Afunction(int n);

A static function can be called in relation to a particular object by a statement such as the following:

aBox.Afunction(10);

The function has no access to the non-static members of aBox. The same function could also be called without reference to an object. In this case, the statement would be:

CBox::Afunction(10);

where CBox is the class name. Using the class name and the scope resolution operator tells the compiler to which class Afunction() belongs."

Why exactly cant Afunction access non-static members?

View 7 Replies View Related

C++ :: Access Private Data Of Base Class Without Access Modifier

Sep 9, 2013

if we don't provide the acces modifiers for base class and we need to manipulate the private data of base class in derived class. Is there anyway to acces the private data members? Here's a coding example

class A {
private :
int a;
};
class B : public class A {
public :
void displayA() { cout<<a<<endl; }
};

how i can acces the a of base class A in derived class B without acces modifiers.

View 16 Replies View Related

C/C++ :: Array Of Functions Pointing To In Class Functions With Arduino

May 3, 2013

At the moment im trying out with pointing to an array of functions. I got this working as following:

typedef void (* functionPtr) ();  
functionPtr functions[2][2]={{do11,do12}, {do21,do22}};    
void do11(){DEBUG_PRINTLN("11");}
void do12(){DEBUG_PRINTLN("12");}
void do21(){DEBUG_PRINTLN("21");}
void do22(){DEBUG_PRINTLN("22");}    
void loop(){
         A=0;
         B=1;
         functions[A][b]();
}  

But now I'm trying to use this to point to a function inside a class so instead of do11, i want to be able to point to Basic.Do11. Somehow this doesnt work and I keep on getting this message:

error: argument of type 'void (Basic::)()' does not match 'void (*)()'

View 2 Replies View Related

C++ :: Using Vector Push Back Function To Output Contents Of Vector (similar To Array)

Feb 9, 2015

How to output vector contents using the push_back function. My program reads in values just fine, but it does not output anything and I've been stuck on why.

here is my code:

#include <iostream>
#include <array>
#include <vector>
using namespace std;
int duplicate( vector < int > &vector1, const int value, const int counter)

[Code].....

View 3 Replies View Related

C++ :: Open File And Read In Rows To String Vector And Return Vector

Jun 7, 2012

I have a cpp app that reads in a number of files and writes revised output. The app doesn't seem to be able to open a file with a ' in the file name, such as,

N,N'-dimethylethylenediamine.mol

This is the function that opens the file :

Code:
// opens mol file, reads in rows to string vector and returns vector
vector<string> get_mol_file(string& filePath) {
vector<string> mol_file;
string new_mol_line;
// create an input stream and open the mol file
ifstream read_mol_input;
read_mol_input.open( filePath.c_str() );

[Code] ....

The path to the file is passed as a cpp string and the c version is used to open the file. Do I need to handle this as a special case? It is possible that there could be " as well, parenthesis, etc.

View 9 Replies View Related

C++ :: Create Class Vector As Template And Define Operations On Vector?

May 13, 2013

I need to create a class vector as a template and define operations on vectors.

And this is what I made.

#include<iostream>
using namespace std;
template<class T>

[Code].....

View 2 Replies View Related

C++ :: Recursive Function 2 - Create Vector Of Vector Of Integers

Mar 26, 2013

Lets say that I have a vector of vector of integers. <1,2,3,4> , <5,6,7,8>, <10,11,12,13>

How do I make a function that creates vector of vector of every different integers?

<1,5,10> , <1,5,11>, <1,5,12>, <1,5,13>
<1,6,10> , <1,6,11>, <1,6,12>, <1,6,13>
<1,7,10> , <1,7,11>, <1,7,12>, <1,7,13>
<1,8,10>, <1,8,11>, <1,8,12>, <1,8, 13>
<2,5,10>, <2,5,11>, <2,5,12>, <2,5,13>

and so on...

View 2 Replies View Related

C++ :: Find Function To A Vector Of Structures Vector

Jul 5, 2013

I have asked a related question before, and it was resolved successfully. In the past, when I wanted to use std::max_element in order to find the maximum element (or even sort by using std::sort) of a vector of structures according to one of the members of the structure, all I had to do was to insert a specially designed comparison function as the third argument of the function std::max::element. But the latter comparison function naturally accepts two arguments internally.

For instance, here is a test program that successfully finds the maximum according to just one member of the structure:

Code:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

[Code] ....

And the output was this, as expected:
Maximum element S.a of vector<S> vec is at: 9
[I]max element of vec.a between slot 3 and slot 6 is: 6, and its index is: 6 vec[6].a = 6
[I]max element of vec.a between slot 4 and slot 7 is: 7, and its index is: 7 vec[7].a = 7
[I]max element of vec.a between slot 5 and slot 8 is: 8, and its index is: 8 vec[8].a = 8
[I]max element of vec.a between slot 6 and slot 9 is: 9, and its index is: 9 vec[9].a = 9

However, I now need to search and find an element of vector<myStruct> according to just one member of myStruct, instead of finding the maximum or sorting as before. This presents a problem because the function std::find does not accept such a comparison function as its third argument.

This was the description of the std::find function that I found: find - C++ Reference

Code:
template <class InputIterator, class T> InputIterator find (InputIterator first, InputIterator last, const T& val);

I could also find another function called std::find_if, but this only accepts a unary predicate like this: find_if - C++ Reference

Code:
template <class InputIterator, class UnaryPredicate> InputIterator find_if (InputIterator first, InputIterator last, UnaryPredicate pred);

And once again this is either inadequate of I don't see how to use it directly, because for the third argument I would like to insert a function that takes two arguments with a syntax like this:

Code:
int x=7;
std::vector<S>::iterator result;
result = std::find(vec.begin(), vec.end(), []( const (int x, const S & S_1) { return ( x == S_1.a ) ; } ) ;

Is there another std function that I can use to make search and find an element according to just one member of myStruct?

Or perhaps there is a clever way to pass two arguments to the unary predicate.

View 4 Replies View Related

C/C++ :: Cannot Print Vector Of Vector Of Doubles

Mar 31, 2014

I am trying to print a matrix solution that I've stored in a vector of doubles. The original matrix was stored in a vector of vector of doubles. I want to print to the screen and an output file. Right now it just prints to screen column-style and the output file is horizontal-style. I tried to change the solution from vector of doubles to a vector of vector of doubles like the original matrix but when I run my code it crashes. Here is what I am referring to:

void readMatrix(vector<vector<double>> &matrix, vector<double> &b, int &N, string input) {
ifstream in(input);
in >> N;
matrix.resize(N);
b.resize(N);

[Code] ....

However when I change my printResult function to this (I removed the string argument because I just want to get it working to the screen first):

void printResult(vector<vector<double>> &sol, const int N) {
//ofstream out(output);
//int j;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++){

[Code] ....

The program crashes. Am I even printing the matrix correctly?

View 4 Replies View Related







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