#include
using namespace std;
class Train
{
public:
float getMaxSpeed();
void setMaxSpeed(float);
Train(); //default constructor
Train(float); //overloaded constructor
private:
float maxSpeed;
};
Train::Train()
{
maxSpeed = 250;
cout<<"\nDefault Constructor : Maximum Speed = \t\t" <
Train::Train(float maximumSpeed)
{
maxSpeed = maximumSpeed;
cout<<"\nOverloaded Constructor : Maximum Speed = \t\t" <
float Train::getMaxSpeed()
{
return maxSpeed;
}
void Train::setMaxSpeed(float ms)
{
maxSpeed = ms;
}
int main()
{
// displaying value through overloaded constructor
Train train1(100);
Train *train2 = new Train(); //dynamically allocating memory to train2
float maximumSpeed;
cout<<"\n\nEnter the maximum speed of Train: \t\t";
cin>>maximumSpeed;
train2->setMaxSpeed(maximumSpeed);
cout<<"Updated Speed : \t\t"<
delete train2; //releasing the memory allocated to train2
system("pause");
return 0;
}
......Indian Songs.......
Wednesday, January 27, 2010
CS 201 ass # 5
Posted by Alisha Naaz at 8:49 AM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment