C++语言程序设计实验报告——实验一

实验一 C++开发环境应用入门

一、实验目的及要求

1.掌握类的构造函数和析构函数的概念和使用方法
2.学习简单的面向对象程序的编写

二、实验环境

1、硬件要求:计算机一台。
2、软件要求:Windows操作系统,Dev-C++或VC++ 6.0编译环境

三、实验内容

设计一个Student类
(1)基本信息:学号、姓名、性别、出生日期、年级、班级、院系、专业;
其中:基本信息为private属性,成员函数为public属性;
(2)Student类有多个构造函数:缺省构造函数、带参数的构造函数、带默认参数的构造函数
(3)基本功能:
A)可以从键盘输入学生的基本信息;
B)定义一个函数SetInfo(形参表),可以修改学生的基本信息函数,例如:班级、专业等;
C)定义一个Show()函数显示学生信息;

#include<iostream>
#include<cmath>
#include<string>
using namespace std; 
class Student 
{ 
private:  
	double num;
	string name, sex, grade, clas, department, major,birthdate;  
public:
	Student() 
	{
	}
	Student(double num,string birthdate,string name,string sex,string grade,string clas,string department,string major){
		this->num=num;
		this->name=name;
		this->sex=sex;
		this->grade=grade;
		this->clas=clas;
		this->department=department;
		this->birthdate=birthdate;
		this->major=major;
	}
	~Student() 
	{
	}
	void SetIn() 
	{
		cout  << "学号:" << endl;     
		cin  >> num;
		cout  << "姓名:" << endl;     
		cin  >> name;
		cout  << "性别:" << endl;     
		cin  >> sex;
		cout  << "出生日期:" << endl;     
		cin  >> birthdate;     
		cout  << "年级:" << endl;     
		cin  >> grade;
		cout  << "班级:" << endl;
		cin  >> clas;
		cout  << "院级:" << endl;
		cin  >> department;     
		cout  << "专业:" << endl;     
		cin  >> major;
	}
	void Show() 
	{
		cout  << "学号:" << num  << endl;   
		cout  << "姓名:" << name  << endl;
		cout  << "性别:" << sex << endl;
		cout  << "出生日期:" << birthdate  << endl;   
		cout  << "年级:" << grade  << endl;  
		cout  << "班级:" << clas  << endl; 
		cout  << "院级:" << department  << endl;
		cout  << "专业:" << major  << endl;
	}
	void SetInfo()
	{
		char a;
		cout  << "是否修改(是=y,否=n)" << endl;
		cin  >> a;  
		if (a  == 'y')
		{
			SetIn();
			SetInfo();
		}  
		else 
		{ 
			Show();
		}
	}
 };
 int main() 
 {
	 Student Stu;
	 Stu.SetIn();
	 Stu.SetInfo();
	 system("pause");
	 return 0;
}

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

刚入坑的软件猿

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

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

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

打赏作者

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

抵扣说明:

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

余额充值