class 4

// omputer.h: interface for the Computer class.
//
//

#if !defined(AFX_OMPUTER_H__2C841290_BF9E_410C_960A_9E152D78E5D0__INCLUDED_)
#define AFX_OMPUTER_H__2C841290_BF9E_410C_960A_9E152D78E5D0__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include<string>
using std::string;

class Computer  
{
	int nCPUs;
	int cpuFreq;
	string cpuBrand;
	
public:
	//有默认参数的函数起到重载函数的作用
	Computer(int n=1);//Computer(); //default constructor

	virtual ~Computer();//destructor

};

#endif // !defined(AFX_OMPUTER_H__2C841290_BF9E_410C_960A_9E152D78E5D0__INCLUDED_)

int main()
{
	Computer acer;//默认初始化
	int x(3);
	int y;
	Computer hp(16);
	Computer *p=NULL;
	p = new Computer(("Cortex"),4);
	
	Computer dell(string("intel"),8,3.2);
	Computer IBM(string("AMD"));
	if(p)
		delete p;
	Computer *q= new Computer[4];//对象数组	
	delete []q;
	Computer w101[60]={{},{},{}};//对象初始化
	//Computer a{string("Intel"),7,2.4};新版本的初始化,vc6.0不支持
	return 0;
}


// computer.cpp: implementation of the computer class.
//
//

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


Computer::Computer(int n)
{
	nCPUs=n;
	cout<<"内核:"<<n<<endl;
	cout<<"默认构造函数"<<endl;

}

Computer::~Computer()
{
	cout<<"析构函数\t";
	cout<<"销毁电脑的CPU核心数:"<<nCPUs<<endl;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值