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

I've used it a little; post your script and what you want fixed, and maybe we can help.

You also might post in "Legacy Languages" instead--IIRC, it used to be called "Legacy and Other Languages," and still seems to be a general bucket for languages that don't have their own special forum.

gusano79 247 Posting Shark

Nitpick: The bisection method is something else.

This looks like it wants to be a binary search, but then it does a linear search on half of the array... strange. Is this a home-grown search algorithm, or is it a specific assignment?

Notice that the array is sorted, so repeated values will be next to each other. Once you've found the value, just keep shifting right as long as it's the same value. Not super efficient, but it'll get you there.

gusano79 247 Posting Shark

Android Developer Guide: OpenGL is a good place to start.

If you're interested in a high-level API, there are libraries out there like Unity and jMonkeyEngine.

gusano79 247 Posting Shark

if I put an if clause in the swap method to check and see if array[a] is != to array[b] I find several instances where they actually are equal and if I don't count those with my counter the the number of viable swaps decreases.
...
whether or not I should consider them viable swaps or not since the computer is doing them then it is using up resources therefore they should be counted.

As far as the swap method is concerned, I'd have it just do the swap, whether the elements are equal or not. This keeps it simple and clear--when you say "swap," you'll want it to really mean "swap," not "swap except if the elements are equal."

But that doesn't answer your question: Should you check for equality before swapping? I wouldn't. It would only matter if the swap operation was inefficient, but we're talking Java here, so any complicated data structure will be represented by a class, and you'll be swapping references to instances of that class, not the instances themselves.

And the other half of your question: Should you count swapping equal elements? If you don't check for equality, then you have to... but you'd want to even if you were checking. Counting swaps is more about the characteristics of the algorithm than it is about sorting any specific data set--if the algorithm says to swap the elements, you'll want to track it regardless.

bguild commented: Well said +6
gusano79 247 Posting Shark

the best way to count the number of swaps

Wouldn't you want to increment your counter inside of swap?

the tests that I have run seem to be correct however Quicksort is so complex I do not trust my data.

One way to validate your counting is to work out a small example by hand, and compare it to what your code is doing. It's not proof, but it is evidence.

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

Look at the desired output; count the number of extra spaces used to indent each line. Do you see a relationship between the number of spaces and the value of x?

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

SDL and Allegro aim to provide a more or less complete game programming library, but you might also consider combining several separate libraries that focus on smaller areas--especially if the general-purpose libraries don't quite do what you want.

A loose assortment of links to get you thinking: Chipmunk, GLFW, OpenAL, Horde3D, Lua, PhysicsFS, SQLite, Ogre3D, Guile, Irrlicht, irrKlang...

gusano79 247 Posting Shark

Are you using Thread directly because you have to (e.g., it's an assignment or something), or is this just exploration? If you have the freedom to explore alternatives, you might be interested in BackgroundWorker.

gusano79 247 Posting Shark

Also could be that nothing is listening at 192.168.1.7:1024

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

Hi again... I got super busy for a while there and this got left behind; sorry. Would it still be helpful to continue?

gusano79 247 Posting Shark

Ok, so inheritence can have a "Is a"/"Can Be" relationship so obviously "Customer" {is a} "Item" wouldn't work

Right, that's what an inheritance relationship would mean.

however, association could be used, surly? Customer {can have} "Item" relationship would, IMO anyway..

That's certainly a possibility. But that isn't an inheritance relationship, which is what I was talking about. What you're describing is more of an ownership property, e.g., Customer has some sort of collection property to contain Items.

Shouldn't some relationship be here though?

Yes, there should... and this is where I'll guess that we're looking at an incomplete assignment. The whole customer/order idea is pretty common when teaching object-oriented concepts, but usually you have something like a class called "Order" that takes care of relating Customers to Items.

gusano79 247 Posting Shark

Oh, also. Here's my copy I've been editing so far:

using System;

    namespace Hangman
    {
        class Program
        {
            const string letters = "abcdefghijklmnopqrstuvwxyz";

            static readonly string[] wordBank = {
                "Fishing", "Computer", "Tree",
                "Location", "Technician", "Work",
                "Butterfly", "Toddler", "Flowers"
            };

            static void Main(string[] args)
            {
                Console.WriteLine("      ~*~*~*~*~*~*~*~*~*~*~*~    ");
                Console.WriteLine("     ~*~Welcome to Hangman!~*~   ");
                Console.WriteLine("      ~*~*~*~*~*~*~*~*~*~*~*~    ");

                Console.Write("Please enter your Name: ");
                string name = Convert.ToString(Console.ReadLine());

                Console.WriteLine(name + ", Welcome to Hangman");
                Console.WriteLine("       ~*~*~*~*~*~*~*~*~*~*~*~    ");
                Console.WriteLine("         ~*~*~Hangman!~*~*~    ");
                Console.WriteLine("       ~*~*~*~*~*~*~*~*~*~*~*~   ");
                Console.WriteLine();

                // creates a random number to choose a word from word bank
                Random random = new Random();

                //selects the word from the wordBank using randomNumber
                string gameWord = wordBank[random.Next(wordBank.Length)];

                // TODO: Hide un-guessed letters.
                Console.WriteLine(" The word is: ", gameWord);

                bool repeat = false;
                char guess;
                do
                {
                    Console.Write("Please enter a new letter: ");
                    guess = Console.ReadKey().KeyChar;

                    if (letters.IndexOf(guess) != -1)
                    {
                        guess = Char.ToUpper(guess);
                        repeat = false;
                    }
                    else
                    {
                        Console.WriteLine("You can only enter letter values, please re-enter choice.");
                        repeat = true;
                    }

                } while (repeat);

                // TODO: Finish the program; see if the letter is in the word and go back for more guesses.
            }
        }
    }
gusano79 247 Posting Shark

Before we talk about how to guess letters and replace the *s, there are a number of problems in the code that should be addressed first. I might seem to get a little pedantic here, but clearing up these issues will make the code shorter and easier to understand, as well as clear up a few misunderstandings about how some of these things work.

From the top:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

You're only actually using the System namespace; remove the rest of the lines so it's clear which parts of the library you're actually using:

using System;

At the start of Main:

static void Main(string[] args)
{
    string Name;
    string gameWord;
    bool[] boolLetters;
    char[] wordArray;
    char[] letters;
    char PlayerGuess;

This advance declaration is required in C, but not C#. In most cases, I prefer to see variable declarations at the same point they're first used, like this:

string Name = Convert.ToString(Console.ReadLine());

That way I don't have to go back to the top of Main to remind myself that Name is a string.

(Note: I'm editing my copy of the code as I go here, so some of the following recommendations will make more sense if you're following along with the edits)

This is a little verbose:

char[] letters = new char[26] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', …
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

What have you tried so far? Show us whatever you've written to solve this problem, and we'll try to point you in the right direction.

gusano79 247 Posting Shark

I noticed some other issues... what compiler are you using? GCC complains about these things; are you getting warnings when you build?

In globals.h, you have #endif;--the semicolon shouldn't be there; just use #endif.

In globals.cpp, currentstate = NULL; should be GameStates* currentstate = NULL;--you need to reiterate the type in the definition.

There is no need to include GameStates.h again here, because it is already included in globals.h.

In Intro.h, you have a variety of function implementations for your Core class--these should be in Core.cpp, not in an unrelated header. Or is that a copy/paste error in the post?

gusano79 247 Posting Shark

One problem is in Core.h:

class Core
{
    ...
} core;

Every time you include Core.h, it defines a variable core--that's where the 'multiple definition' errors are coming from.

Assuming what you want is a single global instance of your Core class, you can do it the following way instead.

In Core.h:

class Core
{
    ...
};

extern Core core;

Somewhere in Core.cpp:

Core core;

This way, everything including Core.h gets the extern declaration, which tells them that there's a variable called core defined somewhere, but the only place it actually gets defined is once, in Core.cpp.

I see you've used extern elsewhere in your code--does this makes sense?

gusano79 247 Posting Shark

i think that it can be done by using nested class???

.

... and then apply inheritance in your classes.

No to both; you've already been told which classes to write, and there is no inheritance relationship involved:

the program is to print a bill using two classes-customer and item

You also know what the data fields should be:

class customer, members are itemname and customer name.in item, members are itemname itemcode,itemprice,noof items

...and what support functions to write:

and functions to calculate bill and update stock

The basic structure has been laid out for you pretty clearly.

Post your code.

Yes to this!

If you've already tried to write something, post it and we'll do our best to point you in the right direction. If you're having trouble with it, read about how to write classes, try to write them yourself, and post what you come up with.

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

I don't think you use single quotes to delimit dates in FoxPro--IIRC, you need to use curly braces, e.g., {8/1/2012}.

gusano79 247 Posting Shark

(sorry for the delay; I've been out of town for a week)

For now, all the websites are using SSOLib.dll.. right?
So i need to add this dll on my real world websites as well in order to implement SSO

Right. The article you linked explains how to set it up under the heading "OK, how do I implement SSO for my sites?" (sadly, there is no anchor in the article for me to link to)

Is it possible not to add the .dll, but just to make website point at it, so that the .dll remains to my end (because we dont want to make the website come in the lime light, It should just point at that.).

As far as I know, no. ASP.NET needs to have the DLL available locally as part of the Web site because it will execute on each page request.

This library is just there to handle connecting to the behind-the-scenes "www.sso.com" Web site. All of the actual SSO work is done by that site, so it shouldn't be a big deal to reference SSOLib.dll in each client Web site project--that is how this particular implementation is intended to be used.

gusano79 247 Posting Shark

How are you storing the image in the testing123 table?

gusano79 247 Posting Shark

Do you mean after you decode the base-64 text it's still not an image? It looks like the start of a JPEG file, and you get "CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality" in the decoded text, but there's nothing after that.

gusano79 247 Posting Shark

The authentication in the sample project is just a stub, but you knew that already because you're trying to replace it with a database lookup. And you knew where to find the authentication code, which suggests you figured out where the login information was going.

I'm not sure what you're asking for here, unless you just stumbled across the authentication code and are wondering how the login info gets there. If that's the case, then here's how I'd trace it:

  1. Pick one of the Web site projects; for purposes of this discussion, I'm going to use www.domain1.com
  2. Users log in at Login.aspx with the "Login" button
  3. Button click handler is in Login.aspx.cs at btnLogin_Click
  4. The handler calls Login, which is part of the base class PrivatePage, in the SSOLib project (PrivatePage.cs)
  5. PrivatePage.Login calls Authenticate in AuthUtil (AuthUtil.cs)
  6. AuthUtil.Authenticate makes a Web service call to AuthService.Authenticate, in the www.sso.com project (AuthService.asmx, ultimately App_Code/AuthService.cs)
  7. AuthService.Authenticate calls UserManager.AuthenticateUser (App_Code/UserManager.cs)
  8. UserManager.AuthenticateUser scans through a hard-coded list of three users to see if you entered one of them.
brian71289 commented: Great Job! +0
gusano79 247 Posting Shark

I cant figure out how the users are being authenticated

It's implicit in the SQL query. If the user name exists in the database and the password matches, then this code authenticates the user.

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

I tried almost all the things and its not working its still giving me the same error, I don't know why.

Please show us what you tried here--that means code.

gusano79 247 Posting Shark

If you were to throw return user; at the bottom of your function the error would go away.

Correct, but...

This is because if for some reason it did not go into your using statements it would never see a return statement.

No, the only thing that would skip code in the using block is throwing an exception, and that possibility doesn't provoke the "not all code paths return a value" compiler message.

This is the real problem:

while (reader.Read())
{
    return user;
}

It's possible that reader has no data, so reader.Read() might return false the first time you call it, and the return statement would never happen.

Once you've properly relocated the return statement, though, you'll notice that it always returns null--you're not doing anything with user. Just mentioning this in case you thought you were done :)

gusano79 247 Posting Shark

Depending on the research topic, it may also be useful to model systems and run simulations.

gusano79 247 Posting Shark

Please post the connection string you're using.

Are you using MySQL Connector/Net?

gusano79 247 Posting Shark

Please post the code in which this error occurs. That will help us figure out what's going wrong.

gusano79 247 Posting Shark

Please don't write your methods like this:

public void GetString(out String value)
{
    value = stringValue;
}

A simple return statement is shorter and easier to read. I recommend you don't write methods with out parameters unless there is truly a need for them. For an example, see Int32.TryParse or Dictionary.TryGetValue.

Also:

public String GetString
{
    get
    {
        return stringValue
    }
}

"GetString" isn't a very useful property name, and if you're not going to do anything special with stringValue, it is (once again) much shorter and more readable to use automatic properties:

public String UsefulPropertyName { get; }

Don't worry about performance yet; try and write simple, clean, readable code first. Once your application is more or less feature complete, it may already run fast enough that the extra boost won't matter. If it doesn't run as fast as you want, then use a profiler to see where the actual performance bottlenecks are. Then you can worry about how to speed them up.

My two cents: If you're writing anything worth using, the speed of a simple property retrieval really isn't going to be your worst-performing code.

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

Can you zip up your source and C::B project files for us?

gusano79 247 Posting Shark

Do you mean the radius of a circle? You can't get a radius from just its center point; that's not enough information. Or are you talking about something else?

gusano79 247 Posting Shark

Linking console executable: bin\Debug\intro1.exe
Execution of 'mingw32-g++.exe -o bin\Debug\intro1.exe obj\Debug\main.o' in 'D:\Documents\intro1' failed.
Nothing to be done.

Is that the entire build output, or is there anything else, especially before this?

It looks like maybe your source file hasn't been added to the project in C::B.

gusano79 247 Posting Shark

How do you want this general property to work? Will users of this class be providing the storage type name?

DrMAF commented: yes, exactly. +0
gusano79 247 Posting Shark

looks like dirs is null. what do I do now?

What's in your app.config file?

gusano79 247 Posting Shark

Which line does the exception happen on?

gusano79 247 Posting Shark

Either settings or Dirs is null. An easy way to see which one is to change this:

for (i = 0; i < settings.Dirs.Length; i++)

...to this:

var dirs = settings.Dirs;
for (i = 0; i < dirs.Length; i++)

That'll tell us for sure what's null.

gusano79 247 Posting Shark

From what you gave us, it looks like Settings.Load() isn't assigning anything to the Dirs object. Are you using the standard Visual Studio settings object, or is this a custom object?

Please post the entire exception, including the stack trace. That will help us figure this out.

Also, try not to post such a large chunk of code. Make a copy of your project and start removing parts until you're down to what you think is the minimum amount code that still has your problem. This will make it easier to find the problem, and folks around here will be more inclined to read your post.

gusano79 247 Posting Shark
gusano79 247 Posting Shark

error: expected ';' before '::' token.

You have to get the iterator from the class, not an instance. Try this:

for (std::string::iterator it = (s.words_input).begin();

error: 'it' was not declared in this scope.

This one disappears once you fix the above problem.

Vasthor commented: thnx +0