本周学习记录
1:学习到黑马程序第70课结构体,正在研究结构体案例1
#include<iostream>
using namespace std;//声明使用std空间里的所有标识符
#include<string>
#include<ctime>
struct student
{
//结构体
string sname;
int score;
};
struct teacher
{
string tname;
struct student s[5];
};
//给老师和学生赋值的函数,len是计算老师个数
void allocateSpace(struct teacher t[], int len)
{
string nameSeed = "ABCDE";
for (int i = 0; i < len; i++)
{
t[i].tname = "teacher_";
t[i].tname += nameSeed[i];
for (int j = 0; j < 5; j++)
{
t[i].s[j].sname = "student_";
t[i].s[j].sname += nameSeed[j];
int random = rand() % 61 + 40;//40~100
t[i].s[j].score = random;
}
}
}
void printInfo(struct teacher t[],int len)
{
for (int i = 0; i < len; i++)
{
cout << "老师姓名: " << t[i].tname << endl;
for (int j = 0; j < 5; j++)
{
cout << "\t学生姓名:" << t[i].s[j].sname
<< "考试分数:" << t[i].s[j].score << endl;
}
}
}
int main() {
//随机数种子
srand((unsigned int)time(NULL));
//1、创建3名老师的数组
struct teacher t[3];
//2、通过函数给3名老师的信息赋值,并给老师带的学生信息赋值
int len = sizeof(t) / sizeof(t[0]);
allocateSpace(t, len);
//3、打印所有老师及所带的学生信息
printInfo(t, len);
system("pause");//让程序暂停一下,然后按任意键继续
return 0;//表明程序正常退出,返回到主程序继续往下执行
}
复习了41-61课的内容,指针和函数还需要找实例多练习,应用还不太熟练,还有些需要背诵的东西,多多使用应该会加强记忆,周末会接着学习,将两个结构体案例学习完
2:本周阅读整理了有关奥巴马的一篇文章(顺便推荐一下这本书,确实是方便又不错,纸张写字也舒服,文后还有对长难句的分析,部分生词都在下面能查到,还能拓展视野,强烈推荐!)
3:下周开始锻炼计划,保持每天的运动量,学习的同时也要身体健康啊。