昆仑山:眼中无形心中有穴之穴人合一

夫君子之行,静以修身,俭以养德;非澹泊无以明志,非宁静无以致远。夫学须静也,才须学也;非学无以广才,非志无以成学。怠慢则不能励精,险躁则不能冶性。年与时驰,意与岁去,遂成枯落,多不接世。悲守穷庐,将复何及!

 

C++ 接口封装 调用

输入Keypad

Keypad头文件

#pragma once
class Keypad
{
public:
	Keypad();
	int getInput()const;
	~Keypad();
};

Keypad源文件

#include "Keypad.h"
#include"Screen.h"
#include<iostream>
using namespace std;


Keypad::Keypad()
{
}

int Keypad::getInput() const
{	
	int input;
	Screen screen;
	screen.displayMessageLine("pls input amount:\t\n");
	cin >> input;
	return input;
}


Keypad::~Keypad()
{
}


输出 Screen

Screen头文件

#pragma once

using namespace std;
#include<string>
class Screen
{
public:
	Screen();
	void displayMessage(string)const;//输出消息
	void displayMessageLine(string)const;//换行输出消息
	void displayDollarAmount(double)const; // 输出金额
	~Screen();
};

screen源文件

#include "Screen.h"
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
Screen::Screen()
{
}

void Screen::displayMessage(string message) const
{
	cout << message;
}

void Screen::displayMessageLine(string message) const
{
	cout << message << endl;
}

void Screen::displayDollarAmount(double amount) const
{
	cout << fixed << setprecision(2) << "$" << amount;
}


Screen::~Screen()
{
}

驱动测试或者客户端测试

#include<iostream>
#include"Screen.h"
#include"Keypad.h"
#include<stdlib.h>
using namespace std;
int main() {
	Screen screen;
	Keypad keypad;
	
	screen.displayDollarAmount(keypad.getInput());
	putchar(10);
	
	screen.displayMessageLine("there is no choice but to grow!!");

	screen.displayMessage("hello world");
	system("pause");
}

posted on 2018-09-18 15:50  Indian_Mysore  阅读(999)  评论(0编辑  收藏  举报

导航