Could someone help me with this? I\'m really busy and I just need to fill in the
ID: 645540 • Letter: C
Question
Could someone help me with this? I'm really busy and I just need to fill in the "insert" part which shouldn't be that difficult.
You have been given a Student class. A user will insert multiple names followed by the word "STOP" With each name,create a Student pointer and insert it into the "students" vector. You must print all the names in the vector in reverse order. Example: Input: Iris Kevin STOP Output: Kevin Iris
#pragma once
#include
#include
#include
using namespace std;
class Student
{
private:
string name;
public:
Student(string name);
string getName();
void setName(string newName);
~Student();
};
Student::Student(string studentName)
{
name = studentName;
}
string Student::getName()
{
return name;
}
void Student::setName(string newName)
{
name = newName;
}
Student::~Student()
{
}
//
// You may insert a function here
int main()
{
vector students;
return 0;
}
Explanation / Answer
#include
#include
#include
#include "Student.h"
using namespace std;
void fillVector(vector&);
void printVector(const vector&);
int main()
{
vector myClass;
fillVector(myClass);
printVector(myClass);
return 0;
}
void fillVector(vector& newMyClass)
{
string name;
cout << "How many you students are in your class? ";
int classSize;
cin >> classSize;
for (int i=0; i {
cout<<"Enter student name: ";
cin>>name;
// method to reverse.then follow steps bellow.
Student newStudent(name);
newMyClass.push_back(newStudent);
cout< }
cout< }
void printVector(const vector& newMyClass)
{
int size = newMyClass.size();
for ( int i=0; i {
cout<<"Student name: "< cout<<"Student grade: "< cout< }
}
// Student.h
#ifndef STUDENT_H_INCLUDED
#define STUDENT_H_INCLUDED
class Student
{
private:
string name;
public:
Student(string name);
string getName();
void setName(string newName);
~Student();
};
#include
#include
using namespace std;
#include "Student.h"
Student::Student(string studentName)
{
name = studentName;
}
string Student::getName()
{
return name;
}
void Student::setName(string newName)
{
name = newName;
}
Student::~Student()
{
}
int main()
{
vector students;
return 0;
}