+ 18
How can i solve vector problems in C++.
I can't understand vector problems. Ex. A vector is declared and initialized as: double v [128] ={4.0}; what are the components of this vector.
9 Respuestas
+ 15
#ifndef TankEventListner_h
#define TankEventListner_h
#include<fstream>
class TankEventListner:PublicSimEventListner
{
Public;
TankEventListner(const Tank*tank):
SimEventListner(),
tank(tank),fout ("current.dat"),
E (0,0), //Accuulated energy starts at zero
t1 (0,0)
il (tank -> getPhysics ()->leftMotor Current() ),// i_l(b)
ir (tank -> getPhysics() -> rightMotor Current () ) // i_r(0)
{
fout <<t1<< " " <<il<< " " <<ir<< std:: endl;
}
//listner does nothing without output evenys
void output Event (Model Input,double){}
// This method is invoked when an atomic Components changes state
void state change (AtomicModel*Model ,double t)
{
//If this is the model of the tank's physics
if (model == tank -> getPhysics ()){
//Get the Current motor resistance
double Rm =tank-> getPhysics ()-> getMotor ohms ();
// update the energy dissipated in the motors
Et= (t = t1 )*( il*il*Rm+ir*ir*Rm);
//Remember the last sample
il =-> getPhysics () -> getMotor Current ();
ir = tank -> getPhysics ()-> getMotor Current ();
t
+ 14
Thanks for answering.
+ 14
check it please.
+ 13
what its mean ,when run any code and its output is compilation error. please tell.
+ 5
No idea what vector means in this context. This is the vector I know:
https://www.sololearn.com/learn/261/?ref=app
+ 5
Vector is not a problem, it's a vehicle to solve many problems with less headache. Fundamentally, vector is a dynamic container belongs to C++ STL (an expendable cupboard, array or whatever you prefer). That is, you store homogeneous types in it for further use.
What you are trying to say is how we can declare and initialize a vector and what are its alternatives.
In double v[128] = {4.0} array, you say to the compiler, "Hey, spare 128 cell of memory of type double (usually 8 byte each -- total 1KB) and initialize the very first cell (v[0]) to 4.0. Rest of the cells would being initialized to 0 but that's not the case always.
Now, for getting the basic concept of what vector is, read through Hatsy Rei 's mini-tutorial. Then continue the following.
The good news is, you can use your lovely array to initialize a vector with ease.
#include <vector>
#include <iostream>
...
// Array as vector initializer
double v[128] = {4.0};
// Vector being initialized by array
std::vector<double> vec(std::begin(v), std::end(v));
// Printing out the result
for (const auto &idx : vec)
std::cout << idx << std::endl;
Well, that's all for the answer!
+ 4
shubham
For a variety of reasons. For example, sometimes the code is too lengthy and online compilers based upon their resource restriction, throw a fake compilation error. Sometimes, transferring a particular source code from an offline IDE to online environment causes similar problems because you simply forgot to add a header file to your code like ctime header. Another possibility which is not obvious for beginners is compiler warnings. Depends on the severness of warnings, your program will face with bizarre reaction from compiler.
+ 3
shubham
This is just a small piece of a larger system by which you can simulate a process. What you have provided here is not going to compile, run and produce a result.
+ 1
I think thats an array of double.