帮我制作以下程序的Gui [英] Help me to make Gui for the following program

查看:63
本文介绍了帮我制作以下程序的Gui的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<iostream>
#include<string>
#include<iomanip>

using namespace std;
const double main_balance=10000;
double deposit(double amount);
double withdraw(double amount);

    int main()
    {
            string password;
            string account;
        cout<<"\t";cout<<"\t";
    cout<<"DEPOSIT AND WITHDRAW "<<endl;
    cout<<"................................................................................\n";
cout<<endl<<endl;
cout<<endl;
cout<<"\t\tEnter account number\t";
cin>>account;
    cout<<"\t";cout<<"\t";
    if(account.length()>=13)
    {

    cout<<"Enter password \t";
    cin>>password;
    cout<<endl;
    if(password.size()>=8)
    {
    cout<<"\t\tCHOOSE THE SERVICE FROM THE MENU "<<endl;
    cout<<endl;
    cout<<endl;
    char select;
    cout<<"A"<<" "<<"WITHDRAW MONEY";cout<<"\t";cout<<"\t";
    cout<<"B"<<" "<<"DEPOSIT MONEY";cout<<"\t";cout<<"\t";
    cout<<"C"<<" "<<"CHECK BALANCE\n";
    cout<<"\t\t\t\t";
    cin>>select;
    switch (select)
    {
        case 'A':
        case 'a':
            double money;
            double Amount;
            Amount=withdraw(money);
            break;
        case 'B':
        case 'b':
        double cash;
        double new_amount;
        new_amount=deposit(cash);cout<<"\t";
        cout<<"You have deposited \t"<<"Tsh"<<cash;
        cout<<endl;
        cout<<"\t";
        cout<<"The balance is \t"<<"Tsh"<<new_amount;

        break;
        case 'c':
        case 'C':
            cout<<"\t\t";
        cout<<"You are balance is "<<"Tsh "<<main_balance<<endl;
        break;
    default:

        cout<<"\t"<<"\t"<<"Invalid selection";
        cout<<endl;
        cout<<"\t\t";
    }

}

else
{
    cout<<"\t"<<"\t"<<"Your password is less than 8"<<endl;
}
}
else
{
    cout<<"Account number should contain 13 digits and above";
}
    return 0;
}

    double deposit(double amount)
    {
        cout<<"\t"<<"\t"<<"Enter the amount you to deposit\t";

        cin>>amount;
        cout<<endl;
        double new_balance;
        new_balance=main_balance+amount;
        return new_balance;
    }
    double withdraw(double amount)
    {
        double remain_balance;
        cout<<"\t"<<"\t"<<"Enter amount to withdraw from your account\t";
        cin>>amount;
        if(amount>=main_balance)
        {
            cout<<"\t"<<"\t"<<"You have insufficent balance to withdraw\t"<<"Tsh"<<amount;
            cout<<endl;
        }
        else
        {
            remain_balance=main_balance-amount;
            cout<<"\t"<<"\t"<<"You have withdrawn \t"<<amount<<endl;
            cout<<"\t"<<"\t"<<"Balance remained after to withraw\t"<<remain_balance<<endl;
            cout<<endl;

        return remain_balance;
        }
    }

推荐答案

虽然我同意这是一个措辞不好(并且研究过!)的问题,但是我的选择中的一个项目模板直接得到了答案,Code :: Blocks 。我所做的就是添加按钮和代码来处理按下此按钮。



自从我上次查看DevC ++以来已经有7年甚至更长时间了 - 我我不知道它是否有tchar.h,虽然我想它会。如果没有(并且代码不会因此而编译),您可以进行一些相当简单的更改:



1.删除<$之前的代码c $ c> #include< windows.h> 并将其替换为 #define UNICODE 1

2。删除 _T()的所有实例。将其替换为 L

_T(你按下按钮1。)变为 L你按下按钮1。



最后,看一下资源编辑器和对话框应用程序。我和许多其他人使用ResEdit来创建资源(.rc)文件。



注意:您应该链接以下库:gdi32,user32,kernel32,comctl32



While I agree that this is a poorly phrased (and researched!) question, there's an answer that comes straight from one of the project templates in my ide of choice, Code::Blocks. All I've done is add the button and the code to handle presses of this button.

It's been some 7 years or more since I last looked at DevC++ - I've no idea if it has a tchar.h, though I'd imagine it would. If it doesn't (and the code wont compile as a result), you can make a few fairly simple changes:

1. Remove the the code before #include <windows.h> and replace it with #define UNICODE 1
2. Remove all instances of _T(). Replace this with L.
I.e _T("You pressed button1.") becomes L"You pressed button1."

Finally, have a look into resource editors and dialog apps. I and many others use ResEdit to create the resource (.rc) file.

Note: You should link the following libraries: gdi32, user32, kernel32, comctl32

#if defined(UNICODE) && !defined(_UNICODE)
    #define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
    #define UNICODE
#endif

#include <tchar.h>
#include <windows.h>

#define IDC_BUTTON1 1000

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           _T("Code::Blocks Template Windows App"),       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    CreateWindow( _T("Button"), _T("Button1"), WS_VISIBLE|WS_CHILD, 20,20, 75,23, hwnd, (HMENU)IDC_BUTTON1, hThisInstance, NULL);

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;

        case WM_COMMAND:
            {
                switch LOWORD(wParam)
                {
                case IDC_BUTTON1:
                    MessageBox(hwnd, _T("You pressed button1."), _T("Attention"), MB_ICONEXCLAMATION);
                    break;
                }
            }
            break;

        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}


这篇关于帮我制作以下程序的Gui的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆