Skip to content

Instantly share code, notes, and snippets.

@jkotra
Last active April 2, 2019 05:12
Show Gist options
  • Save jkotra/870b5109daf62d7bda89e20d37a04765 to your computer and use it in GitHub Desktop.
Save jkotra/870b5109daf62d7bda89e20d37a04765 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <string>
#include <array>
using namespace std;
class Cycling{
private:
float place_finished;
float timing;
float distace_travelled;
public:
//constructor
Cycling(float place_finished,float timing,float distace_travelled){
this->place_finished = place_finished;
this->distace_travelled = distace_travelled;
this->timing = timing;
}
array<float ,3> get_stat(){
array x = {place_finished,distace_travelled,timing};
return x;
}
Cycling operator+ (Cycling obj1){
Cycling x(0,0,0);
x.timing = this->timing + obj1.timing;
x.distace_travelled = this->distace_travelled + obj1.distace_travelled;
return x;
}
};
int main() {
Cycling neil(1,35,50);
Cycling bob(2,50,20);
array nstat = neil.get_stat();
cout << "neil stats:\n";
for (int i = 0; i < 3; ++i) {
cout << nstat[i] << endl;
}
array bstat = bob.get_stat();
cout << "bob stats:\n";
for (int i = 0; i < 3; ++i) {
cout << bstat[i] << endl;
}
Cycling total = neil+bob;
array totalstats = total.get_stat();
cout << "combined stats:\n";
for (int i = 0; i < 3; ++i) {
cout << totalstats[i] << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment