⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eg1.cpp

📁 C++课程更学习...对于初学者很有好出
💻 CPP
字号:
// eg1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <string.h>

// 类
class Student
{
private: // 私有
	char  m_sName[40];   // 姓名
	int   m_nID;         // 学号
	int   m_nAge;        // 年龄
	int   m_nClassNo;    // 班号 

public: // 公有
	void InitStudent(char* sName, int nID,
		int nAge, int nClassNo)
	{
		strcpy(m_sName,sName);
		m_nID = nID;
		m_nAge = nAge;
		m_nClassNo = nClassNo;
	}

	void ShowInfo()
	{
		printf("姓名: %s 学号:%d 年龄:%d 班号:%d\n", 
			m_sName, m_nID, m_nAge, m_nClassNo);
	}

	void UnitStudent()
	{
		// Nothing need to do.
	}

	char* GetName()
	{
		return m_sName;
	}

	int GetID()
	{
		return m_nID;
	}

	int GetAge()
	{
		return m_nAge;
	}

	int GetClassNo()
	{
		return m_nClassNo;
	}

	void SetAge(int nAge)
	{
		if (nAge > 0 && nAge < 150)
			m_nAge = nAge;
	}
};

int main(int argc, char* argv[])
{
	Student Jack; // 对象(包含成员函数的变量)
/*	
	strcpy(Jack.m_sName, "Jack");
	Jack.m_nAge = 21;
	Jack.m_nID = 30;
	Jack.m_nClassNo = 101;
*/	
	//printf("%d\n", sizeof(Student));

	Jack.InitStudent("Jack", 30, 21, 101);
	Jack.ShowInfo();

	printf("Name:%s ID:%d Age:%d ClassNo:%d\n",
		Jack.GetName(), 
		Jack.GetID(),
		Jack.GetAge(),
		Jack.GetClassNo());

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -