Text Practice Mode
Code-Text typing practice
created Yesterday, 17:06 by Fatma Sumbal
2
734 words
5 completed
0
Rating visible after 3 or more votes
saving score / loading statistics ...
00:00
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
class Vehicle // Base class
{
protected:
string vehcID, brand, model, type;
double rent, totalCost;
bool available;
public:
virtual void details(bool showAvailability) // To display details of the vehicle
{
cout << "\n\n-Vehicle ID: " << vehcID
<< "\nBrand: " << brand
<< "\nModel: " << model
<< "\nRent: " << rent <<" Rs per hour";
if(showAvailability) // Availability will not be shown while viewing rented vehicles
cout << "\nAvailable: " << isAvailable();
}
void setTotalCost(int hours)
{
totalCost = rent * hours; // Calculate cost based on hours rented
}
double getCost()
{
return totalCost;
}
string isAvailable() // Returns yes or no
{
return (available? "Yes": "No");
}
void setAvailablity(bool av)
{
available = av; // sets availablity to false when vehicle is rented
}
};
void loadVehicles(Car* cars[], Bike* bikes[])
{
ifstream read("Vehicles.txt");
string line;
bool isCar = true; // Start reading cars
int carIndex = 0, bikeIndex = 0;
while (getline(read, line))
{
if (line == "Cars")
{
isCar = true;
continue;
}
#include<fstream>
#include<vector>
using namespace std;
class Vehicle // Base class
{
protected:
string vehcID, brand, model, type;
double rent, totalCost;
bool available;
public:
virtual void details(bool showAvailability) // To display details of the vehicle
{
cout << "\n\n-Vehicle ID: " << vehcID
<< "\nBrand: " << brand
<< "\nModel: " << model
<< "\nRent: " << rent <<" Rs per hour";
if(showAvailability) // Availability will not be shown while viewing rented vehicles
cout << "\nAvailable: " << isAvailable();
}
void setTotalCost(int hours)
{
totalCost = rent * hours; // Calculate cost based on hours rented
}
double getCost()
{
return totalCost;
}
string isAvailable() // Returns yes or no
{
return (available? "Yes": "No");
}
void setAvailablity(bool av)
{
available = av; // sets availablity to false when vehicle is rented
}
};
void loadVehicles(Car* cars[], Bike* bikes[])
{
ifstream read("Vehicles.txt");
string line;
bool isCar = true; // Start reading cars
int carIndex = 0, bikeIndex = 0;
while (getline(read, line))
{
if (line == "Cars")
{
isCar = true;
continue;
}
saving score / loading statistics ...