C++ How to create subclass in class with array
<p>C++ How to create subclass in class with array</p>

<p>Hi guys, i still learning C++ and face some issues here.</p>

<p>Basically i got a parent class</p>

<p>lets call this parent class as</p>

<pre><code>Vehicle
</code></pre>

<p>It got 2 sub class, lets assume they are </p>

<p><code>Car and Motorcycle</code></p>

<p>I will create a vehicle object assume vehicle size is 20</p>

<pre><code>Vehicle veh[20]
</code></pre>

<p>I will do the following</p>

<pre><code>string vType;

cout &lt;&lt; "Please enter your vehicle Type:";
cin &gt;&gt; vType;
</code></pre>

<p>so i do a comparision if (vType=="Car")</p>

<p>it will return 4 wheels from the sub class, but how do i declare its 4 wheels at Car and 2 wheels at Motorcycle , i know i need create 2 additional cpp file which is </p>

<pre><code>class Car : public Vehicle
{
private:
int noOfWheels;
public:
computePrice();
}
</code></pre>

<p>But how do i set noOfWheels specially to Car as 4 and Motorcycle as 2.</p>

<p>The next is the tricky part.. after knowing how many wheel it is</p>

<p>i will need store a array for each wheel</p>

<pre><code>string wheel[4];
</code></pre>

<p>since i know there 4 wheel in cars.</p>

<p>How do i prompt 4 type and store it in an array, and all of this in an object call Vehicle.</p>

<p>I can use a for loop and thats not the issue, the part i am stuck on is how do i create a string array and store the 4 prompt and then into this Vehicle[0]</p>

<pre><code>wheel 1:
wheel 2:
wheel 3:
wheel 4:
</code></pre>

<p>When user want to print data it will be</p>

<pre><code>Vehicle[0]
Type: Car
Wheel: 4
Wheel[0] = Fine condition
Wheel[1] = Need to check again
Wheel[2] = Fine condition
Wheel[3] = Might need get repair
</code></pre>

<p><strong>Thanks for all help.</strong></p>
