Sprout 2021/04/17
缺點:凌亂、不好整理
明明講的都是學生,能不能有一種資料型別叫做「學生」
Recall: 陣列A可以放 30 個整數
➜ int A[30]
student zhong[30]
struct student{
char name[30];
float score[3];
int speak;
bool pass;
};
#include <iostream>
#include <cstring>
using namespace std;
struct student{
char name[30];
float score[3];
int speak;
bool pass;
};
int main() {
student freshman;
strcpy(freshman.name, "John");
freshman.score[0] = 72.3;
freshman.score[1] = 85.0;
freshman.score[2] = 90.5;
freshman.speak = 5;
freshman.pass = true;
}
#include <iostream>
#include <cstring>
using namespace std;
struct student{
char name[30];
float score[3];
int speak;
bool pass;
};
int main() {
student zhong[30];
strcpy(zhong[0].name, "John");
zhong[0].score[0] = 72.3;
zhong[0].score[1] = 85.0;
zhong[0].score[2] = 90.5;
zhong[0].speak = 5;
zhong[0].pass = true;
}
#include <iostream>
#include <cstring>
using namespace std;
struct book{
char title[30];
double score;
int page;
};
int main() {
book my_book;
strcpy(my_book.title, "Harry Potter");
my_book.score = 4.5;
my_book.page = 350;
cout << my_book.title << ":\n";
cout << "score = " << my_book.score << "\n";
cout << "page = " << my_book.page << "\n";
}
struct book{
char title[30];
double score;
int page;
};
struct shelve{
int id;
int size;
book books[100];
};
// 印出書架上s的第一本書的書名
// cout << s.books[0].title;