Jump to content

Question regarding python programming, specifically Object Oriented Programming


mitch08

Recommended Posts

Hi guys. I encountered this scenario online and I couldn't decipher what to do to make it work. I hope you could help me out..

 

So say for example you have a kiosk on your store and you want to program it for your customers. When a customer press number 1, he/she would be prompted to enter the product brand, model, price, and other specifics so that the system can store it and afterwards process it for the customer. However, not until the customer types in "-none", the system would continue asking him/her about the product. Also, there's a certain menu for the seller (the store) to look up the customer's entry by brand, price etc.

 

My question is, how should I tackle this? I think it's like putting input("Enter brand: ") into a certain variable and then attaching that variable to a class? However that would be complicated because there's also a menu for the seller wherein those things should be neatly grouped so the search can proceed. Sorry if it's kind of unclear but here's another analogy of it:

 

-----

 

[1] Enter the product that you want:

 

[a] Brand:

Price:

[c] Feature:

 

Do you want to add items to your cart? Y/N

 

-----

 

Now that's for the customer. Here's for the seller:

 

-----

 

[a] Search by brand

Search by price

[c] Search by feature

 

-----

 

So for example if I'm the customer and I enter "Skittles", and then I again enter "Snickers", it should be grouped neatly so when I use the seller mode, it can proceed smoothly too. I'm thinking of using a dictionary but we have 2 values: price and feature. How can I proceed with a specific search if it's grouped in a dictionary??

 

Sorry guys, total noob here.. Please help me.. Thank you so much...

Link to comment
Share on other sites

Argos uses a catalog. You can search their catalog using the ordinary levenshtein distance method which then gives you that product's specific serial number. You can then buy products by writing the serial numbers on a piece of paper and bringing it to the desk.

 

My question is, how should I tackle this? I think it's like putting input("Enter brand: ") into a certain variable and then attaching that variable to a class

 

To a cookie actually. You would create a database containing all your stuff with model,brand etc then you can run a search which basically selects all of a specific brand or price. Or a number of brands Heinz and Batchelors etc. Whether you use mysql or not is up to yourself.

http://www.tutorialspoint.com/python/python_database_access.htm

Edited by fiveworlds
Link to comment
Share on other sites

Argos uses a catalog. You can search their catalog using the ordinary levenshtein distance method which then gives you that product's specific serial number. You can then buy products by writing the serial numbers on a piece of paper and bringing it to the desk.

 

My question is, how should I tackle this? I think it's like putting input("Enter brand: ") into a certain variable and then attaching that variable to a class

 

To a cookie actually. You would create a database containing all your stuff with model,brand etc then you can run a search which basically selects all of a specific brand or price. Or a number of brands Heinz and Batchelors etc. Whether you use mysql or not is up to yourself.

http://www.tutorialspoint.com/python/python_database_access.htm

This doesn't look like a webdev assignment as much as a python assignment for lists, directories, dictionaries, etc.

 

Since I've already responded, this is technically unofficial modly advice, but don't give actual code as this is almost certainly homework.

Link to comment
Share on other sites

Since I've already responded, this is technically unofficial modly advice, but don't give actual code as this is almost certainly homework.

 

 

I don't know about other countries but usually mysql is tested as a written paper here. I don't see a problem with linking to a textbook or two.

Link to comment
Share on other sites

Since I've already responded, this is technically unofficial modly advice, but don't give actual code as this is almost certainly homework.

 

 

I don't know about other countries but usually mysql is tested as a written paper here. I don't see a problem with linking to a textbook or two.

I meant code for the specific problem. Just steer clear of doing the actual project.

Link to comment
Share on other sites

Hey guys, I really don't understand what you just talked about. I just badly need some help, in layman's term if possible. I know you're geniuses in this kind of stuff, but please understand I'm a student that's just beginning my journey on this field. So please, if you can explain it in a much simpler term, and if possible with examples (not necessarily the actual code 'cause I think it's not your habit to do so), I would really really appreciate it. Thanks in advance.

Link to comment
Share on other sites

If it would be general OOP language question, like for C++, I would make class for entry like pseudo-code:

 

class Entry

{

private:

String m_Name;

String m_Category;

int m_Price;

 

public:

// constructor with initialization of fields..

Entry( String &name, String &category, int price )

{

m_Name = name;

m_Category = category;

m_Price = price;

}

// Get/Set methods for each field, so they're keep black-boxes (private).

};

 

and yet another class for dynamic list of entries:

 

class DataBase

{

Add( Entry *entry );

Remove( Entry *entry );

int GetLength();

Entry *GetEntryByIndex( int index );

// etc. support functions

};

 

At the beginning of app, make instance of database, and add all entries to it. Could be from file.

 

Database db;

db.Add( new Entry( "Egg", "Food", 1 ) );

db.Add( new Entry( "Chicken", "Food", 10 ) );

db.Add( new Entry( "Bread", "Food", 3 ) );

db.Add( new Entry( "Mercedes", "Car", 100000 ) );

db.Add( new Entry( "Core i7", "Computer", 1000 ) );

 

You can override += operator to be even more OO (if it's the main aim):

db += new Entry( ... );

If it would accept Entry &, it could be shorted to:

db += Entry( ... );

 

Then whenever you have to find entry by name, you go through all entries in dynamic-list like DataBase class object (db), and compare one by one with parameters like name, category, price.

It will be slow with too many entries but good enough for a start for beginner.

 

int count = db.GetLength();

for( int i = 0; i < count; i++ )

{

// required overloaded operator [] in dynamic-list class

// required overloaded operator == in name class (in the example above it was String, but could be subclassed, and overriden)

if( db[ i ] == name )

{

// found

}

}

 

eventually the main loop (less OO friendly):

 

Entry *entry = db.GetEntryByIndex( i );

if( entry->GetName() == name )

or

if( entry->GetCategory() == category )

or

if( entry->GetPrice() == price )

 

You could later sort them, and use binary-search algorithm to speed up operation.

Binary-search allows finding entry in f.e. 4 billions big dynamic-list, within 32 comparison operations.

 

Searching/filtering functions should be implemented as methods of class DataBase. For easy upgrade to the real database like mentioned MySQL in future.

 

ps. Implementations will differ, from language to language. Just giving the basic idea how to organize data.

Edited by Sensei
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.