ロベールのC++入門講座 その2

5章4節

Struct1.cppを今までの理解の確認をかねて、ポインタ渡しのコードにしてみる。


#include <iostream>
using namespace std;

const int MAX_NAME = 16;

struct Student {
char name[MAX_NAME + 1];
int scoreJapanese;
int scoreMath;
int scoreEnglish;
};

void Show(const Student* student) {
cout << "名前 : " << (*student).name << endl << "国語 : "
<< (*student).scoreJapanese << endl << "数学 :"
<< (*student).scoreMath << endl << "英語 ;"
<< (*student).scoreEnglish << endl;

}

int main() {
Student student[] = { { "赤井孝", 73, 98, 86 }, { "笠井大介", 64, 45, 40 }, {
"吉田叶", 76, 78, 69 }, };

int size = sizeof student / sizeof *student;

for (int i = 0; i < size; ++i) {
Show(&student[i]);
}
}


コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です