|
Thank you for the insight. please excuse the casting and the float. If you notice the variables start with d because orginialy they were doubles. I changed to float for an output test. Other than that, it will ouput the correct answer? am I correct in assuming that?
-----
IMHO: C# a poor attempt at bringing C++ to the VB masses
-----
|
|
|
|
|
It's really the int cast that caught my eye - the root of a function is very rarely an integer, and I hate imprecise answers. As a rule, I try to use the greatest precision available in all internal calculations, then use a cast as the final step to limit the output to what the program needs to provide. You're correct in assuming that it will give the right answer, within the limits of the data types you've selected.
The short form of my answer, without my editorial comments, would be that the two implementations are equivalent. Yours may be more efficient, as it requires for each solution one addition and one division, while the other uses two divisions and one addition. Division requires more CPU cycles, generally, than addition, too.
Ancient man conquered his rivals with the jawbone of an ass; modern man uses the jawbone of a politician.
|
|
|
|
|
Thank you very much for the help. Seeings as how I did not even know what a quadratic equation was before I started this little project. I just got a hold of the formula, and kinda winged it from there to come up with an answer.
Thank you very much.
-----
IMHO: C# a poor attempt at bringing C++ to the VB masses
-----
|
|
|
|
|
You're very welcome... Quadratic equations are very useful, and you will probably encounter them often. As an entertaining exercise, try expanding your solution to include the common case where the radical (sc, in your code) is imaginary. Add a test for the case b2< 4ac. If this statement is true, solve the equation using the absolute value of the result before taking the square root and prefix the output of the radical with a 'j'. This gives a general solution of the form Re +/- jIm, which is valid for all equations in two-space. Your root solver will then be able to solve all cases, real and complex. Most important - have fun ith it!
Ancient man conquered his rivals with the jawbone of an ass; modern man uses the jawbone of a politician.
|
|
|
|
|
Is there a function to convert a CString value to an integer value?
|
|
|
|
|
|
try atoi()
regards
rishabhs
|
|
|
|
|
The following piece of code gives compilation error and i would like to get some ideas as to why.
fn_taking_2d_array(char[][MAX_WIDTH] array_arg)<br />
{<br />
}<br />
<br />
main()<br />
{<br />
char** list;
int length = getLength();
list = new char*[length]; <br />
for (int j = 0; j < length; j++)<br />
{<br />
list[j] = new char[MAX_WIDTH];<br />
}<br />
<br />
fn_taking_2d_array(list);
<br />
}
Aren't char** and char[][MAX_WIDTH] ultimately the same? pointer to pointer? It'd be great if i get some thoughts on this..
thanx,
natie.
|
|
|
|
|
natiekyle wrote:
Aren't char** and char[][MAX_WIDTH] ultimately the same?
Nope, char** is a pointer that points to a char pointer (an address that points to another address to hold a char ), while char[][] is only a two-dimensional array.
-Nick Parker
The true measure of a man is how he treats someone who can do him absolutely no good. - Samuel Johnson
|
|
|
|
|
If I have 400,000 sorted number in database like this
023F460B70F41323DBD1D2B49C
02C433C23F22D4498AFDCB9802
02E2C880757F813D0A0C067439
037502424D9A07383A1E6B73B1
.....
.....
.....
.....
A5183AA10FAC1DCCD581254A4
A6A7646433330474835DBAFE5
A7421081507B6CFAB19356F23
and I want to find this data "9DB831A9207DA9DE9F3E45525" is in database or not.
Do you know how to write program to do that?
Thank you for your answer.
|
|
|
|
|
I assume that you can use SQL in your program as a command to grab a certain criteria which would be
SELECT IDS FROM TABLE WHERE ID='9DB831A9207DA9DE9F3E45525';
If you returned a value then its there .
|
|
|
|
|
Anonymous, I never use SQL. Can I use SQL with Visual C++?
I use this below code but it is very slow. My database data is sorted number, so I think there may be the other ways to search quicker. If you know how to do that , please tell me.
<br />
<br />
m_Data = "9DB831A9207DA9DE9F3E45525";<br />
<br />
Found = 0;<br />
for (j=0; j<400,000; j++)<br />
{<br />
if (m_Data == Database_Data[j])<br />
{<br />
Found = 1;<br />
break;<br />
}<br />
}<br />
<br />
|
|
|
|
|
yeah u can use SQL using ADO (active x data objects ).
I was assumming u are working with some Database bridge such as ODBC. if u do not have something like that try using a STL map that will allow you to retrieve a value for a key .
The STL map is basically like a indexed table with a key value pair .
|
|
|
|
|
If they're sorted you can use a vector to hold them and use the std::binary_search ( or whatever it's called ).
Christian
NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma
Anonymous wrote:
OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window.
I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
|
|
|
|
|
Christian Graus wrote:
use the std::binary_search ( or whatever it's called ).
Otherwise known as a thingy-ma-jig.
-Nick Parker
The true measure of a man is how he treats someone who can do him absolutely no good. - Samuel Johnson
|
|
|
|
|
Hello,
I am trying to implement context-sensitive HtmlHelp in my application using VC++ .Net. I have succeeded in implementing help using the F1 key, as follows:
BOOL CMainFrame::OnHelpInfo(HELPINFO* pHelpInfo)
{
//pHelpInfo gives me the ID
::HtmlHelp(this->GetSafeHwnd(),AfxGetApp()->m_pszHelpFilePath,HH_HELP_CONTEXT,pHelpInfo->iCtrlId);
//return CFrameWnd::OnHelpInfo(pHelpInfo);
return 1;
}
I am now trying to do the same for the help toolbar button that changes the cursor into a questionmark until you click on something.
What bothers me is that I can't find any convenient eventhandler like the one above to give me the ID of the menuitem or control that is being clicked upon. The eventhandler above doesn't seem to work for the toolbar. Any ideas? There must be a way to find the ID.
Help much appreciated.
Trimtrom
|
|
|
|
|
Try this:
ON_COMMAND(ID_CONTEXT_HELP, OnContextHelp)
You should save yourself and your company years of grief by shooting yourself through the head immediately. Believe me, in the long run it'll turn out better for everyone. - Tyto (at arstechnica)
Awasu 1.0[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
I need to write a function to copy data from COM Port 3 (COM3) to COM Port 1 (COM1).
Then, I need to write a function to copy data from COM Port 1 (COM1) to COM Port 3 (COM3).
Any help at all is welcome!!!!!
Me, wrong!?! Nah, you just need to change your thinking to make me right.
|
|
|
|
|
You can open a com port as a file under Win32. With minor restrictions, you can specify Read or Write attributes when opening such files to read from or write to. You can even try opening the ports as CFile using MFC. There is an example on Microsoft's site showing how to do this, including creating CArchive objects based on these files. After they are open, you can use standard file read and write routines or the << and >> operators. Look at MSDN.
Here is a link to start you off. This goes through the theory, anyway, plus it is non-mfc. Can't recall the MFC link, but you can look at the VCTERM sample for specs on using the Communication control as well..
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp
My personal experience: Do not try to do the copy in the same thread. Gets very messy. I spun off threads to read and write to and from the files. That worked well, except you now need synchronization between the threads.
Good Luck!
|
|
|
|
|
I've added message handlers for a ComboBox control to that combobox's class (a subclass of CComboBoxEx which I have defined) to handle messages such as WM_CHAR, etc. However, when I use that combobox in a Dialog, my message handlers are not triggered by the user interactions which they are supposed to respond to. Any ideas on what is going on or how i can solve this problem would be much appreciated.
Ben
|
|
|
|
|
did you subclass it?
in the oninitdialog... or somewhere useful
m_myCombo.SubClassWindow(IDC_MYCOMBO, this);
Bryce
|
|
|
|
|
As I understood you have your own class CComboBoxEx in which you have implemented a handler for WM_CHAR, right?
And more you want to use this combo in your dialog.
Then if this is correct then add a combobox to your dialog by dragging it from the resource editor and add a member variable to that combo of the type CComboBox. Then go where your variable was added and change the variable from type CComboBox to CComboBoxEx.
I hope I understood corectly your question...
|
|
|
|
|
I have my own combo-box subclass (CMyCombo) that extends CComboBoxEx in order to add some specific features to all combo boxes in my program. However, I do not know how to display combo boxes of my type in Dialogs. Is there any way to add a combo box control to a dialog box in the resource editor, but use my subclass to implement it, rather than the default CComboBoxEx ?
Ben
|
|
|
|
|
Add it as a normal combo box to the template. Then in class wizard add a control member for the combo box (not a value). This adds a CComboBox member to the class definition - you can then replace CComboBox with CMyCombo.
Dave
|
|
|
|
|