Download PROGRAMMING FUNDAMENTALS IN C++

Transcript
CHAPTER 1. STUDENT MANUAL
48
int* data; //pointer to the integer array
int size;
public:
IntArray(int* d, int s);
void showList();
void showFirst( );
};
// IntArray.cpp
IntArray::IntArray(int* d, int s)
{
data = d;
size = s;
}
void IntArray::showList()
{
cout"Entire list:" endl;
for(int x = 0; x< size; x++)
cout data[x]endl;
cout "" endl;
}
void IntArray::showFirst()
{
cout "First element is ";
cout data[0] endl;
}
a. Add to the class IntArray one more member function named ndMax which returns the largest element
in the array.
b. Write a main program that instantiates one array of integers and then displays the array, the rst
element and the largest element of the array.
1.4.10 LAB SESSION 9: OBJECT MANIPULATION
1.4.10.1 1. OBJECTIVE
The objectives of Lab session 9 are (1) to learn to write parameterized constructor, constructor with default
arguments and (2) to practice destructors.
1.4.10.2 2. EXPERIMENT
2.1) Run the following program in a C++ environment.
class Int{
private:
int idata;
public:
Int(){
idata=0;
cout"default constructor is called"endl;
}
Int(int d=9){
idata=d;
cout"constructor with argument is called"endl;
}