I am C++ noob, forgive me if this a simple question, I have been trying to solve this problem since past couple of days.
There exists a class called student which stores names, age and marks of a student. Each student's profile (age, name and marks is stored in a class). There are n
students in a class hence , a vector<student*>
is created, which stores the pointers to all the students profile in a class.
I want to print the values stored in the `vector I would really appreciate any hints!
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;
class student{
private:
string name;
float marks;
int age;
public:
student(): name("Null"), marks(0),age(0){}
student(string n, float m,int a): name(n), marks(m),age(a){}
void set_name();
void set_marks();
void set_age();
void get_name();
void get_marks();
void get_age();
};
void student::set_name(){
cout<<"Enter the name: ";
cin >> name;
}
void student::set_age(){
cout << "Enter the age: ";
cin >> age;
}
void student::set_marks(){
cout<<"Enter the marks ";
cin>> marks;
}
void student::get_name(){
cout<<"Name: "<< name<<endl;
}
void student::get_age(){
cout<<"Age: "<< age<<endl;
}
void student::get_marks(){
cout<<"Marks: "<< marks<<endl;
}
int main() {
int n;
cout<<"Enter the number of students: ";
cin >> n;
vector <student*> library_stnd(n);
for(int i=0;i<n;i++){
student* temp = new student;
temp->set_name();
temp->set_age();
temp->set_marks();
library_stnd.push_back(temp);
}
for (auto ep: library_stnd){
ep->get_age();
}
return(0);
}