asking for data structure

i have a project in c++,
i am a beginner of c++.
i have to make a student management system , which basic information about name,address,gpa,major,years etc.

i try to make this code..
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 <iomanip>
using namespace std;

struct StudentData{
	
	char name[100];
	int number;
	char major[100];
	float gpa;
	char addres[100];
		
}data;



int main(int argc, char** argv) {
	
	
	
	cout<<"Enter name "<<endl;
	cin>>StudentData.name; 
	cout<<"Enter number"<<endl;
	cin>>StudentData.number;
	cout<<"Enter major"<<endl;
	cin>>StudentData.major;
	cout<<"Enter Gpa"<<endl;
	cin>>StudentData.gpa;
	cout<<"Enter Addres"<<endl;
	cin>>StudentData.address;
	return 0;
}


what makes me confused is how can i make more record of a student??
since from cin i straighly defined StudentData.element

i want that when user type his name, it is automatically generate new object name.
e.g if i type john, all the input belongs to john. and when i type David,,all the input belongs to david.

please give me an enlighment or giving an advice what should i do..
i am very very newbie about this..
or if u have a step-by-step completly tutorial in data structure..please inform me..

Thanks in advance
A way to do what you want is to create multiple StudentData's. See below

i want that when user type his name, it is automatically generate new object name.


If you want to do this you'll have to use either an stl container and/or pointers. If you haven't learned them yet you'll need to do so before you can do what you want.

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <iomanip>
using namespace std;

struct StudentData{
	
	char name[100];
	int number;
	char major[100];
	float gpa;
	char address[100];  // added an s
		
};

int main(int argc, char** argv) {
	
	StudentData John;
	StudentData Dave;
	
	cout<<"Enter name "<<endl;
	cin>>John.name; 
	cout<<"Enter number"<<endl;
	cin>>John.number;
	cout<<"Enter major"<<endl;
	cin>>John.major;
	cout<<"Enter Gpa"<<endl;
	cin>>John.gpa;
	cout<<"Enter Address"<<endl;
	cin>>John.address;
	
	cout<<"Enter name "<<endl;
	cin>>Dave.name; 
	cout<<"Enter number"<<endl;
	cin>>Dave.number;
	cout<<"Enter major"<<endl;
	cin>>Dave.major;
	cout<<"Enter Gpa"<<endl;
	cin>>Dave.gpa;
	cout<<"Enter Address"<<endl;
	cin>>Dave.address;
	
	std::cout << John.name << " " << John.gpa << std::endl;
	std::cout << Dave.name << " " << Dave .major << std::endl;
	
	return 0;
}
thanks mgoetschius ..
but how if i want to automatically generate know object whenever new user is making a new input??
as i know,when i generate that code..i only have 2 object,,which are dave and john.

StudentData John;
StudentData Dave;


thank you..
Topic archived. No new replies allowed.