![]() |
I kind of need help on my program
Hi,
My partner and me are kind of new to c++ and we're working on a program that is rather hard(for our capabilities on c++). Our program is nearly finished and all we have to do is to allow our program to accept some data. The problem is that we want the user to be able to name his/her own structs as it will store their personal data/ students' data, but we don't know how :(. We also want the program to store the user defined names of the structs within another one that would allow data storage for each one of those names. The closest thing we could actually get to solving my problem was a block of code that asked for number of names and names and stored them in a char array(which didn't really work as the user would then actually have to count all the letters of the names that he/her would want to put in:icon_eek:) Anyway, here's the code if you want to look at it: :
// Cesis2.cpp : Defines the entry point for the console application. |
Re: I kind of need help on my program
What do you mean with "name his/her own structs"? Are you saying you want the users to name the actual object of the struct??? Users shouldn't even know that you're using a struct, all they care about is that you save their information. You can declare an array of struct objects (100 for example) and then use them as needed. Or if you want to get fancy, look into Vector (dynamic) arrays.
On a side note, why not use the string class instead of all the char[] arrays: :
|
Re: I kind of need help on my program
If you mean you want them to name each block of information (that you store in a struct) so they can find it later, you can use a map to do it:
:
struct blockOfInfo oldInfo, newInfo;Cprogramming.com has a good tutorial on maps. |
Re: I kind of need help on my program
What we want to do is to make a struct that can be remade into diffrent type of that struct. Like you want to add a new student to your database. we use the student struct to get his information. we want it so that all the diffrent students have a diffrent struct so that we dont have manually add a new struct every time some is new. so its automated.
|
Re: I kind of need help on my program
Quote:
|
Re: I kind of need help on my program
Quote:
Well, if that's the case you should also look into classes and inheritance. You will need to make a base class and then make subclasses to cover all your needs. You can then add any subclass of that base class into a vector or an array and process them. |
Re: I kind of need help on my program
Quote:
|
Re: I kind of need help on my program
Quote:
As an example, imagine a C-style string (array of char, with the string's end marked by a zero). You need to allocate space for the string plus an additional char element for the zero terminator. However, there are data structures that hide this sort of thing from you. The C++ string class is a good example. It allocates a block behind the scenes- say 20 characters- and tracks the current length of the string. It then allocates a larger block if it needs to, but this is all hidden from the user of the class.A vector is similar. Say you have a struct defined like so: :
:
:
:
The upshot of all this is that the user will not need to know in advance how many items they're inputting. The vector is sized to a default or specified size, and if this turns out to be too small, it will grow as needed. Anyways, you can read all about vectors right here (this reference in general is quite helpful and to-the-point, I find). |
Re: I kind of need help on my program
Ok I got the idea, thanks lectripharaoh
|
| All times are GMT -5. The time now is 7:16 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC