Verified:

TheORKINMan Game profile

Member
1305

Jul 25th 2011, 1:45:26

I have a rather specific problem. On my last assignment for the semester in Intro to Programming. Haven't had any issues with previous assignments until this one :\ The assignment is to created a banking system where you add a user id, last name, first name, balance etc...

Assignment requires two classes to be created, one called Account which will store user info and one called BankingSystem which will house the functions.

I'm *THINKING* what I need to do is create vectors for each field (account ID, last name, first name etc...) I'm also very unsure of how the two class objects are going to relate to each other. I assume BankingSystem functions will be modifying Account data? This is our "final" so to speak so that's all the guidelines he's given us this go around and we have to do everything else with our own design choices. Just fishing for anyone out there who may know C++ well as to whether I'm on the right track for what I need to do here.
Smarter than your average bear.

Dibs Ludicrous Game profile

Member
6702

Jul 25th 2011, 7:09:07

why you make my brain hurt so early?
what the heck is a vector?
oh, a dynamic array... duh.
create vector of Accounts.
use BankingSystem to modify Accounts.
think you are having problems in visualizing how objects work.
go away now you bothering me.
There are no messages in your Inbox.
Elvis has left the building.

Ozzite Game profile

Member
2122

Jul 25th 2011, 7:57:57

Yeah, basically what dibs said.

Instead of having a vec of each field type, have an account class that has an accountID,name, etc. The banking system can have a vec of accounts and should have functions that operate on the Accounts class, that is how they will connect.

Also your question isn't really C++ specific, but about OO programming in general, so that may be where you want to review.
Ah, mercury. Sweetest of the transition metals.

deepcode Game profile

Member
309

Jul 25th 2011, 10:49:25

Isn't the whole point of OO to keep each object distinct and have each object maintain it's own data for greater reuseability?

The functions that manipulate the account data should be in the account class, not the banking system class. Otherwise, what ozzite said.

account
account->setdata()
system->account->setdata()

edit for ()'s, obviously even if it makes no sense gotta do what the assignment actually asks of you.

Edited By: deepcode on Jul 25th 2011, 10:56:53
See Original Post

ArsenalMD Game profile

Member
560

Jul 25th 2011, 11:28:43

not me

Dibs Ludicrous Game profile

Member
6702

Jul 25th 2011, 11:29:31

dunno. maybe they're trying to keep data separate from code for some reason.
There are no messages in your Inbox.
Elvis has left the building.

Erian Game profile

Member
702

Jul 25th 2011, 11:31:30

What the others said.

Your original idea is more akin to how you might do it in C (or any other non-OO language).

You need to "visualize"/group distinct objects in your design, that contains associated data for those object. I.e. a "car" object would contain objects such as "tyre", "door", "window". You would NOT describe the world as a set of all tyres discrete from all doors etc. if you have a car object. That makes no sense from an object oriented point of view.

This is very basic OO, so if you can't understand the reasoning behind this kind of abstraction, either your course material sucks, or you need to read up on it more (no offense).

Pang Game profile

Administrator
Game Development
5731

Jul 25th 2011, 14:28:57

ya... pretty much what the others said :p

OO programming is a concept which if taught poorly will be difficult to grasp. Try to remember that objects are a collection of attributes and functions that share a common theme, data and functionality.

In your case, you'll need several different classes...

as others have said, BankingSystem will have a variable called 'accounts', which will be a vector of BankAccounts (or whatever you name that)
BankAccounts will have variables for account id, last name, first name, etc... (as you stated)
Since BakingSystem will have all the functions, you'll need to design it to interact with the Account objects within the vector. I'm not sure what the system is supposed to do functionality-wise, so that's about as far as I can go :p

Hope that helps make it clearer :)
-=Pang=-
Earth Empires Staff
pangaea [at] earthempires [dot] com

Boxcar - Earth Empires Clan & Alliance Hosting
http://www.boxcarhosting.com

Newworld Game profile

Member
386

Jul 25th 2011, 16:36:48

Watch out for Dangling Pointers! :P

*Newworld runs off and hides
pew pew pew

Dibs Ludicrous Game profile

Member
6702

Jul 25th 2011, 16:43:56

since it counts as a "final", i'm a bit annoyed with your teacher. she should've slapped you around a bit more.
There are no messages in your Inbox.
Elvis has left the building.

TheORKINMan Game profile

Member
1305

Jul 25th 2011, 18:16:49

I'm somewhat annoyed also :P This is Intro to Programming aka the first class on a course map for a comp sci major. The first exposure most people have had with OO programming and the class is entirely online and consists of "Here is the book now do the assignments by the deadline".

I learned PHP before taking this class which is decidedly not an OO language or at least not nearly to the degree C++ is but I do understand objects. I've actually done more complex assignments then this one already in this class but the "new concepts" for this assignment are vectors and saving/loading data from a file. My main confusion here was a poor understanding of vectors. I didn't understand that vectors could hold more then one data type simultaniously which is why I thought to split it up the way I did. Thanks for all of the clarification though it helped out quite a bit :)
Smarter than your average bear.

Pang Game profile

Administrator
Game Development
5731

Jul 25th 2011, 18:28:26

yes, you can make a vector of any object type, simple or complex :p
-=Pang=-
Earth Empires Staff
pangaea [at] earthempires [dot] com

Boxcar - Earth Empires Clan & Alliance Hosting
http://www.boxcarhosting.com

qzjul Game profile

Administrator
Game Development
10,263

Jul 25th 2011, 21:20:32

PHP can be object oriented. It is the way we use it for this game :)

I don't believe C++ supports vectors inherently does it? presumably you're using some sort of library for that...
Finally did the signature thing.

Dibs Ludicrous Game profile

Member
6702

Jul 25th 2011, 21:24:26

i don't mind that you like PHP, but if you start trying to dish C++, i'm a have to get really drunk and call you so many names that i'll get banned for a year.
There are no messages in your Inbox.
Elvis has left the building.

hanlong Game profile

Member
2211

Jul 25th 2011, 21:31:53

why do you need vectors for each field?

just use composition to piece it together.

just create a account class and have your main function instantiate multiple account (one per user).

have bankingsystem take in an account as its parameter... like double withdraw(Account a, double amount); and you are done.

your main function would instantiate a banking system and multiple accounts and do crap with it.
Don Hanlong
Don of La Famiglia

TheORKINMan Game profile

Member
1305

Jul 25th 2011, 21:32:44

qzjul: PHP CAN be object oriented. However it is not centered around OO programming like C++ is. Objects are an addition to PHP5 that were not in PHP4.

Yeah I'm using #include <vector> for the driver so as far as I can tell vectors are not inherent to C++.

Thanks to you guys pointing out my stupidity I've finished my "Add an account" portion of the project. Still have to do Delete an account(which dosnt seem like it'll be hard), display accounts, save to file and load from file then I'm done with this class :P
Smarter than your average bear.

hanlong Game profile

Member
2211

Jul 25th 2011, 21:34:40

vector is part of the C++ STL

all those functions you mentioned can be straightforwardly coded into the bankingsystem class.

the account class just contains the account specific information (like name, balance, etc.) and functions to read/write from it so the bankingsystem class can use it (since you shouldn't be using friend classes or inheritance since this isn't a is-a relationship, but more of a has-a)

everything else goes into bankingsystem. no need to complicate matters, the straightforward approach can solve this problem and that's the one you should take =)
Don Hanlong
Don of La Famiglia

qzjul Game profile

Administrator
Game Development
10,263

Jul 25th 2011, 21:36:19

And yea, you shouldn't need vectors... as far as I can tell
Finally did the signature thing.

Dibs Ludicrous Game profile

Member
6702

Jul 25th 2011, 21:39:28

say the data takes up 10% of the memory required by the object, do you need vectors then?
There are no messages in your Inbox.
Elvis has left the building.

hanlong Game profile

Member
2211

Jul 25th 2011, 21:41:21

vectors has nothing to do with memory required or anything.

if you need to store something in a list format with a size that needs to adjust bigger and smaller and still retain fast search big-Os you use vectors.
Don Hanlong
Don of La Famiglia

Dibs Ludicrous Game profile

Member
6702

Jul 25th 2011, 21:42:19

be nice Dibs. %@#%$%@#%@!

Om Mani Padme Ohm.
There are no messages in your Inbox.
Elvis has left the building.

Trife Game profile

Member
5817

Jul 25th 2011, 21:45:50

ORKINMAN WANTS TO CREATE A EARTH EMPIRES BOT!!!!111oneone

TheORKINMan Game profile

Member
1305

Jul 25th 2011, 21:49:35

I *THINK* I have a handle on this project now but just in case anyone was wondering this is the actual assignment guidelines:

Details: Write a program to simulate a simple banking system.

Your first task is to create a class called Account. This class will store a person's account ID, passcode, last name, first name, and balance.

For your second task, you will create a class called BankingSystem. This class must have at least the following functionality:

Add a new account.

Delete an existing account.

Inquire on an existing account (or all accounts).

Save accounts to a file.

Load accounts from a file.
BankingSystem must also use a private data member that is declared as follows:

std::vector<Account> accounts_;

Your third task will be to develop a driver program. The driver program will print some type of menu allowing the user to choose the option they want. Instead of using a BankingSystem object, you must use a pointer to a BankingSystem object with the new operator. Your book describes this operator on pages 476-477. So, in your driver program (in main()), you would write the following:

BankingSystem* myBankingSystem = new BankingSystem();

At the end of your program (end of main() before returning), you have to free this memory explicity by writing the following:

delete myBankingSystem;
Smarter than your average bear.

Dibs Ludicrous Game profile

Member
6702

Jul 25th 2011, 21:52:46

meh, i'm still grumbling about php. Plagiarists Have Problems.
There are no messages in your Inbox.
Elvis has left the building.

hanlong Game profile

Member
2211

Jul 25th 2011, 21:57:14

oh so they want u store all the accounts the banksystem knows.

this is even easier than i thought it would be then. you literally just follow the instructions verbatim :P and add account objects to your vector and delete, fetch, etc. as member functions of bankingsystem.

this is more of an exercise of the vector API under the pretense of "Banking Systems" then trying to OO model a banking system :P
Don Hanlong
Don of La Famiglia

TheORKINMan Game profile

Member
1305

Jul 25th 2011, 22:02:59

Yes once you guys pointed out how retarded my view of vectors was this assignment became much much easier :P
Smarter than your average bear.

Ozzite Game profile

Member
2122

Jul 25th 2011, 22:16:20

Originally posted by TheORKINMan:
delete myBankingSystem;



OMG!!! DON'T DELETE YOUR BANKING SYSTEM

just playing around...

Although in reality you don't need to delete stuff if the next thing you will do is exit the program since all memory will be deallocated then. Not to say a douchey grader wouldn't take off points :-P
Ah, mercury. Sweetest of the transition metals.

qzjul Game profile

Administrator
Game Development
10,263

Jul 25th 2011, 22:35:11

ah i thought you just wanted one account to be created and one banking system; for an expandable array ya you need either vectors or pointers;

pointers ftl
Finally did the signature thing.

TheORKINMan Game profile

Member
1305

Jul 25th 2011, 22:37:13

Yeah he takes off points if you dont follow "Good programming practices" which I understand. You guys should have seen the email he sent out after the last assignment haha he was like "Some of you aren't doing what you're told including sending me programs that don't compile expecting me to fix your mistakes before grading." and "Some of you are putting lazy header comments. Please at least put your name and some type of description of the file/program. Putting nothing is the worst thing you can do." At least I know I'm not the most incompetent person in class when it comes to this ;)
Smarter than your average bear.

hanlong Game profile

Member
2211

Jul 25th 2011, 23:16:59

you should add in reference counting and smart pointers for your banking system and impress him then!
Don Hanlong
Don of La Famiglia

Pang Game profile

Administrator
Game Development
5731

Jul 25th 2011, 23:21:00

scrap C++ and do it in C instead!

malloc the crap out of the assignment! :p
-=Pang=-
Earth Empires Staff
pangaea [at] earthempires [dot] com

Boxcar - Earth Empires Clan & Alliance Hosting
http://www.boxcarhosting.com

hanlong Game profile

Member
2211

Jul 25th 2011, 23:25:48

screw C

x86 assembly ftw!

mov ax, 1h
Don Hanlong
Don of La Famiglia

TheORKINMan Game profile

Member
1305

Jul 25th 2011, 23:33:36

Actually there are 10 points of extra credit available if you add in the ability to deposite and withdraw money. But tbh I dont think I need it. My lowest grade has been a 95.
Smarter than your average bear.

Pang Game profile

Administrator
Game Development
5731

Jul 25th 2011, 23:34:29

I never learned x86 assembly... I worked on a Motorola 68000 back in undergrad

it was the same processor as the Sega Genesis.

MOVE.L (A1),D0
SONIC.B (A1),D2
-=Pang=-
Earth Empires Staff
pangaea [at] earthempires [dot] com

Boxcar - Earth Empires Clan & Alliance Hosting
http://www.boxcarhosting.com

Akula Game profile

Member
EE Patron
4106

Jul 26th 2011, 0:07:57

*sticks fingers in ears* lalalalalala
=============================
"Astra inclinant, sed non obligant"

SOL http://sol.ghqnet.com/
=============================

galleri Game profile

Game Moderator
Primary, Express, Tourney, & FFA
14,044

Jul 26th 2011, 1:57:35

You all should be ashamed of yourselves! Helping out Orkinman to get a good grade!


https://gyazo.com/...b3bb28dddf908cdbcfd162513

Kahuna: Ya you just wrote the fkn equation, not helping me at all. Lol n I hated algebra.

CKHustler

Member
253

Jul 26th 2011, 2:08:28

Oh hanlong, assembly? Of all the languages I think I hated that one the most. lol

I think I did this exact assignment like 6 years ago. I haven't programmed(intensely) in a few years, but I think my first programming class had this assignment in it. I remember making a pizza ordering program in there as well lol.

deepcode Game profile

Member
309

Jul 26th 2011, 7:02:39

<3 ASM

move ah, 1eh
mov dx, [msg]
int 21h

Dibs Ludicrous Game profile

Member
6702

Jul 26th 2011, 7:33:50

Originally posted by galleri:
You all should be ashamed of yourselves! Helping out Orkinman to get a good grade!


shhhh. it's a trick. we help him get good grade, so he get good job, so we can bum money off him.
There are no messages in your Inbox.
Elvis has left the building.

TheORKINMan Game profile

Member
1305

Jul 26th 2011, 20:01:35

Okay so this is probably going to be another stupid question. I'm at the point now in option 3(display account information) where users need to be able to put in an account number and show only that specific account's information. I have the option setup where it displays all accounts using an iterator. But I'm not sure what vector function to use to locate a specific value in multiple Account objects within the vector.
Smarter than your average bear.

TheORKINMan Game profile

Member
1305

Jul 26th 2011, 20:08:53

I actually just thought of a way to do it using a while loop to search through all of the values until it finds one that equals the value I'm looking for. But I'd have to imagine there's a better way to do it.
Smarter than your average bear.

hanlong Game profile

Member
2211

Jul 26th 2011, 20:09:16

bah stop getting us to do ur hw ;P
Don Hanlong
Don of La Famiglia

TheORKINMan Game profile

Member
1305

Jul 26th 2011, 20:11:58

nobody is making you respond, and you havent actually written any of the code for it nor am I asking you to :P
Smarter than your average bear.

Kalick Game profile

Member
699

Jul 26th 2011, 20:24:44

Originally posted by TheORKINMan:
I actually just thought of a way to do it using a while loop to search through all of the values until it finds one that equals the value I'm looking for. But I'd have to imagine there's a better way to do it.


That sounds like a reasonable way to do it. There are more efficient search algorithms, but I'm sure that solution is fine for the class you're in.

Erian Game profile

Member
702

Jul 26th 2011, 21:30:23

Use this:

http://www.cplusplus.com/reference/algorithm/find/

You need to overload the < operator of your Account class for this to work (if you do operator overloading in an assignment as simple as this your professor should give you bonus credits :))

TheORKINMan Game profile

Member
1305

Jul 26th 2011, 22:23:00

Assignment done and turned in. Thanks guys.
Smarter than your average bear.