cplusplus-training/Teil_1/5. Felder/Uebung 1 - Bauernhof.cpp

24 lines
580 B
C++

#include <iostream>
#include <string>
using namespace std;
struct Tier{
uint8_t id;
string name;
bool operator == (const Tier& cmp) const {return id==cmp.id;}
bool operator < (const Tier& cmp) const {return id-cmp.id;}
string to_string(){return "ID: "+id+(name.length()>0?("Name: "+name):"")+"\n";}
};
int main(){
Tier tiere[50];
cout<<"Erstelle Liste\n";
for(int i = 0;i<50;i++){
cout<<"Erstelle index "<<i<<endl;
tiere[i].id=i+1;
}
for(Tier tier:tiere){
cout<<tier.to_string()<<endl;
}
system("pause");
}