i want to create an array of structures

i want to create an array of structures

here i have my coding too

if any one can post a good array of structure coding with an explanation thankx alot#include<iostream>
#include<string>
#include<sstream>

using namespace std;

#define N_records 10

struct stud_info{

int no;

string name;

} student [N_records];

int main()
{
for (int X=1;X<=N_records;X++)
{
cout<<"please inset the student number\n";
getline (cin,student[X].no);
cout<<"please insert the student name\n";
getline (cin,student[X].name);

}
This reply is based on my limited understanding, and might be flawed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
#include<string>
#include<sstream>

using namespace std;

#define N_records 10

struct stud_info{

int no;

string name;

}; // remember the ;

int main()
{
stud_info student[N_records];  // declares an array (called student) that can hold N_records elements of type stud_info

for (int X = 0; X < N_records; X++)   // I started X at 0 because the first element in any array is arrayName[0]. I changed the <= in the continuation condition to < because the last element (in an array of 10) is student[9] (because the first is student[0]).
{
   cout<<"please inset the student number\n";
   getline (cin,student[X].no);
   cout<<"please insert the student name\n";
   getline (cin,student[X].name);
} // end of for-loop

// the code here should read values of name and no from standard input (cin) and assign them to student[0] through student[9]. If you want to store the data in a file or something, more code is required for that.

return 0;
}


hope this helped :)
Last edited on
Topic archived. No new replies allowed.