using vectors to enter sutend details

hello i want to add details of student like age and fees. How can i do it using Vectors. i dont know how to use multidimensional vectors.
For now i can input only Name, but i want to take age and fees as input for the same student also. here is programm

#include<conio.h>
#include <iostream>
#include <vector>
using namespace std;

int main()
{
vector<double> student_name;
string name;
char answer;

cout << "Do you want to enter numbers (y/n)? ";
cin >> answer;

while (answer == 'y')
{
cout << "Enter Name: ";
cin >> name;


student_marks.push_back(name);

cout << "Do you want to enter more names (y/n)? ";
cin >> answer;
}

/

for (int i = 0; i < student_name.size(); i++)
{
cout << "Student #" << i+1 << '\t' << student_name[i];
}
// '\t' is the code for the TAB character
getch();
return 0;
}
vector<double> student_name;???
I think what you are looking for are structs, not vectors.
And I agree with kbw, using doubles to store student names is sort of... weird, to say the least. Unless your students are all named after real numbers - in that case you should pay attention not to let them add together though, it might be hard to identify them afterwards (lame pun intended).
sorry it was mistake vector<double> student_name

What i want to do is, to add student name, his age and his fees. This fees should be added as total. When i delete this particular student from the list of students, his part of fee should also be deleted from the total amount. how can i do that ? i will be very thankful if you can show this by some small example
You can declare a student struct like that:
1
2
3
4
5
6
struct Student
{
     string name;
     unsigned char age; //This can also be an int. I only made this a char cause it's unlikely the student is more than 255 years old.
     unsigned int fees;
};


Then you could write a class to store the students
1
2
3
4
5
6
7
8
9
10
11
class StudentList
{
public:
StudentList() : totalFees(0){}
void addStudent(Student stud);
void removeStudent(Student stud);
~StudentList(){}
private:
unsigned int totalFees;
vector<Student> students;
};


Then you would just have to add implementations for the addStudent/removeStudent methods respectively, that would add or remove the students fees from totalFees when a student is added or removed.
Thankyou very much for your help, but i am really not good in c++ so i will need further help.

How to write addStudent function and removeStudent ? because that is problem for me i am not sure how to do this. your example was really helpful but i will be even more thankful if you can tell me how to write these functions also. Thank you very much once again
Topic archived. No new replies allowed.