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

C++ Helps Someheader.h: sample result shoudl be: 1A 1A 1B 1A 1B 1B Instructions

ID: 3820911 • Letter: C

Question

C++ Helps

Someheader.h:

sample result shoudl be:

1A
1A
1B
1A
1B
1B

Instructions In this exercise you will be working with typeid0. Download the file SomeHeader.h, which defines a class B that inherits from the base class A The initvec0 method creates a vector of type A* and pushes several objects into it. For this exercise, write a main O function that will do the following. Declare a vector of type Aik, and use the initVec (vector & myVec) to populate it. Now, iterate over all vector elements and print the name of each element, one item per line. Note that this output may look different, depending on your operating system and/or compiler Clarification Do not hard-code the name of the derived class. In the example it is B, but your code should not assume that. In your .cpp file, simply iterate over your vector and use typeid(...) name to print out the name of each element in the vector

Explanation / Answer

CODE:
Please include the below code in seperate file, say mainfile.cpp

#include <iostream>
#include <vector>
#include "Someheader.h"

using namespace std;

int main(){
vector<A*> myvec;

initVec(myvec);

for (vector<A*>::iterator it = myvec.begin() ; it != myvec.end(); ++it)
std::cout << ' ' << *it;
std::cout << ' ';

}

OUTPUT:

$ g++ mainfile.cpp
$ ./a.out
0x16aac20 0x16aac60 0x16aac40 0x16aac80 0x16aacd0 0x16aad40