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");
}
|
请发表评论