CHAPER 14 1 3 5

CHAPER 14

1

文件1:

3

文件1:

5

文件1:

//*********************************************************************
// Programming Problems 5  Chapter 14  Programming in C++
// Programmer: Wang Dong  Date: 2010-6-17
//*********************************************************************
#include <string>
#include <iostream>
using namespace std;
class Computer
{
public:
	Computer(string newName,string newBrand,string newModel,int newSpeed,string newSerial,int newNumber);
	string GetName() const;
	string GetBrand() const;
	string GetModel() const;
	int GetSpeed() const;
	string GetSerial() const;
	int GetNumber() const;
	void Write() const;
private:
	string name;
	string brand;
	string model;
	int speed;
	string serialNumber;
	int inventoryNumber;
}; 

文件2:

//*********************************************************************
// Programming Problems 5  Chapter 14  Programming in C++
// Programmer: Wang Dong  Date: 2010-6-17
//*********************************************************************

#include "Computer.h"

Computer::Computer(string newName,string newBrand,string newModel,int newSpeed,string newSerial,int newNumber)
{
	name=newName;
	brand=newBrand;
	model=newModel;
	speed=newSpeed;
	serialNumber=newSerial;
	inventoryNumber=newNumber;
}

string Computer::GetName() const
{
	return name;
}

string Computer::GetBrand() const
{
	return brand;
}

string Computer::GetModel() const
{
	return model;
}

int Computer::GetSpeed() const
{
	return speed;
}

string Computer::GetSerial() const
{
	return serialNumber;
}

int Computer::GetNumber() const
{
	return inventoryNumber;
}

void Computer::Write() const
{
	cout << "Name: " << name << endl;
	cout << "Brand: " << brand << endl;
	cout << "Model: " << model << endl;
	cout << "Speed: " << speed << endl;
	cout << "Serial Number: " << serialNumber << endl;
	cout << "Inventory Number: " << inventoryNumber << endl;
}

文件3:

//*********************************************************************
// Programming Problems 5  Chapter 14  Programming in C++
// Programmer: Wang Dong  Date: 2010-6-17
//*********************************************************************
#include "Computer.h"
using namespace std;
void main ()
{
	Computer com("computer1","lenovo","China",2,"Tianjiao_E",100);
	cout << "Name: " << com.GetName() << endl;
	cout << "Brand: " << com.GetBrand() << endl;
	cout << "Model: " << com.GetModel() << endl;
	cout << "Speed: " << com.GetSpeed() << endl;
	cout << "Serial Number: " << com.GetSerial() << endl;
	cout << "Inventory Number: " << com.GetNumber() << endl;
	cout << "Write: " << endl;
	com.Write();
}
上一篇:AI之HCI:人机交互Human-Computer Interaction的简介、发展历史、案例应用之详细攻略


下一篇:建造者模式