Commit ddd12934 authored by Felix Huther's avatar Felix Huther
Browse files

Merge branch 'master' into 'main'

const correctness and passing by reference to save storage

See merge request !3
parents 773c94b5 48e56c9f
#include "athlete.h"
Athlete::Athlete(FullName fullName)
Athlete::Athlete(FullName& fullName)
:fullName(fullName)
{
}
void Athlete::printName()
void Athlete::printName() const
{
std::cout << fullName;
......
......@@ -6,8 +6,8 @@
class Athlete
{
public:
explicit Athlete(FullName fullName);
virtual void printName();
explicit Athlete(FullName& fullName);
virtual void printName() const;
protected:
FullName fullName;
......
#include "athletecollection.h"
#include <string>
AthleteCollection::AthleteCollection()
{
......@@ -6,25 +7,37 @@ AthleteCollection::AthleteCollection()
void AthleteCollection::addTestData()
{
//TEST DATA FOOTBALLPLAYER
for(int i = 0 ; i < 5 ; i++){
std::string firstName ="FbpFn";
std::string lastName ="FbpLn";
std::string position ="FbpP";
Athlete* footballPlayer = new FootballPlayer(FullName(firstName.append(std::to_string(i)),lastName.append(std::to_string(i))),position.append(std::to_string(i)));
vecAthletes.push_back(footballPlayer);
}
std::string firstName ="Philipp";
std::string lastName ="Lahm";
Athlete* footballPlayer1 = new FootballPlayer(FullName(firstName,lastName),"Vorne Links");
//TEST DATA SWIMMER
for(int i = 0 ; i < 5 ; i++){
std::string firstName ="SwimFn";
std::string lastName ="SwimLn";
std::string style ="SwimStyle";
Athlete* footballPlayer2 = new FootballPlayer(FullName("Oliver","Kahn"),"Torwart");
Athlete* footballPlayer3 = new FootballPlayer(FullName("Sebastian","Schweinsteiger"),"Vorne Rechts");
Athlete* swimmer1 = new Swimmer(FullName("Evgeny","Rylov"),"chest");
Athlete* swimmer2 = new Swimmer(FullName("Kliment", "KOLESNIKOV"),"back");
Athlete* swimmer3 = new Swimmer(FullName("Ryan", "MURPHY"),"chest");
Athlete* Swimmer = new FootballPlayer(FullName(firstName.append(std::to_string(i)),lastName.append(std::to_string(i))),style.append(std::to_string(i)));
vecAthletes.push_back(Swimmer);
}
addFootballballPlayer(footballPlayer1);
addFootballballPlayer(footballPlayer2);
addFootballballPlayer(footballPlayer3);
addSwimmer(swimmer1);
addSwimmer(swimmer2);
addSwimmer(swimmer3);
// Athlete* footballPlayer2 = new FootballPlayer(FullName("Oliver","Kahn"),"Torwart");
// Athlete* footballPlayer3 = new FootballPlayer(FullName("Sebastian","Schweinsteiger"),"Vorne Rechts");
// Athlete* swimmer1 = new Swimmer(FullName("Evgeny","Rylov"),"chest");
// Athlete* swimmer2 = new Swimmer(FullName("Kliment", "KOLESNIKOV"),"back");
// Athlete* swimmer3 = new Swimmer(FullName("Ryan", "MURPHY"),"chest");
// addFootballballPlayer(footballPlayer2);
// addFootballballPlayer(footballPlayer3);
// addSwimmer(swimmer1);
// addSwimmer(swimmer2);
// addSwimmer(swimmer3);
}
void AthleteCollection::addSwimmer(Athlete *athlete)
......
#include "footballplayer.h"
FootballPlayer::FootballPlayer(FullName fullName, std::string position)
FootballPlayer::FootballPlayer(FullName fullName, std::string& position)
: Athlete(fullName),position(position)
{
}
void FootballPlayer::printName()
void FootballPlayer::printName() const
{
Athlete::printName();
std::cout << " Position: " << position;
......
......@@ -5,8 +5,8 @@
class FootballPlayer : public Athlete
{
public:
FootballPlayer(FullName fullName, std::string position);
void printName() override;
FootballPlayer(FullName fullName, std::string& position);
void printName() const;
private:
std::string position;
......
#include "fullname.h"
FullName::FullName(std::string firstName, std::string lastName)
FullName::FullName(std::string& firstName, std::string& lastName)
:firstName(firstName),lastName(lastName)
{
......
......@@ -5,7 +5,7 @@
class FullName
{
public:
FullName(std::string firstName,std::string lastName);
FullName(std::string& firstName,std::string& lastName);
const std::string &getFirstName() const;
......
#include "swimmer.h"
Swimmer::Swimmer(FullName fullName, std::string stil)
Swimmer::Swimmer(FullName fullName, std::string& stil)
: Athlete(fullName),stil(stil)
{
}
void Swimmer::printName()
void Swimmer::printName() const
{
Athlete::printName();
std::cout <<" Stil: " << stil;
......
......@@ -5,8 +5,8 @@
class Swimmer : public Athlete
{
public:
Swimmer(FullName fullName, std::string style);
void printName() override;
Swimmer(FullName fullName, std::string& style);
void printName() const;
private:
std::string stil;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment