hello,

i want to write a simple university programme

please first see my code

#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

#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

For your output error, I assume it's because you are calling cin.ignore() before you take input. afaik you should do this after input, to flush the input stream.

hi akill,

i tried your suggestion but it doesn't works

hi akill,

i tried your suggestion but it doesn't works

So you have the same problem? It skips the first letter?

you can cheick the attach

you can chick the attachment

up up

up up

Bummer. I was going to help you until I saw this bump. How arrogant and presumptuous. Bye bye.

Bummer. I was going to help you until I saw this bump. How arrogant and presumptuous. Bye bye.

Who sees your reply will thinks you are the inventor of C++ or you are Bill Gates

i don't want to see you reply on any topic of me again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.