<< Chapter < Page | Chapter >> Page > |
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();
}
b. Reorganize the program into an interface file and an implementation file and then run the program.
2.2) Given the class student as defined in 2.1.a. Write a complete C++ program in which the main() function creates an array of size 10 to store student objects and prompts the user to enter the data for the student objects in the array and then displays the objects in the array.
2.3) Given the class student as defined in 2.1.a. Write a complete C++ program in which the main() function performs the following tasks:
2.4) Test the following program:
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;
}
What are the outputs of the program? Explain the results.
What is the purpose of the statement delete ptrInt; in the program?
2.5) Define a class named Rectangle which contains two single-precision floating point data members: length and width. The class has some member functions:
Include the class Rectangle in a complete C++ program. The main() function of this program creates two Rectangle objects using the two constructors respectively and displays the data of the two objects to check the working of all the member functions.
Then modify the program by replacing the two above constructor functions by a constructor with default arguments.
2.6) Define a class named CStudent which consists of the following data members:
The class also has the following member functions:
Notification Switch
Would you like to follow the 'Programming fundamentals in c++' conversation and receive update notifications?