Code:
class List
{
public:
List(const int* arr, int sz);
//initializes list object by copying the data from the array arr (of size sz) into it
int HowMany(int val); //returns the number of times the value val appears in the list
void PrintSquares(); //prints squares of data elements in list, separated by commas
private:
int data[100]; //list of up to 100 numbers
int size; //number of values currently stored
};
This is my header file. The following code now is the definition file. I'm supposed to initialize the constructor with a constant int pointer and that is the part that is giving me the trouble. I'm not so sure if i defined my other functions correctly. But if anyone can give me a heads up on how to go about solving the constructor problem and analyzing if I did the other functions right, I would really appreciate it. Thank you.
Code:
#include <iostream>
#include "list2.h"
using namespace std;
List::List(const int* arr, int sz)
{
//initializes list object by copying the data from the
//array arr (of size sz) into it
arr[data];// this part trips me out, I also tried this
size=sz;
}
int List:: HowMany(int val) //returns the number of times the value
//val appears in the list
{
int v=0;
for(int i=0; i<size; i++)
if (data[i]==val)
v++;
return v;
}
void List:: PrintSquares() //prints squares of data elements in list,
//separated by commas
{
for(int i=0; i<size; i++)
{
cout<<data[i]*data[i];
for (int j=0;j<data[i];j++)
cout<<',';
cout<<endl;
}
}