i am required to develop a system to record details of student.
This system should be implemented using structure and array. i am required to develop a structure which contains student details such as Student ID, Student Name, Nationality and Gender.

1st-i have to insert new record
2nd-delete record
3rd-sort record
4th-display record

my question is how to use a structure and array in this program. i haven't done my coding. but i wish to know the steps. i have learned this but not in coding. please show me the way so that i can improve. can i know what's the function of file/io and pointer? thanks

Create a class to hold data's:

class PersonInfo
{
private:
	std::string name;
	std::string nationality;
	char gender;
	// and so on	
public:
	 //some methods to get datas , set datas and any other function
	//that you think will be sufficient to this class usually goes here.

};

Now create a array of class :

const int NUM_OF_SUTDENTS = 25; 
PersonInfo[NUM_OF_SUTDENTS ];
//use loops to initialize datas. 
// and go on from there.

Hey firstPerson, where the h*ll do you see in his spec that he has to use a class?

This system should be implemented using structure and array. i am required to develop a structure which contains student details such as Student ID, Student Name, Nationality and Gender.

To the OP:
I already wrote an extensive post about this, which you can find here:
http://www.daniweb.com/forums/post949513-2.html
(Edit 1 and Edit 2 don't apply to your problem)
Also read this one:
http://www.daniweb.com/forums/post949543-3.html
(which contains some corrections)

This is probably enough to get you started, in case it isn't, I strongly suggest you to Google for a tutorial on structures.

as FirstPerson has told you . You should provide an interface for editing the variables but must not provide direct access to its members.

Well if there is the question of Deleting records, or Adding New Records, I wonder if you are given a bound, For example the Max number of elements in the array, or is it based upon Dynamic Storage with new and delete

"Hey firstPerson, where the h*ll do you see in his spec that he has
to use a class?"

That was uncalled for. If he really needs to use structs, then just
switch the keyword class to struct, realizing that struct by default
has public members , while class by default has private.

Whats up with the attitude?

so far the array that i've learned is as below..


#include <iostream>
using namespace std;
int main()
{

int a [5];
cout<<"enter 5 numbers : ";
for (int i=0; i<5; i++)
cin>>a;

cout<<"you have entered : ";
for(int c=0; c<5; c++)
cout<<a[c]<<" ";

return 0;
}

but,i still don't understand it. for example if want to insert new record in array.the maximum set is set to 100.then if it is more than max,it should give warning. what are the steps? what should i put for the variables? make it in a class? then,, delete record form the student id, sort record according student name and id and finally display record..

even in the previous reply by firstPerson, i don't get it.. im lost there.. would you kindly explain the codes n show me how?

Actually, an array is a list/set of variables, for example:

int array[15];

The above array reserves memory for 15 elements (of type int) (as all arrays start with element 0, the upperbound of the array is 14 (and not 15))

Let me give you an example on where arrays come in handy:
Imagine, you have to keep track of the scores of students (yes, I see the irony :P), and you have to store scores for about 15 students, then you could either: declare a variable for holding each student's score, or you could create one array containing 15 elements to hold each student's scores.

Using the declare-a-variable-for-each-student-approach, your code would quickly grow in size, e.g:

int score0;
int score1;
int score2;
int score3;
int score4;
int score5;
int score6;
int score7;
int score8;
int score9;
int score10;
int score11;
int score12;
int score13;
int score14;
.
.
.

(and even if you'd put multiple of these on the same line, it would still be pretty clunky, what if for example, you've to a thousand of those?)
Your input procedures would become something like this:

cout << "Enter score for student #1: ";
cin >> score0;

cout << "Enter score for student #2: ";
cin >> score1;

cout << "Enter score for student #3: ";
cin >> score2;

cout << "Enter score for student #4: ";
cin >> score3;

cout << "Enter score for student #5: ";
cin >> score4;

cout << "Enter score for student #6: ";
cin >> score5;

cout << "Enter score for student #7: ";
cin >> score6;

cout << "Enter score for student #8: ";
cin >> score7;

cout << "Enter score for student #9: ";
cin >> score8;

cout << "Enter score for student #10: ";
cin >> score9;

cout << "Enter score for student #11: ";
cin >> score10;

cout << "Enter score for student #12: ";
cin >> score11;

cout << "Enter score for student #13: ";
cin >> score12;

cout << "Enter score for student #14: ";
cin >> score13;

cout << "Enter score for student #15: ";
cin >> score14;
.
.
.

Imagine for a while, you're the big boss of a school, and you have to keep track of the score of 1000 pupils...
It would be very clunky, time-consuming and error-prone if you had to create a separate variable for storing each student's score.
(And then we're only talking about one score per student, probably later on, you'll want to store multiple scores per student, so what to do now? Again create another variable for each student? No, that's just where arrays come in handy :))

The same (as above), but using arrays:

int array[15];

for(int i=0; i<15; i++) {
   cout << "Enter score for student #" << i << ": ";
   cin >> array[i];
}

Yes, that's it :P
The big advantage of arrays here is that they don't take up so much space in your code, and, more important: you can use loops (like for) to iterate over the elements in it, by just specifying an index.
Sorry, forgot to tell that, but each element in an array has it's own (unique) index, an example:

// Display the scores of the 4th student (by specifying its index):
// (remember: arrays always start at zero)
cout << scores[3] << endl;

Another important thing about arrays (in C++) which you should never forget: C++ performs no bounds checking (as far as your compiler is concerned), that is:
you could declare an array like this:

int array[25];

And then you could put things like this in your code:

// These are examples of wrong array indexing on an array of 25 elements:

cout << array[25] << endl; // wrong! arrays start at zero, the upper bound of a 25-element array is 24

cout << array[136] << endl; // wrong! another array overrun

// Or even worse:
array[27] = 16; // wrong! you start writing in memory which doesn't belong to your program

Either of the above will probably cause your program to blow up at runtime, you should keep this in mind, because the most common mistake you can make in dealing with arrays is: using a loop somewhere in your program, and overrunning one of the array's bounds (because you chose a wrong condition for your loop, for example).

If you want a more flexible "array" for managing the student's scores, you could maybe try your hands on a vector.
('flexible' in terms of that it is able to grow and shrink when you add/remove elements from it)

A vector can dynamically change its size (grow or shrink) as elements are added or removed from it, with a normal array this isn't possible.
Once you've declared a normal array (by not using dynamic memory allocation), the array always has a fixed size, which can never change throughout your program's runtime.

Comments
that's a fine example

that was handy for me. so, i use array[100] in my case. i have to declare the variable and proceed with the function. thanx

Do you have to use arrays, or could you use vectors?

Even if you don't know what or how to use vectors, they are quite
easy. And it would be a learning experience.

Vectors are way much better and safer that raw arrays. You can
have any size of vectors. For arrays it has to be declared
like so , int a[40]. For vector they can be any size allowed by
memory.

hey guyz can u plz post the full code....i would appreciate ur kind help.... thanx...

Comments
seconded
No, go away and try your own homework and drop the silly "plzsndmetehcodez" kiddie speak

i am required to develop a system to record details of student.
This system should be implemented using structure and array. i am required to develop a structure which contains student details such as Student ID, Student Name, Nationality and Gender.

1st-i have to insert new record
2rd-sort record
3th-display record

my question is how to use a class and array in this program. i haven't done my coding. but i wish to know the steps. i have learned this but not in coding. please show me the way so that i can improve.

This article has been dead for over six months. Start a new discussion instead.