구조체
struct
실습 예제
ch04ex4_book.cpp
#include <iostream>
#include <string>
using namespace std;
struct book {
string title;
string author;
int pages;
int price;
};
void display(book& t);
int main()
{
book b[3] = {
{"컴활1급 실기", "영진", 700, 40000},
{"CPP", "PITCA", 300, 35000},
{"Python", "org", 150, 27000}
};
for (int i = 0; i < 3; i++)
{
display(b[i]);
cout << "----------------------" << endl;
}
return 0;
}
void display(book& t)
{
cout << "제목: " << t.title << endl;
cout << "저자: " << t.author << endl;
cout << "페이지: " << t.pages << endl;
cout << "가격: " << t.price << endl;
}실습 문제
ch04lab4_person.cpp
인물 구조체(Person)의 내용을 출력하는 display_person()함수를 구현하는 코드를 작성하시오. 인물 구조체는 이름(name, 100자), 성별(gender, 10자), 나이(age, 정수) 등의 변수로 구성된다.
Last updated