#include<iostream.h>
class student{
private:
long int rollno;
int age;
char sex;
float height;
float weight;
public:
void getinfo();
void disinfo();
};
void student::getinfo()
{
cout << " Roll no :";
cin >> rollno;
cout << " Age :";
cin >> age;
cout << " Sex:";
cin >> sex;
cout << " Height :";
cin >> height;
cout << " Weight :";
cin >> weight;
}
void student::disinfo()
{
cout<<endl;
cout<< " Roll no = "<< rollno << endl;
cout<< " Age =" << age << endl;
cout<< " Sex =" << sex << endl;
cout<< " Height =" << height << endl;
cout<< " Weight =" << weight << endl;
}
void main()
{
student a;
cout << " Enter the following information " << endl;
a.getinfo();
cout << " \n Contents of class "<< endl;
a.disinfo();
}
class Int{
private:
int idata;
public:
Int(){
idata=0;
cout<<"default constructor is called"<<endl;
}
Int(int d){
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;
Int *ptrInt = new Int();
ptrInt->showData();
delete ptrInt;
}
#include <iostream.h>
void main()
{
int num;
cout<< “Please enter the numbers of input: ”
cin>>num;
int a = new int [num];
int total = 0; // Holds total of user’s eight numbers.
int ctr;
for (ctr=0; ctr<num; ctr++)
{
cout << “Please enter the next number...”;
cin >> a[ctr];
total += a[ctr];
}
cout << “The total of the numbers is “ << total << “\n”;
return;
delete [] a;
}
// IntArray.h
class IntArray
{
private:
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;
}
Comments, questions, feedback, criticisms?