您的位置:首页 > 编程语言

第十章编程练习(1)

2016-02-01 22:44 330 查看
ff.h
#pragma once
#ifndef ff_H_
#define ff_H_
#include <string>
using namespace std;
const int MAX = 6;
class Sudio
{
string name;
char number[MAX];
double money;
public:
Sudio();
~Sudio();
void set(const string & str, const char * num, double mon);
void need(double mon);
};
#endif
function.cpp<pre class="cpp" name="code">#include <iostream>
#include "ff.h"
#include <cstdlib>
#include <string>
extern const int MAX;
int main()
{
Sudio su;
char ch[MAX] = "12345";
su.set("asd", ch, 3.2);
cout << "Need\n";
su.need(2.1);
system("pause");
return 0;
}


main.cpp
#include <iostream>
#include "ff.h"
extern const int MAX;
using namespace std;
Sudio::Sudio()
{
name = "Error";
number[MAX] = 0;
money = 0;
}
void Sudio::set(const string & str, const char * num, double mon)
{
name = str;
int j = 1;
for (int i = 0; i < MAX; i++)
number[i] == num[i];
j++;
if (j == MAX);
if(mon >= 0)
money += mon;
else {
cout << "Error!\n";
return;
}
cout << "The balance on your account is: $ " <<money<< endl;
}
void Sudio::need(double mon)
{
if (money >= mon)
{
money -= mon;
cout << "The balance on your account is: $ " << money << endl;
}
else {
cout << "Insufficient balance on the account you!" << endl;
}
}
Sudio::~Sudio()
{
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: