Assignment Problem Statement: Suppose we have a class named as Train it has two
ID: 3616215 • Letter: A
Question
Assignment
Problem Statement:
Suppose we have a class named as Train it has two constructors,two methods, and a single attribute each of which described asfollows:
maxSpeed – an int value representing themaximum speed of the Train object.
Note: Train speed of modern Trains may be something like 250 kmper hour, so a value you could use for testing purposes is 250.
A default constructor:
A constructor that initializes theattribute ms where ms is the maxSpeed.
An overloaded constructor:
A constructor that takes ms as anargument, where ms is the maxSpeed.
getMaxSpeed() – return the maxSpeed valueassociated withthe Train object.
setMaxSpeed(ms) – change the maxSpeedvalue associated with the Train object, where ms is the newvalue.
Assignment
Problem Statement:
Suppose we have a class named as Train it has two constructors,two methods, and a single attribute each of which described asfollows:
- One attribute:
maxSpeed – an int value representing themaximum speed of the Train object.
Note: Train speed of modern Trains may be something like 250 kmper hour, so a value you could use for testing purposes is 250.
- Two constructors:
A default constructor:
A constructor that initializes theattribute ms where ms is the maxSpeed.
An overloaded constructor:
A constructor that takes ms as anargument, where ms is the maxSpeed.
- Two methods:
getMaxSpeed() – return the maxSpeed valueassociated withthe Train object.
setMaxSpeed(ms) – change the maxSpeedvalue associated with the Train object, where ms is the newvalue.
- Display the value through default constructor and overloadedconstructor.
- Display setter value through main function.
Explanation / Answer
Any problem then just send Private Message to me.#include<iostrea.h> #include<conio.h>
class Train { private int MaxSpeed;
public Train() { MaxSpeed=300; }
public Train(int sp) { MaxSpeed=sp; }
public int getMaxSpeed() { return MaxSpeed; }
public void setMaxSpeed(int sms) { MaxSpeed=sms; }
public void display() { cout<<" Maximum Speed="<<getMaxSpeed()<<"KMs per Hour:; };
int main() { Train mt; mt.display();
mt.setMaxSpeed(400); mt.display();
getch(); return 0; }
#include<iostrea.h> #include<conio.h>
class Train { private int MaxSpeed;
public Train() { MaxSpeed=300; }
public Train(int sp) { MaxSpeed=sp; }
public int getMaxSpeed() { return MaxSpeed; }
public void setMaxSpeed(int sms) { MaxSpeed=sms; }
public void display() { cout<<" Maximum Speed="<<getMaxSpeed()<<"KMs per Hour:; };
int main() { Train mt; mt.display();
mt.setMaxSpeed(400); mt.display();
getch(); return 0; }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.