#include <iostream>
using namespace std;

class Book


		string title;

		double price;



		void setTitle(string s);

		void setPrice(double p);

		string getTitle() const
		{return title;}

		double getPrice() const
		{return price;}

		bool hasKeyword(string key);



void Book :: setTitle(string s)


void Book::setPrice(double p)


void Initalize(Book *book, int size)

	for(int i=0;i>size;i++)
		string t[size];
		double p[size];

		cout<<"Enter the title: ";
		cin>> t[i];

		cout<<"Enter the price: $";


const int SIZE=3;

int main()

	int number;	
	string key;
	Book book;

	cout<< "Enter the number of books: ";
	cin>> number;
	book[SIZE]=new [number];

I have no idea. How can I make dynamically create in the main function?


	cout<<"Enter the keyword: ";

	system ("pause");
	return 0;


I want to make like the picture in the attachment.

However, I don't know how to make it. I am so stuck in class lesson.

Please help me.

The new[] operator doesn't work like other operators. To use it, you must have a pointer that you are storing the return value to.

dataType *pDataType = 0;              //declare a NULL pointer to a dataType

pDataType = new dataType[arraySize];  //create an array on the heap, store it's address in the pointer

//work with the array

delete[] pDataType;                   //destroy the array
pDataType = 0;                        //eliminate the dangling pointer created by array destruction

check it size value before user enter if is equal the array index then +1 this way you can use array as dynamically

check it size value before user enter if is equal the array index then +1 this way you can use array as dynamically

Huh? I hope your not saying that a loop should run from 1 to SIZE. That is totally incorrect. C++ arrays ALWAYS start at 0; therefore, the loop should run from 0 to (SIZE-1).

Example, to input a user-selected number of elements into an integer array:

#include <iostream>

using namespace std;

int main() {
  //local declarations
  int numElements = 0;
  int *intArray = 0;

  //prompt the user for array size
  cout << "How many numbers would you like to enter: ";
  cin >> numElements;

  //create the array
  intArray = new int[numElements];

  //populate the array
  for (int i = 0; i < numElements; ++i) {
    cout << "Enter element " << i << ": ";       //prompt version 1
    //cout << "Enter element " << i+1 << ": ";   //prompt version 2
    cin >> intArray[i];

  //display the array
  cout << "Your array's contents:";
  for (int j = 0; j < numElements; ++j) {
    if (!(j % 10)) {
      cout << endl;
    cout << intArray[j] << " ";

  delete[] intArray;
  intArray = 0;
  return 0;