| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1572 人关注过本帖
标题:程序运行可以,但达不到预期,只能读取默认值,不能存也不能取
取消只看楼主 加入收藏
C00000001
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-5-8
结帖率:100%
收藏
 问题点数:0 回复次数:1 
程序运行可以,但达不到预期,只能读取默认值,不能存也不能取
程序运行可以,但达不到预期,只能读取默认值,不能存也不能取
头文件
#ifndef STACK_H_
#define STACK_H_
namespace bank
{
    class Stack
    {
    private:
        enum{Max=40};
        char fullname[Max];
        char account[Max];
        unsigned long deposit;
        unsigned long deposit_temp;
        void set_tot() { deposit = deposit + deposit_temp; }
    public:
        void save(Stack& n,char* name_user,char*name_acount,unsigned long money);
        void withdraw(Stack& n, char* name_user, char* name_acount, unsigned long money);
        bool verify_name(Stack& n, char* name_name);
        bool verify_acount(Stack& n, char* name_acount);
        void show(const Stack& n)const;
        Stack();
        Stack(const char* name_user, const char* name_acount, unsigned long money);
        ~Stack();
    };
}
#endif
源代码1
#include<iostream>
#include"未命名2.h"
#include<cstring>
#include<cstdlib>
void bank::Stack::save(Stack& n, char* name_user, char* name_acount, unsigned long money)
{
    if (!verify_name(n, name_user))
        {
            std::cout << "Error! validation error!";
            exit(-1);
        }
    else if (!verify_acount(n, name_acount))
        {
            std::cout << "Error! validation error!";
            exit(-1);
        }
    else
        n.deposit_temp = money;
    set_tot();
}
void bank::Stack::withdraw(Stack& n, char* name_user, char* name_acount, unsigned long money)
{
    if (!verify_name(n,name_user))
        {
            std::cout << "Error! validation error!";
            exit(-1);
        }
    else if (!verify_acount(n,name_acount))
        {
            std::cout << "Error! validation error!";
            exit(-1);
        }
    else
        n.deposit_temp = -money;
    set_tot();
}
bool bank::Stack::verify_name(Stack& n, char* name_name)
{
    if (strcmp(n.fullname, name_name) == 0)
        return true;
    else
        return false;
}
bool bank::Stack::verify_acount(Stack& n, char* name_acount)
{
    if (strcmp(n.account, name_acount) == 0)
        return true;
    else
        return false;
}
void bank::Stack::show(const Stack& n)const
{
    using std::cout;
    using std::endl;
    cout << "Fullname: " << n.fullname << endl;
    cout << "Acount: " << n.account << endl;
    cout << "Deposit: " << n.deposit << endl;
}
bank::Stack::Stack()
{

}
bank::Stack::Stack(const char* name_user, const char* name_acount, unsigned long money)
{
    strcmp(fullname, "no name");
    strcmp(account, "no acount");
    deposit = 0;
}
bank::Stack::~Stack()
{

}
程序文件
#include<iostream>
#include"未命名2.h"
int main()
{
    using namespace bank;
    using namespace std;
    Stack stock1("dsadda", "safa", 5465);
    cout << "Enter s(save mony) w(withdraw money) o(show the acount) q(to quit):";
    char ch;
    char temp_name[40];
    char temp_acount[40];
    unsigned long temp_money;
    while (cin >> ch && ch != 'q'&&ch!='Q')
    {
        if (ch == 'q' || ch == 'Q')
            break;
        else
        {
            switch (ch)
            {
            case's':
            case'S':cout << "Enter the fullname:";
                cin.get();
                cin.getline(temp_name, 40);
                cout << "Enter the acount:";
                cin.getline(temp_acount, 40);
                cout << "Enter the money:";
                cin >> temp_money;
                cin.get();
                stock1.save(stock1, temp_name, temp_acount, temp_money);
                break;
            case'W':
            case'w':cout << "Enter the fullname:";
                cin.get();
                cin.getline(temp_name, 40);
                cout << "Enter the acount:";
                cin.getline(temp_acount, 40);
                cout << "Enter the money:";
                cin >> temp_money;
                cin.get();
                stock1.withdraw(stock1, temp_name, temp_acount,temp_money);
                break;
            case'o':
            case'O':stock1.show(stock1);
            }
        }
    }
    cout << "Bye!";
    return 0;
}
搜索更多相关主题的帖子: Stack cout char cin money 
2021-05-22 17:06
C00000001
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-5-8
收藏
得分:0 
不用visual studio 编译 strcmp()不能用我这个编译
我用的Dev-c++能编译
2021-05-22 17:12
快速回复:程序运行可以,但达不到预期,只能读取默认值,不能存也不能取
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.100465 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved