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;
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;
}
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).
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
struct Student
{
string name;
unsignedchar 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.
unsignedint fees;
};
Then you could write a class to store the 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