Assigning values of class objects
<p>main</p>

<pre><code>#include &lt;stdio.h&gt;
#include "Student.h"
#include &lt;stdlib.h&gt;



void main()
{
Student* pStudents = new Student[0];
int arraySize = 0;

int input = 0;

while(input != 3)
{
    printf("Press 1 to add student, 2 to print and 3 to quit.\n");
    scanf_s("%d", &amp;input);
    switch(input)
    {
    case 1:
        pStudents[numOfStudents].AddStudent(pStudents, arraySize);
        arraySize++;
        numOfStudents++;
        break;
    case 2:
        break;
    case 3:
        break;
    default:
        printf("Invalid input\n");
        break;
    }
}
</code></pre>

<p>}</p>

<p>Student.h</p>

<pre><code>#pragma once
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

class Student
{
public:
    Student(void);
    ~Student(void);
     void AddStudent(Student* pStudent, int arraySize);
private:
    string name;
    int ID;
};
</code></pre>

<p>Student.cpp</p>

<pre><code>#include "Student.h"

Student::Student(void)
    : name("N/A")
    , ID(0)
{

}

Student::~Student(void)
{
}
void Student::AddStudent(Student* pStudent, int arraySize)
{
if(arraySize == 0)
{
    delete[] pStudent;
    pStudent = NULL;
    pStudent = new Student[1];

}
else
{
    Student* temp = new Student[(arraySize+1)];
    for(int i = 0; i &lt; arraySize; ++i)
    {
        temp[i] = pStudent[i];
    }
    delete[] pStudent;
    pStudent = temp;
}
printf("Enter name of student.\n");
cin &gt;&gt; name;
printf("Enter ID of student. \n");
cin &gt;&gt; ID;
}
</code></pre>

<p>Okay I've been trying to figure this out but I can't. I'm not sure what I'm doing wrong but I keep getting a write violation when I try to enter a name. I tried looking up the answer, some things I saw say try to use vectors, but I have not been taught how to use them yet.</p>

<p>Updated</p>

<p>main.cpp</p>

<pre><code>void main()
{
Student* pStudents = new Student[100];
Student studentGenerator;
int numOfStudents = 0;
string name;
int ID;


int input = 0;

while(input != 3)
{
    printf("Press 1 to add student, 2 to print and 3 to quit.\n");
    scanf_s("%d", &amp;input);
    switch(input)
    {
    case 1:
        printf("Enter name of student.\n");
        cin &gt;&gt; name;
        printf("Enter ID of student. \n");
        cin &gt;&gt; ID;
        studentGenerator = Student(name, ID);
        pStudents[numOfStudents] = studentGenerator;
        numOfStudents++;
        break;
    case 2:
        for(int i = 0; i &lt; numOfStudents; ++i)
        {
            studentGenerator.PrintStudents(pStudents[i]);
        }
        break;
    case 3:
        break;
    default:
        printf("Invalid input\n");
        break;
    }
}

}
</code></pre>

<p>student.cpp</p>

<pre><code>#include "Student.h"

Student::Student(void)
: name("N/A")
, ID(0)
{

}

Student::~Student(void)
{
}
Student::Student(string studentName, int studentID)
{   
name = studentName;
ID = studentID;
}
void Student::PrintStudents(Student student)
{
cout &lt;&lt; "Name: " &lt;&lt;  name &lt;&lt; endl;
cout &lt;&lt; "ID: " &lt;&lt; ID &lt;&lt; endl;
}
</code></pre>
