追回C++(2)

基本类型的理解,对引用和指针的理解

using namespace std;
//学生实体
struct StudentDto
{
	//名称
	string CName;
	//英文名
	char EName [50];
	//年龄
	int Age;
	//性别
	char Sex;
	//是否缴费
	bool IsFee;
	//分数
	double FenShu;

};

#include <iostream>
#include "Student.h"
using std::cin;
using std::cout;
using std::endl;

int main()
{
	cout << "基本类型、引用、指针!" << endl;
	//学生1
	StudentDto stu1;
	//学生2
	StudentDto stu2;
	//学生3
	StudentDto stu3;
	cout << "请依次录入学生1的姓名、英文名、年龄、性别、是否缴费、分数信息" << endl;
	cin >> stu1.CName >> stu1.EName >> stu1.Age >> stu1.Sex >> stu1.IsFee>>stu1.FenShu;
	cout << "请依次录入学生2的姓名、英文名、年龄、性别、是否缴费、分数信息" << endl;
	cin >> stu2.CName >> stu2.EName >> stu2.Age >> stu2.Sex >> stu2.IsFee >> stu2.FenShu;
	cout << "请依次录入学生3的姓名、英文名、年龄、性别、是否缴费、分数信息" << endl;
	cin >> stu3.CName >> stu3.EName >> stu3.Age >> stu3.Sex >> stu3.IsFee >> stu3.FenShu;
	cout << "两个学生平均分是:" << ((stu1.FenShu + stu2.FenShu) / 2) << endl;
	cout << "下面测试引用和指针*****************************" << endl;
	//学生1的引用
	StudentDto& stu1Alias = stu1;
	//学生2的指针
	StudentDto* stu2Point = &stu2;
	cout << "请修改学生1的分数" << endl;
	cin >> stu1Alias.FenShu;
	cout << "请修改学生2的分数" << endl;
	cin >> (*stu2Point).FenShu;
	//输出全用原始对象
	cout << "两个学生修改后平均分是:" << ((stu1.FenShu + stu2.FenShu) / 2) << endl;
	cout << "下面测试指针传递********************************" << endl;
	//指针指向引用
	StudentDto* stu1AliasP = &stu1Alias;
	//指针指向指针
	StudentDto** stu2PP = &stu2Point;
	cout << "请修改学生1的分数" << endl;
	cin >> (*stu1AliasP).FenShu;
	cout << "请修改学生2的分数" << endl;
	cin >> (**stu2PP).FenShu;
	//输出全用原始对象
	cout << "两个学生修改后平均分是:" << ((stu1.FenShu + stu2.FenShu) / 2) << endl;
	cout << "下面测试指针传切换指向*****************************" << endl;
	//学生2指针指向学生3,应该操作到三上去了
	stu2Point = &stu3;
	//一级指针应该输出学生三姓名
	cout << "一级指针输出,我是:" << (*stu2Point).CName << endl;
	//二级指针也应该输出学生三姓名
	cout << "二级指针输出我是:" << (**stu2PP).CName << endl;
	return 0;
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小乌鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值