473,670 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loading an array of objects

143 New Member
Here's my quandry.....I am building a phone book program with student and staff classes. In main() I am to define 2 arrays 1 for students and 1 for staff.

Each array will hold objects. I have declared the student array and I have a constructor in the student class that doesn't take any arguments. So I have no problem declaring the objects.

The problem is, how do I define the objects and load them in the array?

Each student object contains the following data members. first name, last name, phone number (as string), GPA (as string) and # on hours enrolled (as int).

Using a for loop, how do I put these objects into the array?

And, oh yeah, it all needs to be written to an external file.

Here's my code so far:

Expand|Select|Wrap|Line Numbers
  1. #include "Student.h"
  2. #include <iostream>
  3. #include <string>    //for string manipulation of names
  4. #include <iomanip>    //for set width
  5. #include <fstream>
  6.  
  7. ifstream FileinStu;
  8.  
  9. void main()
  10. {        
  11.     //open external file
  12. //    FileinStu.open("phoneBookStu.txt");
  13.     //create 2 arrays to store data in and load from the file
  14.     Student stuArray[10];  //ensure there is a constructor that accepts no arguements
  15.     int stuCount = 0;
  16.  
  17.     for(int i = 0; i < 10 ; i++)
  18. //        FileinStu>>stuArray[i];
Mar 29 '07 #1
4 2382
Ganon11
3,652 Recognized Expert Specialist
How will you be getting the information? Will you be using user input to get the names and information? Will they be stored in a file?

Generally, you should have methods such as setFName(string str), setLName(string str), and setGPA(string str) so be able to load the data into an individual object. Once the object has been fully defined, you can add it to the array.
Mar 29 '07 #2
teddarr
143 New Member
I do have those functions in the student class. As a matter of fact set and get functions are just about all the class has in it.

There is also a constructor that will take all of the arguments as well as the constructor that doesn't take any arguments.

The original used interface is a menu that will have the selections of display all students, display all staff, display all entries in both arrays, display all entries with a given last name, and finally a selection for add a new entry. So I need to know how to add load the array with the furnished info and eventually add new entries.

We briefly talked about templates and the stack template the other night so I am thinking about using that.

But how do I get started? I'll post more of what I get as it works on the program.
Mar 30 '07 #3
Ganon11
3,652 Recognized Expert Specialist
Well, unless you are loading original data from a file (which you still haven't specified), then the only place you will be adding data is in the Add New Entry portion. You should declare some temporary variables to hold the information as you get it from the user, prompt the user for input, and once you have all the information, create a new Student object with the specified information and add it to the list.

Will you be storing the students in an array? In a vector? In some other data structure?
Mar 30 '07 #4
teddarr
143 New Member
I will be storing students in an array.
Mar 30 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

17
4803
by: Aguilar, James | last post by:
My previous example used the concept of a Shape class heirarchy, so I will continue with that. Suppose I have something like fifty different shapes, and I am trying to instantiate one of them. The trick is, the instatiation will be based on a string with the exact same name as the type that I am trying to instantiate. Obviously, writing a fifty element long switch statement is an inferior solution. So, how can I instantiate based on...
4
3738
by: Adrian MacNair | last post by:
Hi, I created an image gallery which displays 63 images in a slideshow. The problem is that the show was slow because each image loaded one at a time during the show. No problem right? I just did a preload script. But then the user has to sit for 5 minutes waiting for 63 images to download! My images are about 640x480 and average 100kb. Is this too much for one page to load? Should I load my slideshow into differerent windows? If so,...
4
9792
by: Kevin | last post by:
Hi, I have a input with type checkbox. I want it to be automatically checked if the value from the corresponding field in the database is also checked. I tried this: <% set objdc = Server.CreateObject("ADODB.Connection") etc ... sql="select maa13 from mytable" dim rsArray
9
4475
by: Ender | last post by:
I have an application that I would like third party developers to be able to create Plug-ins that will be dynamically loaded into our application to extend functionality. I have utilized the "Let Users Add Functionality to Your .NET Applications with Macros and Plug-Ins" article at MSDN for the dynamic loading of DLLs http://msdn.microsoft.com/msdnmag/issues/03/10/Plug-Ins/default.aspx
6
4498
by: Pete Davis | last post by:
I'm confused about what precisely the limitations are on loading plugins in separate app domains. In all my previous apps that supported plugins, I've loaded them into the same domain as the app, but I've just started playing around with separate AppDomains and I'm finding that I'm not having problems where I expected I would, so maybe someone can help me understand a bit better. I've read that objects instantiated in separate AppDomains...
5
12230
by: John Richardson | last post by:
I've been bothered for some time about my DataGrid not populating my rows very quickly. I have about 10K rows loading into the grid. I create a datatable dt with 2 columns, an ID and a display. The ID is a member of the keys array. I then create a DataView dv over the table, and sort it by Display and ID column (in case of duplicate Display). I then set my DataGrid.DataSource = dv; I then load the datatable with my rows, and this is...
1
1635
by: Dale | last post by:
I have a user control on a Windows Form that, in its Load event handler, calls a method from a class library to initialize an array of objects that are then used to populate a ComboBox. When I run the app, the method runs just fine. The class library returns the array of objects and the ComboBox is loaded. The problem I am having is when I try to open the form that contains the user control in the designer. Instead of the form, I get...
1
1465
by: rekkufa | last post by:
I am currently building a system for serializing python objects to a readable file-format, as well as creating python objects by parsing the same format. It is more or less complete except for a single issue I just cannot figure out by myself: How to load data that specifies immutables that recursively reference themselves. There are only a few solutions I can think of. One: While loading recursive objects, I always create empty versions...
9
1718
by: igor.tatarinov | last post by:
Hi, I am pretty new to Python and trying to use it for a relatively simple problem of loading a 5 million line text file and converting it into a few binary files. The text file has a fixed format (like a punchcard). The columns contain integer, real, and date values. The output files are the same values in binary. I have to parse the values and write the binary tuples out into the correct file based on a given column. It's a little more...
0
8471
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8815
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8592
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8661
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6216
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
2044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1795
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.