C++ :: How To Declare High Order Vectors
Sep 21, 2013
I suspect that C++11 would make it possible to declare high rank vectors such as Code: int N = 15; // chosen arbitrary rank vector<vector<vector<...<vector<double>>>>..> vec; // N layers of nested vectors Is there a way to declare such a vector of rank N (given a fixed integer rank N)?
Heuristically I would like to write the declaration like this: Code:
vector<double> A;
vector<A> vec[0];
for(int i=1; i<N; i++)
{
vector<vec[i-1]> vec[i];
} Is there a way to use the new variadic templates to make this work?
View 9 Replies
ADVERTISEMENT
May 13, 2013
I need to declare the number of vectors according to an input parameter call NUM HOST.
For example, if NUMHOST=4, I need to declare 4 vectors and the name of the vectors seriam: vector1, vector2, vector3, in struct for would be vectori...
for (int i = 0; i <= NUMHOST; i++)
int vector????[3];
View 13 Replies
View Related
Jan 30, 2014
I think there is no always need of keyword extern in order to declare variables globally. Is it right?
For example I can declare a variable globally in one file and use it in some other provided that I have included the last one file ( that has the declaration of the variable of course) and compile these files together :
gcc -c f1.c f2.c for example
View 6 Replies
View Related
Jul 15, 2013
I have two vectors of float that I need to sort in reverse order. reverse() seems to work for one of them, but not the other. I have toggled between sort() and reverse(). for one vector, the expected behavior is seen and the order reverses. For the other, there is no change in order.
This is very simple code, so it's hard to imagine what is going wrong.
Code:
vector<float> vec1, vec2;
vec1[0] = 14.1102; vec1[1] = 14.1145;
vec2[0] = 15.8508; vec2[1] = 26.0842;
sort( vec1.begin(), vec1.end() );
sort( vec2.begin(), vec2.end() );
[Code] ......
Printout is,
Code:
vector 1 sort
14.1102
14.1145
vector 2 sort
15.8508
26.0842
vector 1 reverse
14.1102
14.1145
vector 2 reverse
26.0842
15.8508
You can see that the order of the first vector did not change. Am I right in suspecting that the numbers are too similar for what ever method reverse() uses to determine the difference between values?
View 8 Replies
View Related
Feb 13, 2013
I have a vector which contains vectors containing 7 integers each. I'd like to sort these vectors based on the value of the first integer (int IOT), in ascending order. I know this type of question can be found everywhere, but I'm lost as to why this doesn't compile.
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <windows.h>
using namespace std;
class orders {
public:
int IOT; // Incoming Order Time
[Code] ....
View 7 Replies
View Related
Mar 19, 2014
I create a list of vectors (a vector of n vectors of m elements).
std::vector <std::vector <int> > vsFA (n, std::vector<int>(n));
How I assign values? I try below, but not worked
void armazenaFA( std::vector <int> &vFA) // this function only knows about vFA
{ vsFA[n] [m]= simTime().dbl();
OR
vsFA[n].push_back(simTime().dbl());
}
View 1 Replies
View Related
Sep 19, 2014
This is probably a very basic question, but I need to create two vectors and then loop through the vectors and output each pair that is found.
The user will input min1 and max1 with step1 for the first vector and min2 and max2 and step2 for the second vector. Then the loops will go through and return the combinations will return each pair of the two vectors.
So if I input min1=1 and max1=10 and step1=1 and same for vector two the return would be:
[1,1]
[1,2]
.
.
.
[10,10]
This is for part of a homework assignment, but I can't continue on the assignment without first getting this simple part to work.
View 1 Replies
View Related
Mar 28, 2015
I've made a game and a dialogbox to show up asking to enter a nickname.
The problem is After entering the nickname, it won't show on the highscore list below (textbox)
Where can the problem be? Below is my code:
private void btnPlay_Click(object sender, EventArgs e) {
if (txtName.Text != "") {
Settings.Name = txtName.Text.ToString();
[Code] .....
View 5 Replies
View Related
Feb 9, 2013
I haven't tried to run my program yet, but maybe I will save some trouble if I ask this question first.I am using MC PIC16F690, and I could make a pin high or low by writing RCx = 1 or 0, where x is the pin in the C port. However, I want to use the counter variable from a for() loop as the pin number. Will RC(variablename) = 1 work, or is there another syntax?
View 2 Replies
View Related
Feb 6, 2015
The bottom three functions do not work. Nor are the finished to the extent. I do not know how the data members are being accessed and is only giving me the last output. The overall goal of this program is to output the highest grade with student name and age, lowest grade with student name and age, and the average of all grades. The file is given and is commented out for you to see what the file looks like.
// Header Files
#include <iostream>
#include <fstream>
using namespace std;
// Global Constants
const int STD_STR_LEN = 10;
[Code] .....
View 5 Replies
View Related
Jul 15, 2014
I have taken a keen interest in writing trading programs. I have some Python background, a little C# but no C++.
The example below was provided in a book on HFT and I would love to see how the results look. I was hoping that I would just compile it and away you go!
That didn't happen. To start with the author listed this as a function, so I converted it to a main program. Still having issues with my path and where to see the output. Here it is..
Code
void HFT_AvellanedaStoikov() {
FILE* fin, *fout;
double lambda_a, lambda_b, d_lambda_a, d_lambda_b;
int hh = 0, mm = 0, ss, nb = 0, na = 0, prevnb = 0, prevna = 0, prevm = 0;
double bid, ask, prevbid = 0, prevask = 0;
char * p1, *p2, buffer[1024], fname[512];
[Code] .....
Here is some data:
14 49 24.37 24.38
14 49 24.37 24.38
14 49 24.37 24.38
14 49 24.37 24.38
.... and so on ....
View 3 Replies
View Related
Jun 1, 2013
Write a program that allows a user to enter high scores of a game, keeping tracking of the name of the user and the score. Add the ability to show the highest score for each user, all scores for a particular user, all scores from all users, and the list of users.
This is the program I am trying to write, however I am having difficulty storing the users name and high score, I know I need to store an array for the score but getting confused because of the structure. (By the way I have to use structures as it is a problem from the structures chapter of the ebook I am doing). Below is my code so far. .
Code:
#include <iostream>
#include <string>
using namespace std;
struct highScore
{
string user;
int score;
int highestScore;
int allScores;
[Code]...
View 9 Replies
View Related
Jan 12, 2013
One of my programs I recently created, needs higher precision then what doubles can provide. So I am wondering how I install a library like this [URL] .... I don't quite understand exactly how to install them. Im using visual studio 2012 ultimate right now!
View 3 Replies
View Related
Jun 26, 2014
On a project I'm working on, I need to update many QLabels very quickly. Each label needs to be updated at about 20 to 50 hertz and there can be over 50 labels at any given time. The problem I'm having is after running the program for about a minute, the labels freeze and the whole program crashes about 10 seconds later. If I comment out the setText() and setNum() calls and reroute the outputs to the console, it runs fine and never crashes. Why does calling SetText() and setNum() so quickly cause the program to crash and how can I prevent this?
View 5 Replies
View Related
Dec 23, 2014
I basically have a listbox that has postcode areas i.e : AE,CW,GU etc etc.
The user selects this and then a postback occurs - an sql statement is builts and a database query operation is performed and the results are returned to a datatable called tempdata.
So far so good. I then need to loop through this datatable and copy the records to my main viewstate datatable which is the datasource for google maps api.
DataTable tempstore = GetData(querystring, "");
//check tempstore has rows otherwise add defaultcust as default otherwise map will be blank
if (tempstore.Rows.Count == 0)
{
[Code].....
So my main datatable can grow and grow as users add more postcodes. However when it gets to around 500 rows or so I get a huge memory spike only on postback and then it settles back down.
My ram usage goes from 2gb to 3gb and if even more postcodes is selected it maxes the memory and crashes my pc.
If I remove the:
dtpc.Importrow(row);
the memory spike goes completely, obviously because the main datatable has no rows. I thought you only run into memory issues when you have thousands of rows?
View 1 Replies
View Related
Jan 21, 2013
How to create a symbol table for an assembly language and high level language in c++?
View 1 Replies
View Related
Aug 30, 2014
I was investigating for the first time how to generate prime numbers with a considerably high upper limit, around 10^6 or so. I read about sieve's algorithm and tried to implement it using c#, as I had previously brute forced the generation. In Sieve's algorithm, instead of marking the values that were not prime I simply eliminated them, but I don't think that would make any difference. The issue is that my implementation of sieve's algorithm must be wrong, as when I establish the limit as 10^5 I get the following output:
Brute force:
Computation time: 00:00:00.0643539
Sieve's algorithm:
Computation time: 00:00:20:6934223
I have already checked that their generation of primes is correct, but I do not know why one is significantly slower than the other. Here is my code.
using System;
using System.Collections.Generic;
using System.Linq;
[Code].....
View 5 Replies
View Related
Mar 20, 2015
how to manually control the temperature of High Power Leds using PID controller. I have two GUIs,one reads the temperature from the Led while the second is used to ON/OFF the Leds and at the same time controls the Led brightness using slider control.The GUI that reads the temperature has a PID controller application on it.The output from this controller is what i want to use to increase or decrease the Led brightness which invariable changes the Led temperature.How to go about using this PID controller to control the Led brightness is what i have not been able to grasp well.The slider on the GUI is scaled from 0% to 100%.My thinking is that the output from the controller should be in percentage which will make me to adjust the slider accordingly.My question is that will this type of arrangment produce an output that will efficiently control the Led brightness. how to accomplish that. Attached to this post is a modified code of a tutorial on PID controller which i found on the net. a tutorial on how to develop a graph. i wish to display the Setpoint,Process value and the output value on a graph.
View 2 Replies
View Related
Feb 13, 2013
I am writing a program which handles the CAN messages Received from BUS.My code is taking almost 60% of CPU usage.
View 14 Replies
View Related
Jul 11, 2014
I am making a multiple quiz program. So everything is working fine, except for the part where i'm trying to add a highscore for each user which is being stored in a binary file. I have added a sample of the program containing the error. This isn't the actual program, which is very long.
class user { //The collection of all info pertaining to the users
char user_id[50];
public:
int hscore1;
user() {
strcpy(user_id,"NULL");
hscore=0;
[Code] ....
View 1 Replies
View Related
Aug 19, 2013
How to declare functions in C++
View 1 Replies
View Related
Mar 6, 2015
I remember that the syntax exists I just don't remember what it is.I want to write a conditional function () prior to main (). in that function I'm using a variable that isn't introduced until main (). How do I let C know that I will be int'ng this function prior to the point where it is going to be accessed so that it doesn't freak out? alternatively is it possible to int the variable in both main() and my conditional function so that it exists? I imagine this would cause an issue because I would essentially be int'ng it twice.
I've done the cursory google searches however I don't think I'm using the correct keywords to get the results I'm looking for. If necessary I would be more than happy to post the code it's just a simple 40 line homework assignment.
View 6 Replies
View Related
Aug 20, 2014
I have this class with template:
template<template<class, class> class ContainerType>
class Movie {
public:
typedef ContainerType<Actor*, std::allocator<Actor*> > Container;
and i have a member func to find actor in movie according to actor id:
const Actor* findActor(int id) const {
typename Container::iterator it;
Actor* p(NULL);
it=actors.begin();
std::for_each(it,actors.end(),(*it)->getId()==id?p=*it:0);
if (p==*actors.end()) return NULL;
return p;
}
I receive error that no match for operator= in it.
How to declare correct iterator ?the type of actors is Container..
View 6 Replies
View Related
Sep 29, 2013
How i can declare a bit string in C++ .....
View 9 Replies
View Related
Jul 14, 2013
Can you declare a stack globally?
Code:
stack< int > stk;
View 4 Replies
View Related
Oct 11, 2013
It has been a few years since I have had to do this, but I need to declare a method in my base class, but produce no code for it. Then when this library is used by my second project I will derive a class from this base class and put the code into it there. How is this possible? I used to know how but do not remember how now.
The library is a static library designed for linking with both 32bit and 64bit Windows applications to handle a lot of the tedious stuff with Windows programming. The method in question handles specific command inputs. However, since each program that uses this library will have different uses for these commands, I want to leave it up to the user to code their own handling, but require it to be coded in the derived class.
View 2 Replies
View Related