I have been working on this program i am stuck on and need somw help
i am placing the entry into from the main into a pointer array in the Stock class and then assigning the values to the Vehicle class. the thing i am having problems with is accessing the the values later for display.i dont quite understand how i would access them to display them back to the user from the pointer.

#include "Vehicle.h"
#include "Stock.h"

int main()
{
    cout << "Enter a new vehicle:"<<endl;
    Stock stock;
    stock.createTruck();

    system("pause");
    return 0;
}
//-------------------------------------------
#include "Vehicle.h"
#ifndef STOCK_H
#define STOCK_H
class Stock
{
private:
    Vehicle* itemPtr[500];
    int counter;
public:
    Stock()
    {
        counter=0;
    }
    ~Stock()
    {
        for(int i = 0;i < counter; i++)
        {
            delete itemPtr[i];
        }
    }
     void createTruck()
    {
        string maker="";
        double cost=0;
        int onHand=0;

        cout << "Enter maker:";
        cin>>maker;
        cout << "Enter Cost:";
        cin >> cost;
        itemPtr[counter++] = new Vehicle(maker,cost);
    }
    void displayTruck()
    {

    }
};
#endif
//-------------------------------------------
#include <iostream>
#include <string>
using namespace std;
#ifndef VEHICLE_H
#define VEHICLE_H
class Vehicle
{
private:
    string maker;
    double price;
    double cost;
public:
    //constructors
    Vehicle()
    {
        maker = "";
        price = 0.0;
        cost = 0.0;
    }
    Vehicle(string vehicleMaker,double vehicleCost)
        {
            maker=vehicleMaker;
            cost=vehicleCost;
        }
    string getMaker() const 
    {
        return maker;
    }
    virtual double getCost() const 
    {
        return cost;
    }
    void setMaker(string vehicleMaker)
    {
        maker=vehicleMaker;
    }
    void setCost(double vehicleCost)
    {
        cost=vehicleCost;
        const double percentage=.25;
        price=cost + cost*percentage;
    }
};
#endif

Try something like this.

void displayTruck()
{
    for (size_t i = 0; i < counter; ++i)
        std::cout << itemPtr[i]->getMaker() << itemPtr[i]->getCost() << std::endl;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.