Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- using namespace std;
- class Jumper {
- private:
- char name[50];
- int jersey;
- double trial[3];
- public:
- Jumper() {}
- Jumper(char* name, int jersey, double trial[]) {
- strcpy(this -> name, name);
- this -> jersey = jersey;
- for (int i=0; i<3; i++) {
- (this -> trial)[i] = trial[i];
- }
- }
- double total() {
- return trial[0] + trial[1] + trial[2];
- }
- void info() {
- cout << "jersey: " << jersey << " name: " << name << " length: " << total();
- }
- };
- int main()
- {
- srand (time(NULL));
- Jumper jumpers[10];
- for (int i=0; i<10; i++) {
- char* name;
- cin >> name;
- int rndJersey = rand() % 99 + 1;
- int trial1 = rand() % (250 - 200 + 1) + 200;
- int trial2 = rand() % (250 - 200 + 1) + 200;
- int trial3 = rand() % (250 - 200 + 1) + 200;
- double trial[] = {trial1, trial2, trial3};
- Jumper* j = new Jumper(name, rndJersey, trial);
- jumpers[i] = *j;
- delete j;
- }
- for (int i=0; i<10; i++) {
- jumpers[i].info();
- }
- double max = -99999;
- int index = -1;
- for (int i=0; i<10; i++) {
- max = max < jumpers[i].total() ? jumpers[i].total() : max;
- index = i;
- }
- cout << endl;
- cout << "Winner jumper with length: " << max << " info: ";
- jumpers[index].info();
- cout << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment