Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose we have a C++ class called student. There are many ways one can create a

ID: 3821550 • Letter: S

Question

Suppose we have a C++ class called student. There are many ways one can create a collection student objects. Among these: one can use a normal C++ array or an STL vector, and one could create a collection of objects, or of pointers to objects (presumably allocated on the heap.) a. Write a line of C++ code that declares an array a that can hold 10 objects of type student b. Write a line of C++ code that declares an array b that can hold 10 pointers to objects of type student. c. Write a line of C++ code that declares an STL vector c that can hold 10 objects of type student d. Write a line of C++ code that declares an STL vector d that can hold 10 pointers to objects of type student In the previous problem, you were asked to write four different declarations, (a), (b), (c) and (d). Each of these has "pros" and "cons". There are also differences among them that we might describe as "neutral", for whether they are a pro/con depends on the context. For the "pros" and "cons" below, please indicate which of the letters above (a, b, c, d) the statement applies to. Note that in some cases, you may have to indicate more than one letter. Circle the letters to which the statement applies. If you mess up, cross out all the letters and list the letters in the space to the right.

Explanation / Answer

2.

a. Student a[10]; // Array of 10 object
b. Student *b[10]; // an array of 10 pointers to "Student" objects
c. vector<Student> c; // Vector of student objects
d. vector<Student*> d; // Vector of pointers to student objects

3.

#1: Choices: c and d (You need to add vector header file)

#2: b,c and d (b is an array of pointers, c and d are vectors, their capacity is dynamic)

#3: a, b, c and d

#4: none

Below code is compiling and executing successfully.

#include <iostream>
#include <vector>
using namespace std;

class Student{
string name;
};

int main()
{
Student a[10]; // Array of 10 object
Student *b[10]; // an array of 10 pointers to "Student" objects
vector<Student> c; // Vector of student objects
vector<Student*> d; // Vector of pointers to student objects
return 0;
}

#5: a and b (Memory of an array is initialized at time of declaration)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote