标签:pac 系统 names rand 实现 空间 ret 函数 com
//computer.h
class computer //类定义
{
private:
char brand[20];
float price;
public:
void print();
void SetBrand(const char * sz);
void SetPrice(float pr);
};
#include "computer.h" //包含类定义
#include <iostream>
using namespace std;
void computer::print() //成员函数的实现
{
cout << "品牌:" << brand << endl;
cout << "价格:" << price << endl;
}
void computer::SetBrand(char * sz)
{
strcpy(brand, sz); //字符串复制
}
void computer::SetPrice(float pr)
{
price = pr;
}
#include "computer.h" //定义了类computer
int main() //主函数
{
computer com1; //声明了computer类对象(或说类变量)com1
com1.SetBrand("Lenovo");//调用public成员函数SetBrand设置品牌brand
com1.SetPrice(8000); //调用public成员函数SetPrice设置品牌price
com1.print(); //信息输出
return 0;
}
标签:pac 系统 names rand 实现 空间 ret 函数 com
原文地址:http://www.cnblogs.com/Burgess-Fan/p/7049881.html