questions in vector & class

hello,

i want to write a simple university programme

please first see my 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream>
#include<string>
#include<vector>
using namespace std;


class subject
{
	string code;
 	public:
	void create_code();
	void list_of_code();
};

class student
{
	string name;
 	public:
	void create_student();
	void list_student();
};

int main()
{
	int size_of_student,size_of_subject;
	student student_attributes;
	subject subject_attributes;
	// creating new student first
	vector<student>new_student;
	cout <<"How many student do you want to create? ";
	cin >> size_of_student;
		for (int i = 0 ; i < size_of_student; i++)
		{
			student_attributes.create_student();
			new_student.push_back(student_attributes);		
				// creating subjects
				vector<subject>new_subject;
				cout <<"How many subject do you want to create? ";
				cin >> size_of_subject;
				for (int i = 0 ; i < size_of_subject; i++)
					{
						subject_attributes.create_code();
						new_subject.push_back(subject_attributes);		
					}
				cout <<"You successfully created a student with "<<size_of_subject<<" subjects "<<endl;
		}
	return 0;
}


please notice that my code doesn't include the member function for the classes(late i'll include it but for now help for my questions)

now my questions is, is my way correct to get the student name and new subject by using vector?

another question, how to list all the student? or list all the subject? (cout of vector))

another question is how to liast all student for a specfic subject? can you please show me

thanks
now i'm doing well

i update my code and it works, but i got some problems on getting data((new_student,new_subject)

the output is not same as input, for example input:empror9 ,output:mpror9 it's not complete

also the way in output is not good

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<iostream>
#include<string>
#include<vector>
using namespace std;

void control()
{
	cout <<"control";
}
class subject
{
	vector<string>new_subject;
	string code;
 	public:
	void create_code();
	void list_of_code();
};

class student
{
	vector<string>new_student;
	string name;
 	public:
	void create_student();
	void list_student();
};

int main()
{
	int size_of_student,size_of_subject;
	student student_attributes;
	subject subject_attributes;
	// vectors for students and subjects
	vector<student>new_student;
	vector<subject>new_subject;
	cout <<"How many student do you want to create? ";
	cin >> size_of_student;
		for (int i = 0 ; i < size_of_student; i++)
		{
			student_attributes.create_student();
			new_student.push_back(student_attributes);	
			// start to add subject for a specfic student
			cout <<"How many subject do you want to create? ";
			cin >> size_of_subject;
				for (int i = 0 ; i < size_of_subject; i++)
				{
					subject_attributes.create_code();
					new_subject.push_back(subject_attributes);		
				}			
		}
		
		for ( int i = 0 ; i < size_of_student ; i++){
		new_student[i].list_student();
		}
		for ( int i = 0 ; i < size_of_subject ; i++){
		new_subject[i].list_of_code();
		}
	return 0;
}

void subject::create_code()
{
	int size_of_subject;
	cout <<"Creat a new subject: ";
	cin.ignore();
	getline(cin,code);
	cout << endl;
}

void subject::list_of_code()
{
	cout << endl;
	cout << code << endl ;
	for (int i = 0 ; i < new_subject.size(); i++)
	cout << new_subject[i] << endl;
}

void student::create_student()
{
	int size_of_subject;
	cout <<"Creat a new student: ";
	cin.ignore();
	getline(cin,name);
	cout << endl;
}

void student::list_student()
{
	cout << endl;
	cout << name << endl ;
	for (int i = 0 ; i < new_student.size(); i++)
	cout << new_student[i] << endl;
}


please compile
please help
I just want to clarify why you need int size_of_subject inside the function create_student.
Hm have you tried just using getline instead of cin inside the main code?? why don't you try to make the vectors a public member and not private it might be a possible reason as to why they can't get the input right. I'll try to look into this further
wildsummerdream,

hi i tried all your suggestion but same problem :(
by the way i cant do like this
getline(cin,num_of_student);

it shows syntax error
hm, i see. I'll try then to figure out what's the real problem it might have been just something that has been overlooked.
empror9 wrote:
the output is not same as input, for example input:empror9 ,output:mpror9 it's not complete
well, on line 65 and 82 you have an ignore(). Now why? that skipps the first entered character
if i delete this code ignore()

it shows this error

http://www.daniweb.com/forums/attachment.php?attachmentid=18817&d=1294891655
Topic archived. No new replies allowed.