gusano79 247 Posting Shark

Decryption is the same as shifting by (26 - shift)

gusano79 247 Posting Shark

Are you able to post your current schema definition? Having that kind of specific information will help.

Meanwhile...

1) Does this mean I need to create a different table for every location (this doesn't seem wise as I don't know how many location will exist as the company grows in the future)?

Your instinct is correct; you don't want multiple tables for locations. How would you write a query in a database like that without having to revise and rebuild your application every time you wanted to add or remove a location?

2) Can I create a data table to "define" the warehouses, the ID numbers, etc.?

Yes, that's better. A table that represents the various locations parts could be stored. Then your inventory can just refer to that table to indicate where a part is.

3) if so, where do I store the dynamic (changing) data for each part number/location for things like selling price, number of units sold, total value sold, etc.?

In general, keep information about an object with the object it's about. Examples:

  • Selling price is probably about the part itself, for a simple application.
  • Number of units sold is about a specific order.
  • Total value sold is about an order. You could store this with the order, but there's no need to actually save this value anywhere--you can always calculate it for any order by adding up the prices.

4) Must I break apart the existing INVENTORY …

gusano79 247 Posting Shark

A few other comments:

int input

"Input" is where the value comes from, but in general, variable names should describe what the variable means more than anything else. In this case, something like totalRolls would make it much easier for someone else to read and understand your code (this includes future versions of yourself).

rollHist[0] += 1

Not really wrong, but rollHist[0]++ is more idiomatic. At least that's what I've observed.

/*  This block of code generates the random numbers for die1 and die2 
* and stores the values of each roll in the die1 and die2 arrays.

I don't know if you're supposed to be writing separate methods yet, but I'd like to observe that anywhere you feel that an introduction like this is appropriate, it is also probably appropriate to turn that section into its own method. Just as a general guideline.

gusano79 247 Posting Shark

First thing that leaps to my attention is this section:

if (rollTotal == 2) // for each roll of the dice. With the if 
{
    rollHist[0] += 1; // statements it calculates how many times
}
if (rollTotal == 3) // a certain value is produced by a roll of the 
{
    rollHist[1] += 1; // dice.
}
if ...

Notice that the second (and subsequent) if statements will always be evaluated, but we know that if rollTotal is two, only the first if block matters. A better way to express this is to use else clauses--something like this:

if (rollTotal == 2) // for each roll of the dice. With the if 
{
    rollHist[0] += 1; // statements it calculates how many times
}
else if (rollTotal == 3) // a certain value is produced by a roll of the 
{
    rollHist[1] += 1; // dice.
}
else if ...

Although if you're always testing the same variable, you may be able to use a switch statement as well. Something to consider.

But notice that every if block looks very similar to the others. The code may produce correct output, but patterns like this usually indicate that there's a more compact way to represent the operation, which IMO is better as long as it's not too hard to understand (for this exercise it won't be).

To get you started: Can you identify a relationship between the value of rollTotal and the integer you're …

gusano79 247 Posting Shark

What never was clearly explained is why we would need to use such related forms
What is the benefits of using such a related form? Are there negatives to using this? What situations would best warrant the use of a Parent/Child Form?

The Wikipedia article on MDI is a good place to start.

Because of the three "related" forms, I began to wonder if this would be an instance where I should have a Parent form and it's two Children.

I think not. You have a clear sequence of steps, which IMO lends itself better to more of a wizard/assistant style.

gusano79 247 Posting Shark

Have another look at your Average method... it's not really calculating an average, is it?

static double Average(List<int> listvalues)
{
    double variance = 0;
    foreach (int value in listvalues)
    {
        variance += (intList[i] - Average) * (intList[i] - Average);
    }
    return (double)variance / listvalues.Count;
}

You're trying to calculate variance there, which is getting a little ahead of itself.

First thing you should do is write a method that just does a simple average--you need that value to calculate variance. Then you should end up with something like this in a Variance method:

double average = Average(intList);
// Build a new list of (intList[i] - average)^2
return Average(newList);
gusano79 247 Posting Shark

Ah, ok. You'll want to store the result of calling Average(intList) in a double variable--here, a local variable in Main would work just fine.

gusano79 247 Posting Shark

From Wikipedia's article on variance:

The variance of a random variable or distribution is the expectation, or mean, of the squared deviation of that variable from its expected value or mean.

So you need the mean first; you're already calculating that in Average. So for each original number, find its difference from the mean, square that, and remember it... then average all of the resulting values.

The calculation should look very similar, and you should in fact be able to reuse Average to get the final result.

Does that make sense? If not, there is a basic example in the Wikipedia article that may help

gusano79 247 Posting Shark

It looks like the problem is that you're testing every single user name in the table, and every one that is wrong will result in the "no access" dialog showing.

The naive fix would be to hold off showing the dialog until you've checked all the users and then only show it if you didn't match the user name and password anywhere.

A much better solution is to first select the row where the user name matches--there should only be one, right? Then see if the password matches the one in the database for that user. If you can find the user name and the password matches, you've authenticated someone; otherwise (i.e., can't find user name or password doesn't match), then deny access.

Really there's no need to loop over the entire table (I'm assuming that's what rs represents). If this is an assignment, then it's a really horrible example of how not to work with a database.

gusano79 247 Posting Shark

How are you running your normal database queries (or do you have any)?

SqlCommand.ExecuteNonQuery and SqlCommand.ExecuteScalar are simple enough if you're using plain ADO.NET.

You can also wire up stored procedures to a LINQ data context or an Entity Framework data model.

gusano79 247 Posting Shark

Following is the code I have written and its not working.

"Not working" isn't a very useful description of the problem. When posting questions about broken code, please provide some details, e.g., what you think should happen that isn't happening.

Meanwhile, this is wrong:

string ID = Convert.ToString(reader);

If you want to get values from the reader, you need to tell it which column to retrieve:

string ID = reader["Username"];

...or whatever column name you want.

Also, your query looks suspicious:

select empID from TB_credentials WHERE @Username = userNameTXT and @Password=passwordTXT

Normally column names don't start with @, and the named parameters do:

select empID from TB_credentials WHERE Username = @userNameTXT and Password=@passwordTXT

Recommended reading: Retrieving Data Using a DataReader

Some other observations:

string ID = reader["Username"];
return ID ;

This is a little verbose--no need to declare a variable if all you're going to do is return it; the following does the same thing, but is shorter and more readable:

return reader["Username"];

Also, what happens when there is no data returned? In this section:

while (reader.Read())
{
    return reader["Username"];
}

If reader is empty (i.e., the requested user doesn't exist), the entire while loop is skipped, and you have no code to deal with this possibility. Also, using a while loop here is somewhat inappropriate, as you only care about the first record returned.

Consider this alternative:

if(reader.Read()) …
gusano79 247 Posting Shark

If Feed is a method, it would look something like this:

public void Feed(string FoodType)
{
    if (Food != "Unknown")
        Console.WriteLine("{0} eats some {1}.", Name, Food);
}

public void Feed()
{
    Feed("Unknown");
}
gusano79 247 Posting Shark

Which line does the exception happen on?

gusano79 247 Posting Shark
gusano79 247 Posting Shark

I was wondering if those @ numbers mean that they all point to the same thing

I'm saying I don't think they do. Now that I know you're using DLL Export Viewer, I can say that with certainty. The two hex columns after the name are "address" and "relative address"--these tell you where the names point.

but I will assume you are correct.

Don't assume, we know what that does :)

I've checked off Show Unmangled Names only.

Well, different compilers mangle names differently. I think one of two things is going on here: Either DLL Export Viewer doesn't officially support unmangling the output of whatever compiler was used originally, but it does well enough that all it leaves is the parameter size at the end; or maybe it's adding the parameter size to the name itself, though that seems unlikely.

gusano79 247 Posting Shark

All of the examples I've seen have ordinals separated from the function name by white space; your numbers appear to be part of the mangled names. I think @28 indicates the total size of the function's arguments.

gusano79 247 Posting Shark

When I've seen this kind of error before, it's usually one of two things:

  1. The ActiveX object wasn't registered properly--or simply doesn't exist.
  2. The application was built with reference to a version of the ActiveX object with a different class ID.

I'd look at #1 first--which ActiveX components are you using, and are they all installed on the test PC?

gusano79 247 Posting Shark

"nab" isn't a permutation of "abnana". Permutations can get you closer to a complete solution, but that's not all there is to it.

True, you'd also need to look at subsets of the original set of letters.

For completeness, you'd also want to consider a nonempty game board, which would involve finding words with specific letters in fixed positions.

gusano79 247 Posting Shark

I think the question is actually "how do I generate permutations?"

gusano79 247 Posting Shark

both the strings are not working for me

If you want specific help, give us specific problems; "not working" doesn't tell us much. Does the runtime throw an exception? Any error messages?

gusano79 247 Posting Shark

http://www.connectionstrings.com/ is a useful resource if you're having trouble getting the connection strings right. Check out their FoxPro page.

gusano79 247 Posting Shark

I occasionally work with .NET applications that connect to FoxPro databases; we use the OLE DB drivers.

As for the column names, that's a choice on the part of the database designer--though if I remember correctly, FoxPro column names can't be very long; that's why the cryptic abbreviations.

gusano79 247 Posting Shark

The code looks okay. OleDbConnection lives in System.Data.dll; does your project reference this assembly?

gusano79 247 Posting Shark

I can get it to display just fine. Could you post your entire program?

gusano79 247 Posting Shark

If I declare b as zero at the top of the program above the while command the program runs but into an infinate loop WHY?

Indentation matters in Python. As you wrote it, line 3 (b += 1) is not part of the loop. Indent this line to match the print statement and it should work as you expect.

Also, instead of a while loop, consider using a for loop here.

gusano79 247 Posting Shark
gusano79 247 Posting Shark

i am now using this code
but still i got same error , :(

Look at the return value of File.Create--it returns a FileStream object. If you want to close the file immediately, you need to do something like this:

FileStream fs = File.Create("fred.txt");
fs.Close();

Or if you're into the whole brevity thing:

File.Create("barney.txt").Close();

If you're going to be writing to it pretty soon after, though, it's better to keep the stream object around and just write to it later.

gusano79 247 Posting Shark

could you please highlight those parts? i'm too tired to try to find them

Apart from mn.cpp, have a look at C::C() and D::D(); that's where you should be creating the new B and C, respectively.

gusano79 247 Posting Shark

Here's your problem:

int main(){
D* d;
d->add();

You've declared D* d, but you never assign it a value. It could be pointing anywhere. Then you go and try to use this uninitialized pointer. That is an excellent way to get a segfault.

I compiled this using GCC, and it said "warning: 'd' is used uninitialized in this function". Do you get a warning like this? If it does, you need to pay more attention to your compiler. If it doesn't, get a new compiler.

This is not the only place you're using uninitialized pointers; I count at least two more.

Bonus comment:

#include "A.h"
#include <vector>
#include <iostream>
using namespace std;
class A;
class B {

In B.h, when you include A.h, you're including the definition for the A class already. No need to declare class A; after that. Again, there are a few places you're doing this.

gusano79 247 Posting Shark

Hi guys,

I'm trying to use the random number generator as part of the GSL library and it is working fine for a few hundred 'rounds' of my code (it is used quite a few times per round) but then i get an error message in the command window:

gsl: rng.c:46: ERROR: failed to allocate space for rng state
Default GSL error handler invoked.

Please post the part of your code that is actually generating the random numbers.

My guess is that you're creating a new generator every time you need a random number, and you're not destroying it after you're done. If that's the case, the allocator will happily reserve whatever amount of space it needs for each generator, and eventually you'll run out of memory.

gusano79 247 Posting Shark

If you check my tags, I am using microsoft windows and windows API.

Even so, please take the five seconds to put it in the question as well. You'll get better answers faster.

EnumDisplaySettings can get you the current video mode or a list of available modes.

gusano79 247 Posting Shark

Hello,
I have been working with opengl and other graphics libraries and they all require the bits per pixel of the screen on initialization of a window. My question is, is there any way to get the system's preffered bits per pixel? or that of the monitor?

Depends on your OS. You can't use the OpenGL API until you have an OpenGL context, the creation of which is system-specific. Your operating system API should have some way to get both the current video mode and a list of all supported video modes.

gusano79 247 Posting Shark

Ya, I guess you got it right there, but will Java be enough for accessing it? Like, CAN I do it in Java? How I'll do it is a separate journey altogether :D but can I do it?

Maybe someone who knows for sure can chime in; I don't think Java supports promiscuous sockets. If that's true, you'd have to come up with a native library and a JNI wrapper if you still wanted to use Java to analyze the traffic. For example, jNetPcap.

gusano79 247 Posting Shark

A direction you might look in is your network card's scandalously-named promiscuous mode.

gusano79 247 Posting Shark

May i distribute it? and how it works?

SQLite is public domain, so do what you want, including distribute it.

It's a C/C++ library, although you can find bindings to other languages if you look for them. There's a C-function API for managing the database files, and you write almost-standard SQL queries for data access.

gusano79 247 Posting Shark

If you prefer a database, but need an offline save file, and don't want to install a database server, you might look at SQLite.

gusano79 247 Posting Shark

Depending on your OS, you probably have a simple "play this audio file" system call available.

There are also a variety of third-party multimedia libraries that provide a more flexible audio API, for example, SDL.

If you have some time to play with it, you might also consider OpenAL.

gusano79 247 Posting Shark

I'd say that to be a successful software engineer, you should at least be comfortable with basic algebra. You've got that covered already, so stopping now shouldn't hold you back.

But.

Any math class you take or technique you learn will prove useful and make you better at software engineering. Some mathematical areas may seem highly specialized, but you might be surprised at how widely some of the concepts from those areas can be applied.

My recommendation, then, is continue to take math classes as long as you find them interesting and rewarding, and stop when they start turning into pain and drudgery.

It almost doesn't matter what the topics are, but there are a few standard classes that you should probably take at some point if you choose to continue with the math: Linear algebra, and symbolic logic. Linear algebra will tone up your matrix and vector muscles, and there are a variety of techniques that come from there that are handy to have in your back pocket. The logic course is likely a philosophy credit, and you'll probably be ahead of the class because of your experience with programming, but it should help formalize your thinking and fill in any gaps you might have.

gusano79 247 Posting Shark

if i open with notepad the original file ( from that i obtined that .h ) and the outputed file .. they are the same.
But if i open the outputed file it is closing when i start it :|

If they're really the same, there shouldn't be any difference, so something must have changed.

I tried :

std::ofstream file;
file.open("ADRIAN2.EXE");

file.write( (const char*)nosize, nosize_size);
file.close();

Hm. Have you tried opening the file in binary mode? You'll definitely want to do that with an executable.

gusano79 247 Posting Shark

Depending on your application, it might not matter too much, but there can be a significant performance penalty for getting all twenty fields instead of the four you need. Not just because of the amount of data sent across the wire, but also if you have multiple instances of your application running, it's that much more load on the database server.

It also keeps your application cleaner for greater maintainability. Next time someone looks at your code--and this could be you, six months from now, when you've forgotten everything =)--they won't have to wonder "why aren't we using these other sixteen fields?"

zachattack05 commented: That's a good point +5
gusano79 247 Posting Shark

You can use something like this to turn the binaries into code, then write them out using the standard library.

If you want to get fancy with the linker, you can also link them to your application directly.

gusano79 247 Posting Shark

You have:

ptr[M][N] = (double) 1000 + i * N + j;

M and N will always be outside of the array, and are the same every time through the loop.

You probably meant:

ptr[i][j] = (double) 1000 + i * N + j;

Same goes for the cout immediately after.

gusano79 247 Posting Shark

1. there is an elegant way of doing things more clean and not a list of files that i very confusing?

A common practice is to use a different folder for each namespace, with one type per file. This is automatically supported by some IDEs--Visual Studio and SharpDevelop come to mind.

2. its a good idea of lets say - open a abstract class file and add - i think its called - nested classes for all the classes derived from it?

I don't recommend using nested classes too much. I prefer to stick to one class per file; it makes things easier to find.

3. side-Question: there is a way of tell the solution to automatically set the folder-usings above every class i create?

Your IDE may have some sort of template it uses when generating new classes. If it does (again, VS and SD do) you can probably customize this template to start out with whatever content you want.

gusano79 247 Posting Shark
gusano79 247 Posting Shark

Please post the error message and the code where the error happens; we can't help if we don't know what's going wrong.

gusano79 247 Posting Shark

Please i want to end a program in a function outside
function main.

Is exit what you want?

also want to end executing a function of type void without
allowing it to end

Not sure what "it" is at the end there... if you want to exit a void function, a simple return statement should do.

gusano79 247 Posting Shark

I have investigated using an IntPtr: I have no way of knowing the length of the data coming out of the dll method so I can't successfully copy the data to a byte[]. If there was a way to iterate over the data IntPtr provides access to then I would be able to find the string null terminator and copy to content to a byte[].

Is there a way to manipulate IntPtr to get a byte[] of the method output?

You can use Marshal.ReadByte to locate the string terminator, along these lines:

int length = -1;
while(Marshal.ReadByte(ptr, ++length) != 0);

Then you can use Marshal.Copy to get the array:

byte[] bytes = new byte[length];
Marshal.Copy(ptr, bytes, 0, length);

And there you have it.

Extra credit: Turn this into a custom marshaler for UTF-8 strings.

PoovenM commented: Clean, simple answer. Thank you :) +6
gusano79 247 Posting Shark

i'm trying to study this paper: http://db.grinnell.edu/sigcse/iticse2007/Program/viewAcceptedProposal.asp?sessionType=paper&sessionNumber=113

it has the 'linearization' in its title. i just want to know what is its meaning. i searched google but it gave me something like calculus which i dont get.

No calculus involved :)

The paper describes a method that analyzes source code, which is not necessarily linear (conditional branches, loops, recursion, &c.). They perform a basic simulation of the program without actually running it, which yields a plausible sequence of actions (i.e., a list, which is linear) that the program might take during normal execution.

gusano79 247 Posting Shark

Private Sub Button_Click() Handles Button1.Click, Button2.Click, Button3.Click
MsgBox()
End Sub

Can anyone tell me how can we print that which button is clicked?????

The Click event is an EventHandler, which takes two parameters, the first of which is the object that caused the event--in this case, it's one of your buttons. Then you can use something like the button's Name property to display which one it is.

gusano79 247 Posting Shark

Hi :)i heard about mvvm & mvc design pattern but when i search for them i get only things that relative to asp & wpf... and those are (if i dont get it wrong) web developers

MVC = Model/View/Controller

You're getting a lot of ASP links because of Microsoft's ASP.NET MVC, which is an implementation of the MVC design pattern for ASP.NET.

MVVM = Model/View/ViewModel

This one is much more closely tied to Microsoft products; it came from them originally as a pattern for use with WPF. It's not as widely applicable as MVC yet, but that's only because it's newer.

should i leave the search for knowledge on those patterns?
i dont know nothing about them, i just heard on them and thought if i need to learn about them

These are useful architectural patterns; I would recommend you at least become familiar with the basic MVC pattern, perhaps leaving the more technology-specific patterns and frameworks for when you actually end up using them.