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;
}
void showData(){
cout<<"value of idata: "<<idata<<endl;
}
};
void main()
{
Int i;
Int j(8);
Int k=10;
}
class Vector{
private:
int *value;
int dimension;
public:
Vector(int d=0){
dimension=d;
if (dimension==0)
value=NULL;
else{
value=new int[dimension];
for (int i=0; i<dimension; i++)
value[i]=0;
}
}
void showdata(){
for (int i=0; i<dimension; i++)
cout<<value[i];
cout<<endl;
}
~Vector(){
if (value!=NULL)
delete value;
}
};
void main()
{
Vector v(5);
v.showdata();
Vector v2(v);
v2.showdata();
}
Vector(const Vector& v){
dimension = v.dimension;
value=new int[dimension];
for (int i=0; i<dimension; i++)
value[i]=v.value[i];
}
class some{ // code segment a
public:
~some() {
cout<<"some's destructor"<<endl;
}
};
void main() {
some s;
s.~some();
}
class some{ // code segment b
int *ptr;
public:
some(){
ptr= new int;
}
~some(){
cout<<"some's destructor"<<endl;
if (ptr!=NULL){
cout<<"delete heap memory"<<endl;
delete ptr;
}
}
};
void main()
{
some s;
// s.~some();
}
class Auto {
public:
Auto(char*, double);
displayAuto(char*, double);
private:
char* szCarMake;
double dCarEngine;
};
Auto::Auto(char* szMake, double dEngine){
szCarMake = new char[25];
strcpy(szCarMake, szMake);
dCarEngineSize = dCarEngine;
}
Auto::displayAuto(){
cout<< “The car make: “<< szCarMake<< endl;
cout<< “The car engine size: “<< dCarEngine<< endl;
}
void main(){
Auto oldCar(“Chevy”, 351);
Auto newCar(oldCar);
oldCar.displayAuto();
newCar.displayAuto();
}
Comments, questions, feedback, criticisms?