473,379 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

object members in vector

Okay guys,

I got my vector to work but how do I do the following:

1. I create a bank account object.
2. I place that bank account object in the vector
3. I have a loop that repeats steps 1 and 2

My question is.....how do I get the vector to have objects of the same
type, but with different names?

I want account1 in element 0
account2 in element 1
And so on until the user finally decides that they want to break out of
the loop.

Aug 4 '05 #1
3 1834
nick wrote:
I got my vector to work but how do I do the following:

1. I create a bank account object.
2. I place that bank account object in the vector
3. I have a loop that repeats steps 1 and 2

My question is.....how do I get the vector to have objects of the same
type, but with different names?
They already have different names. If your vector is known as 'v', then
the first object is 'v[0]', the second is 'v[1]', and so on.

I want account1 in element 0
account2 in element 1
And so on until the user finally decides that they want to break out
of the loop.


That I don't understand. If you want to give your accounts some names,
then you should declare a member variable 'name' or sometning in each
account object.

V
Aug 4 '05 #2
Okay, I think I see your point. So let me rewrite it and tell me if I'm
on the right track....
I create an object called bankAccount. I activate all the member
variables and functions for it. So let's say that it has a deposit
amount of 1200. That bankAccount object goes into vector position[0]. I
stay in my loop and it creates another bankAccount object with, let's
say, a 300 deposit. That goes into my vector at position[1].

So I then have X amount of bankAccount objects in my vector with
different deposit amounts. So I need to create a loop to add elements
to the vector just like a for loop with arrays?

Aug 4 '05 #3
nick wrote:
Okay, I think I see your point. So let me rewrite it and tell me if I'm
on the right track....
I create an object called bankAccount. I activate all the member
variables and functions for it. So let's say that it has a deposit
amount of 1200. That bankAccount object goes into vector position[0]. I
stay in my loop and it creates another bankAccount object with, let's
say, a 300 deposit. That goes into my vector at position[1].

So I then have X amount
... X number ..
of bankAccount objects in my vector with
different deposit amounts. So I need to create a loop to add elements
to the vector just like a for loop with arrays?


I suppose... A standard container 'vector' is essentially a wrapper
around its C++ array of data, with the ability to add to that array (the
"regular" C++ array doesn't allow that) and remove from it. A 'vector'
behaves similarly to the other standard sequential containers, 'list' and
'deque', with a couple of exceptions (lacking a better word).

You were asking about the names of those objects. I am not sure what you
need those names for, but often in banking every account has a number and
an associated customer name. With that information at hand you can either
look up the account (find it in the container) by the number or by the
name, provided that the lookup functionality exists. You don't have to
assign any other "number" than the position in the vector (and the lookup
functionality for it already exists in the indexing operator, []), but you
could add the functionality to look the accounts up by the customer name
as well...

V
Aug 4 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jessica | last post by:
Hi, I have a question regarding the object-oriented issue. I understand that a class is a type. I have an array class. Now say that I want to implement an algorithm A that uses the array class....
21
by: Jason Heyes | last post by:
I want to allow objects of my class to be read from an input stream. I am having trouble with the implementation. Here are the different approaches I have tried: // Version 1.0 - Default...
9
by: jon wayne | last post by:
OK! I had this nagging doubt Consider (without worrying abt access specifiers) class Kid : public Parent{...}; Parent::someFunc() { Kid k; }
4
by: ahrimen | last post by:
Hi, First I'll state my over all goal = a text based game with several rooms that have several exits as my first real program that I've done without the help of a book. I can make a normal...
23
by: sidney | last post by:
Hi all, I am trying to make a vector containing objects the have a reference member. However, as soon as I try to push_back an element into this vector, g++ balks at the fact that it needs to...
14
by: Glen Dayton | last post by:
While looking at some old code I ran across a snippet that increments a pointer to access different members of a structure: .... struct Badness { std::string m_begin; std::string m_param1;...
4
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
12
by: hweekuan | last post by:
hi, it seems i can't assign the const variable u in class A, one way to solve the problem may be to build a copy constructor. however, why does C++ or vector class not like this code? my g++ is:...
12
by: subramanian100in | last post by:
Suppose class Base { public: virtual ~Test() { ... } // ... }; class Derived : public Base
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.