사용자:하늘/문화/지명: 두 판 사이의 차이

(새 문서: 시리즈:초급 프로그래밍 c++ c++ 초반 <syntaxhighlight lang="c++"> #include <iostream> using namespace std; class Cube { public: int x, y, z; int Volume, Area;...)
 
잔글 (하늘님이 사용자:하늘/지명 문서를 넘겨주기를 만들지 않고 사용자:하늘/문화/지명 문서로 이동했습니다)
 
(사용자 2명의 중간 판 18개는 보이지 않습니다)
1번째 줄: 1번째 줄:
시리즈:초급 프로그래밍 c++


c++ 초반
<syntaxhighlight lang="c++">
#include <iostream>
using namespace std;
class Cube
{
public:
    int x, y, z;
    int Volume, Area;
    Cube();
    Cube( int x, int y, int z );
};
Cube::Cube( int x, int y, int z) {
    this->x = x, this->y = y, this->z = z;
    Volume =  x * y * z;
    Area = x * y * 2 + y * z * 2 + z * x * 2;
}
Cube::Cube() :Cube ( 1, 1, 1) {}
int main(void)
{
    Cube *boxes = new Cube[3];
    boxes[0] =  Cube();
    boxes[1] =  Cube( 3, 3, 3 );
    boxes[2] =  Cube( 4, 4, 4 );
    cout  << "부피" << boxes->Volume << endl;
    cout << "겉면적" << boxes->Area  << endl;
    boxes++;
    cout  << "부피" << boxes->Volume << endl;
    cout << "겉면적" << boxes->Area  << endl;
    boxes++;
    cout  << "부피" << boxes->Volume << endl;
    cout << "겉면적" << boxes->Area  << endl;
}
</syntaxhighlight>

2024년 4월 16일 (화) 16:48 기준 최신판