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

C++ Questions You are given a vector of class objects named vec. Objects of the

ID: 3860728 • Letter: C

Question

C++ Questions

You are given a vector of class objects named vec. Objects of the class which is vec's base type contain a public vector member named stuey which is of base type Point. Also, Point class objects have an accessor get_x(). Show the declaration of vec as well as [just enough of] each class' definition to help someone unfamiliar with object-oriented programming visualize this situation. Show the one line needed to access the x value of the 3^rd point of the 16^th object in the original vector.

Explanation / Answer

#include<iostream>

#include<vector>

using namespace std;

class Point

{

int x = 1;

public:

Point()

{

x = 0;

}

int get_x()

{

return x;

}

};

class vec

{

public:

vector<Point> stuey;

vec()

{

}

};

int main()

{

//declare vector of object type vec

vector<vec> obj;

//to access x value of 3rd point of 16th object in original vector as array index start from 0 , 3rd point accessed //using index 2 and 16th object of vector with index 15...

obj[15].stuey[2].get_x();

}

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