Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I love this free tutorial -- it has an entire chapter devoted to databases.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here's an interesting little article I cam across recently.

Walk into any bookstore, and you'll see how to Teach Yourself Java in 7 Days alongside endless variations offering to teach Visual Basic, Windows, the Internet, and so on in a few days or hours. ... The conclusion is that either people are in a big rush to learn about computers, or that computers are somehow fabulously easier to learn than anything else. There are no books on how to learn Beethoven, or Quantum Physics, or even Dog Grooming in a few days. Felleisen et al. give a nod to this trend in their book How to Design Programs, when they say "Bad programming is easy. Idiots can learn it in 21 days, even if they are dummies.

The article also has a lot of good advice for new programmers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use clock() instead of time(). clock() returns the number of (usually) milliseconds that have elapsed since the program started. I don't know how changing the computer's time will affect clock()

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Before your program starts doing calculations synchronize the clock with NTP.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I can't get to PFO.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In general you are right, but I don't think his csv file contains any text -- all numeric. So complicating the code by parsing for quoted material is unnecessary.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are getting core dump becuse the pointer has never been allocated any memory. Lines 6 and 11 attempt to store an integer into a pointer that contains an invalid address. Is it a requirement of the assignment to use a pointer?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

100(1+0.00417)=100.4417

That is incorrect. 100 * 1.00417 = 100.417, not 100.4417.

In any event, just a simple loop will calculate the value after N number of months.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It's fairly easy to accomplish in either language. In C, call fgets() to read each line, separate it into tokens with strtok(), then convert each string token into integers using atol() (or one of several other conversion functions).

In C++ it's a little simpler, call getline() with a line terminator (last parameter) as the comma, then use one of the string convesion functions to convert from string to int.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

inline functions, the compiler can choose to make them inline as if they had been macros or to just make them regular functions. inline functions as well as functions written as macros has the potential to bloat the compiled program, making it a lot larger than if the function had been written as normal functions. With macros the compiler has no options but to duplicate the code every time it is called. But if you use inline functions the compiler can elect to make them normal functions in order to reduce program size.

Here are a few guidelines I follow:

  1. never write functions as macros, IMO that is just bad programming style.
  2. One or two statement functions should be written as inline functions.
  3. Any functions larger than two statements should be normal functions.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The drivers are 32bit. You should consider implementing MSSQL, or Mysql or whatever db that has 64bit drivers.

I question that. On my 64-bit Windows 7 and 8 I use 32-bit database drivers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I will go with my method because it has less no. of statements

That's a poor reason not to use his code. If you post the exact assignment I'm willing to wager that your instructor wants you to swap the variables in memory, not just on the console screen.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It doesn't work with other programs because the other programs are not in the same address space as the one you posted. What you want to do is called injecting, here are a few google links for you to consider.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

So the c++ code is already compiled as an exe program? Then in the java program construct a string that contains the name of the program followed by the command-line arguments you want to pass. After that call a function that executes other programs. I'm not a java programmer but in C/C++ it would be system().

Maybe this tutorial will help you

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The question is, which ALGORITHM is faster. You can't test that if you include other factors that contribute to overall time (such as memory, catch, operating system, and other things out of control of the programmer like CPU time slices, time consumed by other processes, etc). In order to answer the question we need to isolate out all other factors.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It should also be noted that reading two integers...

That may be true, but that's testing hardware, not the program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

But that's still not testing the speed of the algorithms, it's still testing machine speed. Shouldn't care about hardware issues.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

None of that is relevant when comparing the speed of various algorithms on the same computer. He's not trying to find out whose computer is faster, but which algorithm is faster.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Simple solution: use the mod % operator to determine if a number is odd or even, then if even just add to the sum. Note: the only reason I'm posting entire code is because this thread is already over 2 weeks old, so it probably won't affect the OPs program one way or the other.

int n1 = 1;
int n2 = 10;
int sum = n1 + n2;
for(int number = n1; number <= n2; number++)
{
   if( (number % 2) == 0) 
   {
      sum += number;
   }
}

No need for all that complicated math or use of vectors.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

So the most reliable way to find out how fast a given piece of code is, is to measure.

Not necessarily -- just sum up the clock cycles for each machine instruction. I already posted two charts for 80x88 family of processors.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First off -- LPWSTR is a pointer, declared like this:

typedef wchar_t* LPWSTR

That means LPWSTR buffer[256]; is an array of 256 pointers of type wchar_t*. I don't think that is what you intend.

What you want ot WCHAR buffer[255];

Now to answer your question. Once you get the text into buffer variable you need another buffer in which to format the string that will be passed to system() function. There are a few different ways to do it, one way is to use strcpy followed by strcat

WCHAR cmd[255];

_tcscpy(cmd,_T("net localgroup administrators /add  "));
_tcscat(cmd,buffer);
_wsystem(cmd);

One problem with system() and _wsystem() is that there is no way to prevent the cmd box from appearing on the scrren momentarily while the command is being executed. If you want to hide that then you need to call a different function, such as CreateProcess(). I'm not sure whether it can be hidden if ShellExecute() is called or not. But I know that it can be hidden with CreateProcess().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I am trying to call the borland C++ DLL from VS 2005 .But its giving Linking Error.

You can't link Borland DLLs from Microsoft compilers because name mangling is different. Even C language names are different -- Microsoft puts an underscore before the name while Borland doesn't. There are even more difference in c++ function mangling.

However, all may not be lost. You might be able to dynamically link by calling LoadLibrary() then GetProcAddress(). This will return a pointer to the function which you can then use to call the function.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Reverend: You would start a revolt with that song -- it's Country song and a lot of people hate country. I could only listen to the first 10 seconds.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

strcmp() wants two char* not two std::string

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

int size=0;
int a[size];

That creates an array of 0 elements. That's not what you want. Move line 11 down to below line 13 where the value of size is known. Note: you will have to use a c++11 compliant compiler to compile this.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here and here are a couple charts that tell you the clock cycles for the MUL and SFL/SHR instructions on the 80X86 family of processors. The shift operation is less than 1/4th the time of the multiplication instruction. How the compiler will optimize the multiplication operator is dependent on the compiler and you have no control over that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

<off-topic> why the hell do you guys want avatars like old bits of carpet? </off-topic>

I think that is a default avatar.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It was down just a few minutes ago. PFO is also down.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

have you learned pointers yet? You will need to use a pointer to find the first digit character in the string. Then use a loop to print the next 8 digits to the screen, one digit at a time.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The Stepford Wives -- good movie for a few laughs

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Welcome back -- good to see old faces again :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yea, there's a link at the bottom of every page, just scroll all the way down and you will find it on the very last line.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What is User Acceptance Test? What is the test for? That would give us some ideas what to call those rankings.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

the program you posted is incorrect. line 4 should be double, not int.

I tested it with both Code::Blocks which uses gcc compiler and VC++ 2012 and they both report "equal"

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

"People seem naturally comfortable disclosing personal information on unprofessional websites

Those are probably the same people who post prolifically on FaceBook and MyPage.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm using wamp on MS-Windows 7, and inside www folder I created cgi-bin folder and put some files in it. When I go to Chrome I enter localhost/cgi-bin and it responds

The requested URL /cgi-bin/ was not found on this server.

There are other folders in www and it can access them ok. There's even cgi-bin.old which it accesses.

Do browsers block people (and me) from gaining access to cgi-bin folders?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

somewhat

ifstream in("filename.ext");
std::string line;

while( getline(in,line) )
{
   switch(line[0])
   {

   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I tested the original problem in this thread on VC++ 2012 and it produced the expected results -- "equal". But other compilers may produce different results, especially old MS-DOS programs such as Turbo C and Microsoft C (the version released prior to year 2000).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Boost apparently thought it is important enought to write a library for floating point comparisons.

In most cases it is unreasonable to use an operator==(...) for a floating-point values equality check.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
if (x == 0) then  // O(1) simple variable access
      for i = 1 to n do // O(n)
           a[i] = i; // O(1) simple variable access

Now, read this again until you understand it

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If 5.2 and 5.200001 are the same number under the given floating point representation,

They are not the same, which is why you can't test for equality. If you want to learn more about it read this wiki article

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Didn't you read any of the links I gave you? The very first one explains how to do it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Sugar-Free vanilla pooding made with skim milk.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

if(a==5.2)

Should never test for equality with floats and doubles because of extraneous fractional values beyond your control, which is due to the way floats/doubles are stored in memory. The value 5.2 might actually be stored in memory as 5.200001 and the test for equality will fail. Since the program printed "less" my guess is that the value of variable named a might be something like 5.199999

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What have you studied about big O notation? Here are some examples

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

And you walked 10 miles everywhere...up hill...both ways, and you were thankful for it. ;)

And in snow up to my waist :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Most of us older folks lived our entire lives without a phone attached to our bodies, so what we never had we never miss. I have a cell phone (not a smartphone) but rarely carry it with me. The only reason I even have the damned thing is so that I can have it in the car in case of an emergency. It came in handy a couple times for that. Otherwise for me it is just a useless toy.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you have the entire line in a char array then just do this:

char line[255] = "B 127.2 Hi 183.2 Someone 23.8 Lost"


switch(line[0])
{

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You didn't ask a question.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A 2d array is declared like this:

int values[10][20];

It is very similar concept to an Excel spreadsheet, which has columns and rows. In the above declaration the array has 10 rows and 20 columns. What phorce illustrated above is a 1d array, not a 2d array.