473,563 Members | 2,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a very simple question, pls help a new programmer

I used to write program in Matlab. I have no experience in C++ at all.
But my boss order me to convert a matlab function to C++ function, so
he can use it with his program. For the concept of the program, it
receive a new input and keep some variable in memory to give a output.
Could you please tell me what mistake I have make in the program?

Thanks
#include <stdio.h>
#include <math.h>
class CGripperHystere sis {

private:

public:
CGripperHystere sis( );
void SetThreshold( double threshold);
double CalculateOutput ( CGripperHystere sis, double input_data);
};

CGripperHystere sis::CGripperHy steresis( )
{
double m_last_update_s ide = 0;
double m_last_on_curve _value = 0;
double m_threshold = 0;
double output_data = 0;
double input_data = 0;
}

void CGripperHystere sis::SetThresho ld( double threshold)
{
m_threshold = threshold;
}


double CGripperHystere sis::CalculateO utput(CGripperH ysteresis, double
input_data)
{
double output_data_tem p;

if (m_last_update_ side == 0 && m_last_on_curve _value == 0)
{
if (input_data <= threshold){
output_data = 0;
m_last_update_s ide = 0;
m_last_on_curve _value = 0;}
else if (input_data threshold){
output_data = (input_data-threshold)/(1-threshold) ;
m_last_update_s ide = 0;
m_last_on_curve _value = output_data;
}
}
else if (m_last_update_ side == 0 && m_last_on_curve _value 0 &&
m_last_on_curve _value <1)
{
output_data_tem p = (input_data-threshold)/(1-threshold);
if (output_data_te mp >= m_last_on_curve _value)
{
output_data = output_data_tem p;
m_last_update_s ide = 0;
m_last_on_curve _value = output_data_tem p;
}
else if (output_data_te mp < m_last_on_curve _value && input_data >
m_last_on_curve _value*(1-threshold))
{
output_data = m_last_on_curve _value;
m_last_update_s ide = 0;
m_last_on_curve _value = m_last_on_curve _value;
}
else if (output_data_te mp < m_last_on_curve _value && input_data <=
m_last_on_curve _value*(1-threshold))
{
output_data = m_last_on_curve _value;
m_last_update_s ide = 1;
m_last_on_curve _value = output_data;
}
}
else if (m_last_update_ side == 0 && m_last_on_curve _value >= 1)
{
if (input_data >= (1 - threshold))
{
output_data = 1;
m_last_update_s ide = 0;
m_last_on_curve _value = 1;
}
else if (input_data < (1 - threshold))
{
output_data = (input_data)/(1-threshold) ;
m_last_update_s ide = 1;
m_last_on_curve _value = output_data;
}
}
else if (m_last_update_ side == 1 && m_last_on_curve _value <= 1 &&
m_last_on_curve _value 0)
{
output_data_tem p = (input_data)/(1-threshold);
if (output_data_te mp <= m_last_on_curve _value)
{
output_data = output_data_tem p;
m_last_update_s ide = 1;
m_last_on_curve _value = output_data_tem p;
}
else if (output_data_te mp m_last_on_curve _value && input_data <
m_last_on_curve _value*(1-threshold) + threshold)
{
output_data = m_last_on_curve _value;
m_last_update_s ide = 1;
m_last_on_curve _value = m_last_on_curve _value;
}
else if (output_data_te mp m_last_on_curve _value && input_data >=
m_last_on_curve _value*(1-threshold) + threshold)
{
output_data = m_last_on_curve _value;
m_last_update_s ide = 0;
m_last_on_curve _value = m_last_on_curve _value;
}
}
else if (m_last_update_ side == 1 && m_last_on_curve _value == 0)
{
if (input_data < threshold)
{
output_data = m_last_on_curve _value;
m_last_update_s ide = 0;
m_last_on_curve _value = m_last_on_curve _value;
}
else if (input_data >= threshold)
{
output_data = (input_data-threshold)/(1-threshold) ;
m_last_update_s ide = 0;
m_last_on_curve _value = output_data;
}
}
return output_data;
}

Aug 9 '06 #1
2 1256

Marco wrote:
I used to write program in Matlab. I have no experience in C++ at all.
But my boss order me to convert a matlab function to C++ function, so
he can use it with his program. For the concept of the program, it
receive a new input and keep some variable in memory to give a output.
Could you please tell me what mistake I have make in the program?

Thanks
#include <stdio.h>
#include <math.h>
class CGripperHystere sis {

private:

public:
CGripperHystere sis( );
void SetThreshold( double threshold);
double CalculateOutput ( CGripperHystere sis, double input_data);
};

CGripperHystere sis::CGripperHy steresis( )
{
double m_last_update_s ide = 0;
double m_last_on_curve _value = 0;
double m_threshold = 0;
double output_data = 0;
double input_data = 0;
}
Here is one mistake. Those members should be declared in the class and
initialized in the constructor. You should also consider using
constructor initialization instead of setting values in the constructor
body.

Aug 9 '06 #2

"Marco" <mo******@gmail .comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
>I used to write program in Matlab. I have no experience in C++ at all.
But my boss order me to convert a matlab function to C++ function, so
he can use it with his program. For the concept of the program, it
receive a new input and keep some variable in memory to give a output.
Could you please tell me what mistake I have make in the program?
It might help if you told us what the problem is. Is it failing to compile?
If so, what error messages do you get, and for what lines of code? Is it
compiling, but not running properly? If so, have you tried debugging it?
Does it produce wrong output? Or crash?

You need to tell us exactly what help you want, not just ask us what's wrong
with some random code.

-Howard
Aug 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
5324
by: perseus | last post by:
I think that everyone who told me that my question is irrelevant, in particular Mr. David White, is being absolutely ridiculous. Obviously, most of you up here behave like the owners of the C++ language. A C++ interface installation IS ABOUT THE C++ LANGUAGE! The language does not possess the ability to handle even simple file directory...
6
6628
by: Beach Potato | last post by:
Hi: I've searched newsgroups and various archives, including MSDN & MFC sources, but at this point failed to locate an accurate and simple implementation of WndProc function for MSWindows window objects. Something like: class BaseWindow { virtual LRESULT WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
5
3701
by: Rich | last post by:
I have a simple, single threaded program in C++ that runs as Idle priority. The program creates some data which needs dumping to file if the computer is shutdown or logged out. At the moment there is almost no Win32 code in it (only a few lines to do the idle priority class). What is the simplest way of programatically detecting the...
51
8232
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct code? many thx!
10
2354
by: serge calderara | last post by:
Dear all, I need to build a web application which will contains articles (long or short) I was wondering on what is the correct way to retrive those article on web page. In orther words, when there is such information to be displayed are they coming from imported files, database ? Where and how this type of information is stored ? What...
13
2022
by: aum | last post by:
Hi, I'm a Python programmer, just starting to get into javascript. On reading some of the js guides, and not liking any of the OO usage patterns I saw, I've cooked up something which python folks might find to taste. Here's the code - first the 'engine', then some code demonstrating the usage patterns. For me (and maybe for some of...
10
1599
by: pipponino | last post by:
I own a simple Virtual Tour Site. At this time I can't afford to hire a programmer to make it everything that I want so I am trying my best to have it function for the time being as best as I can using out of the box templates. I would like to add a simple feature to the front of my site. This site is www.towncenter.com I store the tours in...
13
1521
by: aaragon | last post by:
Hi everyone, I just wanted to know if there is any difference in performance in declarating the variables in the beginning of a function or within for loops. For example: double test() { double a,b,c; for(int i=0; i<n; i++){
30
3483
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
10
2117
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel <System.Web.Services.WebService(Namespace:="http://...
0
7882
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7634
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7945
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5481
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5208
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.