Module 4 Objects classes and methods Activity 4.1 1. Taking the in-class example of the car, continue coding this example but include one or more additional variables for the speed of the car. Include...

1 answer below »
Module 4activities 4.1 and 4.2


Module 4 Objects classes and methods Activity 4.1 1. Taking the in-class example of the car, continue coding this example but include one or more additional variables for the speed of the car. Include mutator and accessor methods for the car’s speed and use them in the start(), accelerate(), brake() and stop() methods to extend their functionality. When the car starts, initialise its speed to 0. Allow the accelerator method to increase the speed by a given increment and the brake method to decrease by a given decrement. Print the current speed to the screen. 2. Race time: take the same example and separate the class into a header file. Write another program that instantiates two car objects, one small and the other large (if you don’t know cars, look up examples for brands of cars and their fuel tank capacities). In your code, start each car and then accelerate each car at different rates. Do this in a loop three times for each car and then reverse the rates for braking. Print the name of the car that comes to a complete stop first and declare the other car the winner. Constructors and inheritance Activity 4.2 1. Taking your work from the first half of the module, create constructor and destructor methods for the ‘Car’ class. 2. Write a program using the object-oriented paradigm that keeps track of bank accounts. Each class should have constructor and destructor methods but the choice of members will be up to you. Start with a class for ‘account’ and then allow for different types of derived classes, such as ‘savings account’ and ‘credit card account.’ A bank account should allow funds to be added to it as well as withdrawn but not to be overdrawn. A credit card account should allow funds to be charged to it but not more than its limit. In the main() function, open a savings account with $10,000 and then make three withdrawals of $4,000, if there are enough funds. Open a credit card account, with a limit of $3000 and make two charges of $2000 if there are enough funds. If you breach the conditions for each, display an appropriate error message.
Answered Same DayAug 01, 2021Torrens University Australia

Answer To: Module 4 Objects classes and methods Activity 4.1 1. Taking the in-class example of the car,...

Robert answered on Aug 02 2021
164 Votes
Assessment 2c - Submission/4.1.1 Car.cpp
#include
#include
using namespace std;
class Car {
private:
string strColour;
string strBrand;
float fltFuelTankCapacity;
int intOdometerReading;
int speed;
public:
void start(int);
void accelerate(int);
void brake(int);
void st
op();
void setColour(string);
void setBrand (string);
void setFuelTankCapacity(float);
void setOdometerReading(int);
string getColour();
string getBrand();
float getFuelTankCapacity();
int getOdometerReading();
int getspeed();
};
void Car::start(int tmpspeed) {
speed = tmpspeed;
return;
}
void Car::accelerate(int tmpspeed) {
speed = speed+tmpspeed;
return;
}
void Car::brake(int tmpspeed) {
speed = speed-tmpspeed;
return;
}
void Car::stop() {
return;
}
void Car::setColour(string strTempColour) {
strColour = strTempColour;
return;
}
void Car::setBrand(string strTempBrand) {
strBrand = strTempBrand;
return;
}
void Car::setFuelTankCapacity(float fltTempCapacity) {
fltFuelTankCapacity = fltTempCapacity;
return;
}
void Car::setOdometerReading(int intTempOdometerReading) {
intOdometerReading = intTempOdometerReading;
return;
}
string Car::getColour() {
return strColour;
}
string Car::getBrand() {
return strBrand;
}
float Car::getFuelTankCapacity() {
return fltFuelTankCapacity;
}
int Car::getOdometerReading() {
return intOdometerReading;
}
int Car :: getspeed(){
return speed;
}
int main() {
Car myCar;
int accelerate , brake;
myCar.setColour("Red");
myCar.setBrand("Ferrari");
myCar.setFuelTankCapacity(70.0);
myCar.setOdometerReading(47876);
myCar.start(0);
cout<<"Enter the speed to accelerate the car:";
cin>>accelerate;
myCar.accelerate(accelerate);
cout<<"Please apply the brake:";
cin>>brake;
myCar.brake(brake);
myCar.stop();
cout <<"Color: " << myCar.getColour() << endl;
cout << "Brand: " << myCar.getBrand() << endl;
cout << "Tank: " << myCar.getFuelTankCapacity() << endl;
cout << "Odometer: " << myCar.getOdometerReading() << endl;
cout<<"Current speed:"<return 0;
}
Assessment 2c - Submission/4.1.2Car.h
#ifndef CAR_H_INCLUDED
#define CAR_H_INCLUDED
#include
#include
using namespace std;
class Car {
private:
string strColour;
string strBrand;
float fltFuelTankCapacity;
int intOdometerReading;
int speed;
public:
void start(int);
void accelerate(int);
void brake(int);
void stop();
void setColour(string);
void setBrand (string);
void setFuelTankCapacity(float);
void setOdometerReading(int);
string getColour();
string getBrand();
float getFuelTankCapacity();
int getOdometerReading();
int getspeed();
Car()
{
cout<<"Constructor Invoked"< }
~Car()
{
cout<<"Destructor Invoked"< }
};
void Car::start(int tmpspeed) {
speed = tmpspeed;
return;
}
void Car::accelerate(int tmpspeed) {
speed = speed+tmpspeed;
return;
}
void...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here