[C++] 구조체를 써서 축구팀을 만들어 보자

2022. 5. 31. 17:19코딩 1막 <C++개념편>/코딩 1막 <C++응용편>

728x90

#include <iostream>
#include <string>

using namespace std;

struct SoccerPlayer	
{
	string name;
	int age;
	string position;
	string club;
};

void main()
{
	
	SoccerPlayer soccerPlayerA;			
	soccerPlayerA.name = "오사쯔";
	soccerPlayerA.age = 28;
	soccerPlayerA.position = "미드필더" ;
	soccerPlayerA.club = "경일마드리드";

	SoccerPlayer soccerPlayerB;
	soccerPlayerB.name = "손흥민";
	soccerPlayerB.age = 30;
	soccerPlayerB.position = "윙어";
	soccerPlayerB.club = "토트넘 핫스퍼";

	SoccerPlayer soccerPlayerC;
	soccerPlayerC.name = "Zidane";
	soccerPlayerC.age = 34;
	soccerPlayerC.position = "중앙미드필더";
	soccerPlayerC.club = "레알마드리드";

	SoccerPlayer soccerPlayerD;
	soccerPlayerD.name = "조현우";
	soccerPlayerD.age = 32;
	soccerPlayerD.position = "골키퍼";
	soccerPlayerD.club = "대구FC";

	SoccerPlayer soccerPlayerE;
	soccerPlayerE.name = "김민재";
	soccerPlayerE.age = 25;
	soccerPlayerE.position = "센터백";
	soccerPlayerE.club = "토트넘 핫스퍼";

	SoccerPlayer soccerPlayers[] = { soccerPlayerA , soccerPlayerB, soccerPlayerC, soccerPlayerD, soccerPlayerE };

	for (int i = 0; i < 5; i++)
	{
		cout << i + 1 << "번째 선수" << endl;
		cout << "선수명 : " << soccerPlayers[i].name << endl;
		cout << "선수나이 : " << soccerPlayers[i].age << endl;
		cout << "선수포지션 : " << soccerPlayers[i].position << endl;
		cout << "선수가 속한 클럽 : " << soccerPlayerD.club << endl;
		cout << endl;
	}
}

출력 결과

 

728x90