C++ :: Simulation Of Motion Of Magnets On A Rod - Long Double Not Working

Apr 25, 2013

I'm currently working on a simulation of the motion of magnets on a rod. As part of it, there are arrays of the properties of the magnets:

long double *accelerations; // These will later be dynamically allocated depending on the number
long double *velocities; // of magnets
long double *positions;

However, when I go to compile this, the compiler gives me these error for the pointers:

error: two or more data types in declaration of 'accelerations'
error: two or more data types in declaration of 'velocities'
error: two or more data types in declaration of 'positions'

Apparently, the compiler isn't recognising long double* as a type and is instead reading is as the two types long and double*.

My compiler is MinGW 4.4.3

View 4 Replies


ADVERTISEMENT

C++ :: Converting String Into A Long Double

Mar 11, 2013

I have a problem with converting a C++ string into a long double. In order to do this, I used the function strtold, but the result I get is only the integral part, that is: if for example the input string is 12.476, I only get 12 as the converted long double value. This happens with atof too.

Here is my code:

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sstream>
string test = "12.345";
long double test_longd = strtold(test.c_str(),NULL);

[Code] .....

View 3 Replies View Related

C/C++ :: Converting String To Long And Then To Double

Jun 15, 2014

So I have problem with my code, I'm trying to convert string to long and then string to double, but I get this when I compile it:

terminating with uncaught exception of type std::invalid_argument: stod: no conversion

I was thinking if there is a way to do this without using (stol) or (stod)

Market::Market(string filename)
{
string line, word, date, stockprice;
long realdate;

[Code].....

View 14 Replies View Related

C++ :: Long Double Datatype - Output Always 0

Nov 11, 2014

My code:

#include<cstdio>
#include<iostream>
using namespace std;
main() {
long double j;
scanf("%Lf", &j);
cout<< j;
return 0;
}

If I give any number as input, the output is always 0. why? where's the problem ? p

View 6 Replies View Related

C :: Convert Scanf Output To Long Double And Discard The Last Newline

Apr 18, 2014

My goal is to read a one line file of a comma separated numbers into a floating point array. The numbers have up to 25 positions after the decimal. I'm having two issues with the following code.

1) atof() seems to be returning zeros every time. Why?

2) The last number includes the new line character. How do I get rid of it?

Note that I adapted the scanf command from here: The power of scanf() - [URL], and don't completely understand it.

Code:
#include <stdio.h>
#include <math.h>
//The following will be calculated in the real program.
#define DIM 1
#define N 8
int main()

[Code]......

In the "real" program, N is calculated and known before reading in the file and the file will always have 2 times N numbers.

View 9 Replies View Related

C/C++ :: Double Comparison For Range Is Not Working Correctly

Mar 17, 2015

I am trying to compare a double to be within various ranges, but the comparison is not working correctly. Rounding precision is not a concern, because if the value will match the boundaries so rarely, and it is rounding up to the higher range is acceptable. Below is the doe at issue:

if (kq == 2) {
if (fundt[kq-1][ky-1][2-1] < 450,000,000.00) ktti[ky-1][0] = 1;
else if ((fundt[kq-1][ky-1][2-1] >= 450,000,000.00) && (fundt[kq-1][ky-1][2-1] < 525,000,000.00)) ktti[ky-1][0] = 2;
else if ((fundt[kq-1][ky-1][2-1] >= 525,000,000.00) && (fundt[kq-1][ky-1][2-1] < 650,000,000.00)) ktti[ky-1][0] = 3;
else if ((fundt[kq-1][ky-1][2-1] >= 650,000,000.00) && (fundt[kq-1][ky-1][2-1] < 750,000,000.00)) ktti[ky-1][0] = 4;
else if ((fundt[kq-1][ky-1][2-1] >= 750,000,000.00) && (fundt[kq-1][ky-1][2-1] < 850,000,000.00)) ktti[ky-1][0] = 5;

[Code] ....

I know that a triple-dimension array looks complex, but I can guarantee that is a double. The literal constants I am using should automatically be doubles. The subscript of [2-1] looks odd, but this is code I was given to maintain, and that is how it is written elsewhere, so I kept it for consistency. The problem I am having is that when I run this code, all the data I input is less than the 450 million value, but the run falls through all the if and if-else conditions, and the else code is what is actually executed, i.e., I always get six as my result.

I am running on a Sun Sparc, and the compiler used is SunStudio 12. I have tried using variables, with the values listed above assigned to each variable, but it does work either. When I use variables, if the input value is negative, the comparison for less than 450 million works, but any positive input values will through to the else and give me six.

View 1 Replies View Related

C++ :: Printing Double Triangle - Working Fine Up To Input 7

Feb 22, 2013

I wrote code for printing a double triangle. Its woking fine upto input is 7. but when the input is 8 the output is disturbed. the code is this.

#include<iostream>
using namespace std;
int main() {
int a;
cout<<"Enter a number"<<endl;

[Code] ....

View 3 Replies View Related

C++ :: How To Reverse Nibble In A Long Long Int Variable

Apr 1, 2015

I have a long long int k=0x0000888804eaad0e

And i need the reverse of this (nibble wise) in other long long int variable.

That is i want the result to be = q=0x0000e0daae408888;

Or the result also can be like this = q=0xe0daae4088880000;

How to accomplish the above?

View 4 Replies View Related

C++ :: Packets And Tcp Simulation?

Nov 24, 2014

I have to write a program to take packets of information destined for certain ports then provide the current message using the packets I've gotten so far. Packets can come out of order, so when asked for the message, packets that haven't arrived yet are skipped and the next packet is appended. After giving the message, I have to delete all the current packets as well as ones that are received late, after the packets that were supposed come after the late packet were already provided in the message.

Data:Up to 1000 ports, numbered 0-64000, and each message can contain up to 1000 packets.

View 2 Replies View Related

C++ :: SDL - How To Handle Mouse Motion Input

Oct 19, 2013

I am using SDL 2.0. But I don't know how to handle mouse input. Do you think you can explain of how to do that? Or give me a link that explains that really great?

I know how to handle a mouse button that presses down for a sec.

Code:
if (event.type == SDL_MOUSEBUTTONDOWN){
if (event.button.button == SDL_BUTTON_LEFT){
// Do something . . .
}
}

But not how to handle the mouse input of what the mouse is hovering over and that.

Like in a start menu of a game. I want a button for example to appear blue when I hover over it and when I click on it. It should start the game for example.

View 6 Replies View Related

C++ :: Visual Arrow Following Motion Of Ball?

Aug 25, 2013

I have created plane as floor and sphere as ball. I used physics equations to it and ball falls under gravity. Now i want to attach visual arrow to this ball which moves with it according to velocity direction. If ball bounces then direction of velocity is changed so does arrow.

View 1 Replies View Related

C/C++ :: Charge Simulation Method?

Sep 26, 2014

how to write a "charge simulation method" program in C or C++? It's to calculate electric distribution and also electric potential of two different dielectrics. I have attached the diagram of the shape of the electrode that needs to be investigated.

View 1 Replies View Related

C/C++ :: Email Simulation Using Queue?

Feb 1, 2015

Here is the assignment I get:

Write an email simulator that processes mail at an average of 40 messages per minute. As messages are received, they are placed in a queue.assume that the messages arrive at an average rate of 30 messages per minute.messages must arrive randomly.

Each minute, you can dequeue up to 40 messages and send them. Assume that 25% of the messages in the queue cannot be sent in any processing cycle.use a random number to determine whether a given message can be sent. If it can't be sent, enqueue it.

Run the simulation for 24 hours, At the end of the simulation, print the statistics that show:

-The total messages processed.
-The average arrival rate.
-The average number of messages sent per minute.
-The average number of messages in queue in a minute.
-The number of messages sent on the first attempt, the number sent on the second attempt, and so forth.
-The average number of times messages had to be requeued (do not include the messages sent the first time in this average)

Well, actually I've done a part of the coding. But how to continue it. And here is my code :

#include <iostream>
using namespace std;
#define SIZE 40
class Queue {
int queue[SIZE];
int head, tail;
public:
Queue();
void Enq(int num);

[code]....

View 1 Replies View Related

C/C++ :: Trapezoidal Motion Profile Using Discrete Method?

Mar 9, 2015

I'm trying to program an arduino to generate a Trapezoidal Motion Profile to control a DC motor with a quadrature encoder.

Essentially, the user will input the desired Target Position, Max Velocity and Acceleration (decel = -accel) and the code will calculate the target position versus time which will then be compared with the actual position. The result will then be subject to a PID calculation

My initial assumption was that I could use basic Newtonian physics to determine position (i.e. PT = P0 + V0T + 1/2AT2, VT = V0 + AT). However, after reading through documentation for pre-existing motion controllers, I discovered that the prevalent method was to use a discrete time method, which is as follows:

VK = VK-1 + A (A = Acceleration)
PK = PK-1 + VK-1 + A/2

I'm having a hard time understanding quite how this equation would generate the target position versus time. In the case of Velocity, it seems to just add the acceleration to the current velocity. But what about everything in between?

View 2 Replies View Related

C# :: How To Make A Planet That Moves In A Circle Motion

Dec 7, 2014

i would like to make a planet that moves in a circle motion. I dont know how to start and how i can move a "planet" in a circle motion?

View 2 Replies View Related

C++ :: Dynamic Linking Of Two Software For Co-Simulation

Jan 25, 2013

My Project is to Dynamically Link 2 Software for Co-simulation n C/C++. So that Output of One Software becomes Input of Other automatically . at present we input the parameters manually in both the software . what to do so that it pick up values itself and gives the output by solving each and everything at once in both the software .

View 5 Replies View Related

C++ :: Flash Memory Simulation Using A Code

Jan 23, 2013

I have to simulate flash memory using C++ for a project.

View 2 Replies View Related

C++ :: Combinational Logic Simulation Using QThreads

Oct 30, 2013

I'm trying to create program that reads in commands from an input file, and accordingly creates, connects or destroys logic gate primitives (and gates, or gates). Additionally, I'm trying to modify a previous program that I wrote to do this using QThreads, where each gate is placed in its own QThread. I'm trying to avoid using invokemethod, and I'm sure this method can work. My specific issue that I'm having trouble debugging is in my connect code block in main.cpp. Whenever I try to reference a gate specified by the input file that is NOT the true or false gate (I have one of each and they are attached to any gate that needs a true or false input), I get only a NULL reference. This includes attempting to reference the gate in my gatelist QMap. Calling gatelist.value(newCommand.at(1)) causes the program to hang, and the connect statements referencing said gate return errors about connecting a signal or slot of a NULL pointer.

Here is main.cpp:
#include <QPointer>
#include <QMap>
#include <QDebug>
#include <QString>
#include <QFile>
#include <QTextStream>

[Code] ...

My accompanying class declarations can be found here : [URL] ....

View 6 Replies View Related

C :: Arduino Programming - Control Motion Of Servo Motor

Jul 16, 2013

I am working on a project that requires using an arduino microcontroller to control the motion of a servo motor. The arduino language is pretty much C.

The original code is of the form:

Code:
#include <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

[Code] .....

But the problem is I don't want the motor's motion to behave linearly (constant increments of the pos variable). My desired motion is a sinusoidal like function. How to approach this?

I am quite new to programming, especially with microcontrollers. My guess is that instead of the pos+=1, I would need something like pos+=sin(argument). I am not sure what that argument should be.

View 4 Replies View Related

C Sharp :: Motion Of Controls - Picturebox Position In Form?

Apr 8, 2012

I have a form with a picturebox and some buttons to move the picturebox. I don't want the user to guide the picturebox out of the form even by dragging the form border picturebox moves just in the form border, and also there is a button to guide the picturebox to the start position (start choose by user). What can i do?

View 1 Replies View Related

C++ :: Lotto Simulation - Defining User And Lottery?

Feb 11, 2013

How do i define user and lottery..

//Declarations
#include <iostream>
#include <cstdlib>
#include <ctime>

const int lotteryDigits = 10;
const int SIZE = 5;
const int Power = 1;
int generateLottery(int[], int, int);

[Code] ....

View 15 Replies View Related

C++ :: Visual Studio 2013 - Leap Motion Virtual Piano

Sep 10, 2014

I currently have a project that requires me to build a leap motion Virtual Piano. I am using Windows Visual Studio 2013 and i plan to use C++ to code it.

I assume my first step is to create a virtual piano using C++.. Then, link it with leap motion interface.

Can i know which audio library suits my project and how can i go about doing it?

View 1 Replies View Related

C Sharp :: Full Code For Webcam Alert Motion Detector?

Mar 12, 2013

i have webcam i need to make project when this webcam detect any motion in his spot give me alert ,,,

View 4 Replies View Related

C++ :: Error In Classic Bank Teller Simulation Program?

Feb 17, 2014

Anyhow, I have a program due Wednesday that is along the lines of the classic Bank Teller simulation using Queue's.

Unlike most of these programs, I have to integrate my own Queue, QueueNode, Teller, and Customer classes. I have attached all of these headers below plus the main file.

Now the error: While I'm sure there are other issues with the code, it will not let me create a new customerQueue (of Queue type) object as such:

Queue<Customer> customerQueue;

The error it is giving me is:

no matching constructor for initialization of 'Queue<Customer>'

Here is my code:

Queue.h:

#ifndef QUEUE2_H_
#define QUEUE2_H_

#include <iostream>
#include "Teller.h"
#include "Queue.h"

[Code] ....

View 1 Replies View Related

C++ :: Build A Banking Simulation Program Around The BankAcct Class?

Sep 5, 2014

I'm supposed to build a banking simulation program around the BankAcct class, which provides the following service: create new account with unique account number (maximum 5 accounts created in a single test running); deposit/withdraw; print information of all existing account. I was running a test program with only 2 services first, namely creating new account and depositing, but the program just keep on crashing and I couldn't figure out why.

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

[Code].....

View 1 Replies View Related

C++ :: Passwords Must Be At Least 7 Characters Long

Dec 4, 2013

I've written a code that request for a password and its suppose to look like this.

Sample Output (inputs in bold)
Please enter a password: pass6
Passwords must be at least 7 characters long
Please enter a password: TarrantNW
Passwords must include a digit or dollar sign (0-9, $)
Please enter a password: Tccd-03

But when I run the program it stops at "Passwords must be at least 7 characters long" and the box closes and where I should put the loop=

#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
const int SIZE = 7;
char password[SIZE + 1];

[code]....

View 3 Replies View Related







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