C++学习第四十七篇

C++学习第四十七篇,第1张

C++学习第四十七篇
#include
#include 
using namespace std;

//1、创建学生数据类型:学生包括(姓名年龄分数)
//自定义数据类型,一些类型集合组成的一个类型
//语法 struct 类型名称 {成员列表};
struct Student
{
	//成员列表

	//姓名
	string name;
	//年龄
	int age;
	//分数
	int score;
};
int main()
{
	//2、创建结构体数组
	struct Student stuArray[3] =
	{
		{"张三",18,100},
		{"李四",19,90},
		{"王五",20,95},
	};

	//3、给结构体数组中的元素赋值
	stuArray[2].name = "赵六";
	stuArray[2].age = 80;
	stuArray[2].score = 90;
	//4、遍历结构体数组
	for (int i = 0;i<3;i++)
	{
		cout << "姓名:" << stuArray[i].name << "  年龄:" 
			<< stuArray[i].age << "  分数:" << stuArray[i].score << endl;
	}
	
	system("pause");
	return 0;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5611506.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存