码迷,mamicode.com
首页 > 编程语言 > 详细

C代码和python代码:模拟ATM(自动柜员机)界面

时间:2020-02-21 00:17:15      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:c语言   time   语句   getc   pychar   ase   单选   atm   删除   

一、前言与总结

  1. python中没有可以替代 switch 语句的,
    所以那些break都是没有作用的,可以删除掉
  2. 用途 C语言 Python
    清屏 system("cls") i = os.system("cls")
    暂停 getchar() k=input()

二、C代码

运行环境:VS2017
以下是代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char SelectKey,CreditMoney,DebitMoney;
    while(1)
    {
        do{
            system("cls");
            puts("=========================");
            puts("|  Please select key:   |");
            puts("|  1. Quary             |");
            puts("|  2. Credit            |");
            puts("|  3. Debit             |");
            puts("|  4. Return            |");
            puts("=========================");
            SelectKey = getch();
        }while( SelectKey!='1' && SelectKey!='2' && SelectKey!='3' && SelectKey!='4' );
        switch(SelectKey)
        {
            case '1':
                system("cls");
                puts("================================");
                puts("|    Your balance is $1000.    |");
                puts("|  Press any key to return...  |");
                puts("================================");
                getchar();
                break;
            case '2':
                do{
                    system("cls");
                    puts("==================================");
                    puts("|   Please select Credit money:  |");
                    puts("|   1. $50                       |");
                    puts("|   2. $100                      |");
                    puts("|   3. Return                    |");
                    puts("==================================");
                    CreditMoney = _getch();
                }while( CreditMoney!='1' && CreditMoney!='2' && CreditMoney!='3' );
                switch(CreditMoney)
                {
                    case '1':
                        system("cls");
                        puts("=========================================");
                        puts("|  Your Credit money is $50,Thank you!  |");
                        puts("|         Press any key to return...    |");
                        puts("=========================================");
                        getchar();
                        break;
                    case '2':
                        system("cls");
                        puts("==========================================");
                        puts("|  Your Credit money is $100,Thank you!  |");
                        puts("|         Press any key to return...     |");
                        puts("==========================================");
                        getchar();
                        break;
                    case '3':
                        break;
                }
                break;
            case '3':
                do{
                    system("cls");
                    puts("====================================");
                    puts("|   Please select Debit money:     |");
                    puts("|   1. $50                         |");
                    puts("|   2. $100                        |");
                    puts("|   3. $500                        |");
                    puts("|   4. $1000                       |");
                    puts("|   5. Return                      |");
                    puts("====================================");
                    DebitMoney = _getch();
                }while( DebitMoney!='1' && DebitMoney!='2' && DebitMoney!='3'                  && DebitMoney!='4' && DebitMoney!='5' );
                switch(DebitMoney)
                {
                    case '1':
                        system("cls");
                        puts("===========================================");
                        puts("|   Your Debit money is $50,Thank you!    |");
                        puts("|        Press any key to return...       |");
                        puts("===========================================");
                        getchar();
                        break;
                    case '2':
                        system("cls");
                        puts("===========================================");
                        puts("|   Your Debit money is $100,Thank you!   |");
                        puts("|        Press any key to return...       |");
                        puts("===========================================");
                        getchar();
                        break;
                    case '3':
                        system("cls");
                        puts("===========================================");
                        puts("|   Your Debit money is $500,Thank you!   |");
                        puts("|        Press any key to return...       |");
                        puts("===========================================");
                        getch();
                        break;
                    case '4':
                        system("cls");
                        puts("===========================================");
                        puts("|   Your Debit money is $1000,Thank you!  |");
                        puts("|        Press any key to return...       |");
                        puts("===========================================");
                        getchar();
                        break;
                    case '5':
                        break;
                }
                break;
            case '4':
                system("cls");
                puts("================================");
                puts("|   Thank you for your using!  |");
                puts("|            Good bye!         |");
                puts("================================");
                return 0;
        }
    }
    getchar();
    getchar();
    return 0;
}

三、Python代码

运行环境:Pycharm,python3.74
pycharm中的 i=os.system("cls") 清屏效果没有体现,凑合着用
以下是代码:

import os
import time

def SK():
    """
    银行机器的选择键
    """
    i=os.system("cls")
    print("=========================")
    print("|  Please select key:   |")
    print("|  1. Quary             |")
    print("|  2. Credit            |")
    print("|  3. Debit             |")
    print("|  4. Return            |")
    print("=========================")
    SelectKey = input()
    return SelectKey

def CM():
    """
    CM()是贷款的菜单选项
    """
    i=os.system("cls")
    print("==================================")
    print("|   Please select Credit money:  |")
    print("|   1. $50                       |")
    print("|   2. $100                      |")
    print("|   3. Return                    |")
    print("==================================")
    CreditMoney = input()
    return CreditMoney

def CM1( x):
    """
    贷款的提示语
    """
    i=os.system("cls")
    print("=========================================")
    print("|  Your Credit money is ", x,"Thank you!  |")
    print("|         Press any key to return...    |")
    print("=========================================")
    m = int(0)
    return m

def DM():
    """
    DM()是借钱的菜单选项
    """
    i=os.system("cls")
    print("====================================")
    print("|   Please select Debit money:     |")
    print("|   1. $50                         |")
    print("|   2. $100                        |")
    print("|   3. $500                        |")
    print("|   4. $1000                       |")
    print("|   5. Return                      |")
    print("====================================")
    DebitMoney = input()
    return DebitMoney

def DM1(x):
    """
    借钱的提示语
    """
    i=os.system("cls")
    print("===========================================")
    print("|   Your Debit money is ", x, ",Thank you!    |")
    print("|        Press any key to return...       |")
    print("===========================================")
    m = int(0)
    return m

def R():
    """
    这是返回主菜单的过渡页
    """
    i=os.system("cls")
    print("****** ",end="")
    time.sleep(1)
    print("Please wait patiently. ",end="")
    time.sleep(1)
    print("******")

def main():
    while 1:
        SelectKey=SK()
        while SelectKey!='1' and SelectKey!='2' and SelectKey!='3' and SelectKey!='4':
            SelectKey=SK()
        if SelectKey=='1':
            i=os.system("cls")
            print("================================")
            print("|    Your balance is $1000.    |")
            print("|  Press any key to return...  |")
            print("================================")
            k=input()
            R()

        elif SelectKey=='2':
            CreditMoney = CM()
            while CreditMoney != '1' and CreditMoney != '2' and CreditMoney != '3':
                CreditMoney = CM()
            if CreditMoney == '1':
                m = CM1(50)
                k=input()
            elif CreditMoney == '2':
                m = CM1(100)
                k=input()
            else:
                R()

        elif SelectKey=='3':
            DebitMoney = DM()
            while DebitMoney!='1' and DebitMoney!='2' and DebitMoney!='3'                 and DebitMoney!='4' and DebitMoney!='5':
                DebitMoney = DM()
            if DebitMoney == '1':
                n=DM1(50)
                k=input()
            elif DebitMoney == '2':
                n=DM1(100)
                k=input()
            elif DebitMoney == '3':
                n=DM1(500)
                k=input()
            elif DebitMoney == '4':
                n=DM1(1000)
                k=input()
            else:
                R()

        else:
            i=os.system("cls")
            print("================================")
            print("|   Thank you for your using!  |")
            print("|            Good bye!         |")
            print("================================")
            return 0

main()

C代码和python代码:模拟ATM(自动柜员机)界面

标签:c语言   time   语句   getc   pychar   ase   单选   atm   删除   

原文地址:https://www.cnblogs.com/jmshy/p/12337916.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!