借贷计算器源代码(贷款计算器源码)
admin 发布:2022-12-19 18:36 209
本篇文章给大家谈谈借贷计算器源代码,以及贷款计算器源码对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、求WINDOWS一样的计算器JAVA源代码一个
- 2、vc计算器代码
- 3、VC计算器的源代码
- 4、c语言贷款计算器的源程序
- 5、C#计算器源代码
- 6、求一个 java 个人贷款还款计算器 的源代码,
求WINDOWS一样的计算器JAVA源代码一个
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator
{
public static void main(String[] args)
{
CalculatorFrame frame=new CalculatorFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class CalculatorFrame extends JFrame
{
public CalculatorFrame()
{
setTitle("Calculator");
CalculatorPanel panel=new CalculatorPanel();
add(panel);
pack();
}
}
class CalculatorPanel extends Panel
{
public CalculatorPanel()
{
setLayout(new BorderLayout());
result=0;
lastCommand="=";
start=true;
flag=true;
display=new JButton("0");
display.setEnabled(false);
add(display,BorderLayout.NORTH);
ActionListener insert=new InsertAction();
ActionListener command=new CommandAction();
panel=new JPanel();
panel.setLayout(new GridLayout(4,5));
addButton("7",insert);
addButton("8",insert);
addButton("9",insert);
addButton("/",command);
addButton("CE",command);
addButton("4",insert);
addButton("5",insert);
addButton("6",insert);
addButton("*",command);
addButton("Backspace",command);
addButton("1",insert);
addButton("2",insert);
addButton("3",insert);
addButton("-",command);
addButton("sqrt",command);
addButton("0",insert);
addButton(".",insert);
addButton("=",command);
addButton("+",command);
addButton("1/x",command);
add(panel,BorderLayout.CENTER);
}
private void addButton(String label,ActionListener listener)
{
JButton button=new JButton(label);
button.addActionListener(listener);
panel.add(button);
}
private class InsertAction implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
String input=event.getActionCommand();
if(startflag)
{
display.setText("");
start=false;
}
if(flag)
display.setText(display.getText()+input);
}
}
private class CommandAction implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
String command=event.getActionCommand();
if(command.equals("CE"))
{
display.setText("0");
start=true;
flag=true;
command="=";
}
else
if(startflag)
{
if(command.equals("-"))
{
display.setText(command);
start=false;
}
else
if((command.equals("1/x")||command.equals("sqrt"))flag)
calculate(Double.parseDouble(display.getText()),command);
else
if(flag)
lastCommand=command;
}
else
{
if(command.equals("Backspace")flag)
{
String s=display.getText();
char[] s1=s.toCharArray();
if(s.length()=2)
{
String s2=new String(s1,0,s.length()-1);
display.setText(s2);
}
else
{
display.setText("0");
start=true;
}
}
else if(flag)
{
calculate(Double.parseDouble(display.getText()),command);
lastCommand=command;
start=true;
}
}
}
}
public void calculate(double x,String command)
{
if(lastCommand.equals("+")) result+=x;
else if(lastCommand.equals("-")) result-=x;
else if(lastCommand.equals("/"))
{
if(x!=0)
result/=x;
else
{
display.setText("除数不能为0");
start=false;
flag=false;
return;
}
}
else if(lastCommand.equals("*")) result*=x;
else if(command.equals("1/x"))
{
if(x!=0)
result=1/x;
else
{
display.setText("除数不能为0");
start=false;
flag=false;
return;
}
}
else if(command.equals("sqrt"))
{
if(x=0)
result=Math.sqrt(x);
else
{
display.setText("函数输入无效");
start=false;
flag=false;
return;
}
}
else if(lastCommand.equals("=")) result=x;
display.setText(""+result);
}
private JButton display;
private JPanel panel;
private double result;
private String lastCommand;
private boolean start;
private boolean flag;
}
分记得给我啊!这是我自己编的!
vc计算器代码
/*
说明:
采用树形结构处理表达式,按优先级运算结果,一个加,减,乘,除或数值为一个节点
优先级如下:
函数:4
括号:3
乘除:2
加减:1
*/
#include windows.h
#include iostream
#include fstream
#include string
#include cmath
using namespace std;
const char NUM[]={'0','1','2','3','4','5','6','7','8','9','.'};
const char OPERATION[]={'+','-','*','/'};
const double PI=3.14159265358979;
const double EE=2.71828182818281;
class Fun //处理系统数学函数的类
{
public:
Fun(string o,int t,double l=0.0,double r=0.0):op(o),type(t),lvalue(l),rvalue(r){}
static string FUN[];
double calc();
private:
int type; //666 0 1 sin90 2 3! 3 3C2
string op; //函数类型
double lvalue; //函数左边的值
double rvalue; //函数右边的值
static int FunNum;
};
int Fun::FunNum=10;
string Fun::FUN[]={"!","sin","cos","tan","log","ln","C","A","^","-"};
/*
函数说明:
1:log是以10为底的工程对数
2:ln 是以e为底的自然对数
3:C 计算组合数 输入规则 如计算 3取2的组合 输入表达式 3C2
4:A 计算排列数 输入规则 如计算 3取2的排列 输入表达式 3A2
5:! 计算阶乘
6:^ x的y次方 输入 x^y
*/
int factorial(int n) //阶乘函数
{
int i,s=1;
for(i=1;i=n;i++)
s*=i;
return s;
}
int C(int a,int b)
{
return factorial(a)/(factorial(b)*factorial(a-b));
}
int A(int a,int b)
{
return factorial(a)/factorial(b);
}
double Fun::calc() //计算系统函数的值
{
if(type==0)
return lvalue;
else
{
if(op=="!")
return factorial(lvalue);
if(op=="sin")
return sin(rvalue/180*PI);
if(op=="cos")
return cos(rvalue/180*PI);
if(op=="tan")
return tan(rvalue/180*PI);
if(op=="log")
return log10(rvalue);
if(op=="ln")
return log10(rvalue)/log10(EE);
if(op=="C")
return C(lvalue,rvalue);
if(op=="A")
return A(lvalue,rvalue);
if(op=="^")
return pow(lvalue,rvalue);
if(op=="-")
return -rvalue;
else
{
string err="暂时没有函数"+op;
MessageBox(NULL,err.c_str(),"错误",MB_OK);
return 0;
}
}
}
struct Unit //双向链表保存运算单元
{
Unit(int p,char o,string c,double v,int t,Unit * pr=NULL,Unit * n=NULL)
:PRI(p),Operation(o),Code(c),value(v),Type(t),Pre(pr),Next(n){}
int PRI; //优先级
char Operation; //操作符
string Code; //原始代码
double value; //数据
int Type; //类型 操作符0 数据1 函数2
Unit * Pre; //构成双向链表
Unit * Next;
};
class Node //表达式树状结构的节点
{
public:
Node(char o,int p,int e=1,double v=0,Node * ph=NULL,Node * pl=NULL,Node * pr=NULL)
:Operation(o),PRI(p),Expression(e),value(v),Head(ph),Left(pl),Right(pr){}
Node * Head; //节点的根,左树枝,右树枝
Node * Left;
Node * Right;
double GetValue();
char GetOperation() const {return Operation;}
int GetPri() const {return PRI;}
int IsExp() const {return Expression;}
private:
char Operation; //操作符
int PRI; //优先级
int Expression; //记录该节点是否是表达式0 1
double value; //该节点的值
};
double Node::GetValue() //运算该节点的值
{
if(IsExp()) //该节点的值还未算出来
{
double lvalue,rvalue;
lvalue=Left-GetValue();
rvalue=Right-GetValue();
Expression=0;
char op=GetOperation();
switch(op)
{
case '+':
return lvalue+rvalue;
case '-':
return lvalue-rvalue;
case '*':
return lvalue*rvalue;
case '/':
return lvalue/rvalue;
default:
return 0;
}
}
else
return value;
}
bool Isnum(char c)
{
for(int i=0;isizeof(NUM);i++)
{
if(c==NUM[i])
return true;
}
return false;
}
bool Isoperation(char c)
{
for(int i=0;isizeof(OPERATION);i++)
{
if(c==OPERATION[i])
return true;
}
return false;
}
Unit * Analyse(string exp) //分析表达式并生成链表
{
int pri=0; //当前优先级
int stat=1; //当前的读入状态 括号 0 运算符 1 其他 2
Unit * head=NULL,* p=NULL;
int i=0,explen;
explen=exp.size();
for(i=0;iexplen;i++)
{
char c=exp.at(i);
if(c=='(')
{
pri+=3;
stat=0;
}
else if(c==')')
{
pri-=3;
stat=0;
}
else if(Isoperation(c) stat!=1) //操作符后的当正负号处理
{
stat=1;
Unit * temp=p;
int add_pri; //自身增加的优先级
if(c=='+' || c=='-')
add_pri=1;
else
add_pri=2;
p-Next=new Unit(pri+add_pri,c," ",0,0);
p=p-Next;
p-Pre=temp;
}
else //其他的当做函数处理
{
stat=2;
string function="";
while(iexplen (c=exp.at(i),! Isoperation(c)) c!=')')
{
function+=c;
i++;
}
i--;
if(head==NULL)
{
p=new Unit(pri,' ',function,0,2);
head=p;
}
else
{
Unit * temp=p;
p-Next=new Unit(pri,' ',function,0,2);
p=p-Next;
p-Pre=temp;
}
}
}
return head;
}
Unit * Calc(Unit * head) //计算双向链表基本单元的值
{
Unit * p=head;
while(p!=NULL)
{
if(p-Type!=0) //非操作符
{
string temp=p-Code;
string op;
double lvalue=0,rvalue=0;
int l_point=0,r_point=0;
int i=0,type=0;
char ch;
while(itemp.size() (ch=temp.at(i),Isnum(ch)))
{
if(ch=='.')
{
l_point++;
i++;
continue;
}
if(! l_point)
lvalue*=10;
lvalue+=(ch-'0')*pow(10,-l_point);
i++;
if(l_point)
l_point++;
}
while(itemp.size() (ch=temp.at(i),! Isnum(ch)))
{
op+=ch;
type=1;
i++;
}
while(itemp.size() (ch=temp.at(i),Isnum(ch)))
{
if(ch=='.')
{
r_point++;
i++;
continue;
}
if(! r_point)
rvalue*=10;
rvalue+=(ch-'0')*pow(10,-r_point);
i++;
if(r_point)
r_point++;
}
Fun * f=new Fun(op,type,lvalue,rvalue);
p-value=f-calc();
}
p=p-Next;
}
return head;
}
Node * Tree(Unit * head) //生成表达式树
{
Node * root=NULL,* proot=NULL,* pbranch=NULL;
Unit * p=head;
int now_pri; //当前优先级
bool hadop=false;
while(p!=NULL)
{
if(p-Type==0) //如果是一个操作符
{
hadop=true;
if(root==NULL)
{
proot=new Node(p-Operation,p-PRI,1);
root=proot;
pbranch=root;
now_pri=p-PRI;
proot-Left=new Node(' ',0,0,p-Pre-value);
proot-Right=new Node(' ',0,0,p-Next-value);
}
else
{
if(p-PRInow_pri) //优先级低于当前优先级,树根方向
{
proot=new Node(p-Operation,p-PRI,1); //新的树根
proot-Left=root; //根的变换
proot-Left-Head=proot;
proot-Right=new Node(' ',0,0,p-Next-value);
proot-Right-Head=proot;
root=proot;
pbranch=proot; //右树枝的变换
//pbranch-Right=new Node(' ',0,0,p-Pre-value); //树枝右边取值
}
else if(p-PRI==now_pri) //优先级相同,先算左边的
{
Node * temp;
temp=new Node(p-Operation,p-PRI,1);
temp-Left=pbranch;
if(pbranch-Head==NULL)
{
proot=temp;
root=proot;
pbranch-Head=proot;
}
else
{
Node * temp0;
temp0=pbranch-Head;
temp0-Right=temp;
temp-Head=temp0;
pbranch-Head=temp;
}
pbranch=temp;
pbranch-Right=new Node(' ',0,0,p-Next-value);
pbranch-Right-Head=pbranch;
}
else
{
Node * temp;
temp=new Node(p-Operation,p-PRI,1);
pbranch-Right=temp;
temp-Head=pbranch;
pbranch=pbranch-Right;
pbranch-Left=new Node(' ',0,0,p-Pre-value);
pbranch-Left-Head=pbranch;
pbranch-Right=new Node(' ',0,0,p-Next-value);
pbranch-Right-Head=pbranch;
}
now_pri=p-PRI;
}
}
p=p-Next;
}
if(! hadop)
root=new Node(' ',0,0,head-value);
return root;
}
int main()
{
string exp;
ifstream infile("test.txt",ios::in);
while(! getline(infile,exp).eof())
{
if(exp=="")
continue;
Unit * h=Analyse(exp);
h=Calc(h);
Node * root=Tree(h);
coutexp"="root-GetValue()endl;
}
return 0;
}
VC计算器的源代码
// jisuanqiDlg.cpp : implementation file
//
#include "stdafx.h"
#include "jisuanqi.h"
#include "jisuanqiDlg.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJisuanqiDlg dialog
CJisuanqiDlg::CJisuanqiDlg(CWnd* pParent )
: CDialog(CJisuanqiDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CJisuanqiDlg)
m_num = 0.0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);
}
void CJisuanqiDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CJisuanqiDlg)
DDX_Text(pDX, IDC_EDIT1, m_num);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CJisuanqiDlg, CDialog)
//{{AFX_MSG_MAP(CJisuanqiDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
ON_BN_CLICKED(IDC_BUTTON14, OnButton0)
ON_BN_CLICKED(IDC_BUTTON15, OnButtonPoint)
ON_BN_CLICKED(IDC_BUTTON16, OnButtonEqual)
ON_BN_CLICKED(IDC_BUTTON13, OnButtonChu)
ON_BN_CLICKED(IDC_BUTTON12, OnButtonMul)
ON_BN_CLICKED(IDC_BUTTON11, OnButtonSub)
ON_BN_CLICKED(IDC_BUTTON10, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON17, OnButtondelet)
ON_BN_CLICKED(IDC_BUTTON18, OnButtonclear)
ON_BN_CLICKED(IDC_BUTTON19, OnButtonkaifang)
ON_BN_CLICKED(IDC_BUTTON20, OnButtonziranduishu)
ON_BN_CLICKED(IDC_BUTTON21, OnButtonchangyongduishu)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJisuanqiDlg message handlers
BOOL CJisuanqiDlg::OnInitDialog()//初始化变量
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu-AppendMenu(MF_SEPARATOR);
pSysMenu-AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
t=true;
j=true;
i=10;
p=0;
q=0;
m_num=0;
m_lnum=0;
return TRUE; // return TRUE unless you set the focus to a control
}
void CJisuanqiDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CJisuanqiDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CJisuanqiDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CJisuanqiDlg::OnButton1()
{
// TODO: Add your control notification handler code here
if(t)
{
m_num=m_num*10+1;
UpdateData(FALSE);
}
else
{
m_num=m_num+1.0/i;
i*=10;
UpdateData(FALSE);
}
}
void CJisuanqiDlg::OnButton2()
{
// TODO: Add your control notification handler code here
if(t)
{
m_num=m_num*10+2;
UpdateData(FALSE);
}
else
{
m_num=m_num+2.0/i;
i*=10;
UpdateData(FALSE);
}
}
void CJisuanqiDlg::OnButton3()
{
// TODO: Add your control notification handler code here
if(t)
{
m_num=m_num*10+3;
UpdateData(FALSE);
}
else
{
m_num=m_num+3.0/i;
i*=10;
UpdateData(FALSE);
}
}
void CJisuanqiDlg::OnButton4()
{
// TODO: Add your control notification handler code here
if(t)
{
m_num=m_num*10+4;
UpdateData(FALSE);
}
else
{
m_num=m_num+4.0/i;
i*=10;
UpdateData(FALSE);
}
}
void CJisuanqiDlg::OnButton5()
{
// TODO: Add your control notification handler code here
if(t)
{
m_num=m_num*10+5;
UpdateData(FALSE);
}
else
{
m_num=m_num+5.0/i;
i*=10;
UpdateData(FALSE);
}
}
void CJisuanqiDlg::OnButton6()
{
// TODO: Add your control notification handler code here
if(t)
{
m_num=m_num*10+6;
UpdateData(FALSE);
}
else
{
m_num=m_num+6.0/i;
i*=10;
UpdateData(FALSE);
}
}
void CJisuanqiDlg::OnButton7()
{
// TODO: Add your control notification handler code here
if(t)
{
m_num=m_num*10+7;
UpdateData(FALSE);
}
else
{
m_num=m_num+7.0/i;
i*=10;
UpdateData(FALSE);
}
}
void CJisuanqiDlg::OnButton8()
{
// TODO: Add your control notification handler code here
if(t)
{
m_num=m_num*10+8;
UpdateData(FALSE);
}
else
{
m_num=m_num+8.0/i;
i*=10;
UpdateData(FALSE);
}
}
void CJisuanqiDlg::OnButton9()
{
// TODO: Add your control notification handler code here
if(t)
{
m_num=m_num*10+9;
UpdateData(FALSE);
}
else
{
m_num=m_num+9.0/i;
i*=10;
UpdateData(FALSE);
}
}
void CJisuanqiDlg::OnButton0()
{
// TODO: Add your control notification handler code here
//UpdateData();
if(t)
{
m_num=m_num*10+0;
UpdateData(FALSE);
}
else
{
m_num=m_num+0.0/i;
i*=10;
UpdateData(FALSE);
}
}
void CJisuanqiDlg::OnButtonPoint()
{
// TODO: Add your control notification handler code here
int i=10;
t=false;
}
void CJisuanqiDlg::OnButtonEqual()
{
// TODO: Add your control notification handler code here
switch(r)
{
case '+':
{
m_num=m_num+m_lnum;
UpdateData(FALSE);
break;
}
case '-':
{
m_num=m_snum-m_num;
UpdateData(FALSE);
break;
}
case '*':
{
m_num=m_mnum*m_num;
UpdateData(FALSE);
break;
}
case '/':
{
if(m_num==0)
{
MessageBox("除数不能是0!");
}
else
{
m_num=m_cnum/m_num;
UpdateData(FALSE);
break;
}
}
}
t=true;
}
void CJisuanqiDlg::OnButtonMul()
{
// TODO: Add your control notification handler code here
r='*';
t=true;
m_mnum=m_num;
m_num=0;
UpdateData(FALSE);
}
void CJisuanqiDlg::OnButtonChu()
{
// TODO: Add your control notification handler code here
r='/';
t=true;
i=10;
m_cnum=m_num;
m_num=0;
UpdateData(FALSE);
}
void CJisuanqiDlg::OnButtonSub()
{
// TODO: Add your control notification handler code here
r='-';
i=10;
t=true;
if(j)
{
m_snum=m_num;
}
else
{
p=0;
adda[p]=m_num;
p++;
for(q=0;q=p;q++)
{
m_lnum=m_lnum+adda[q];
q++;
}
m_num=m_lnum;
UpdateData(FALSE);
m_num=0;
m_snum=m_lnum;
}
m_num=0;
}
void CJisuanqiDlg::OnButtonAdd()
{
// TODO: Add your control notification handler code here
r='+';
t=true;
j=false;
i=10;
p=0;
adda[p]=m_num;
p++;
for(q=0;q=p;q++)
{
m_lnum=m_lnum+adda[q];
q++;
}
m_num=m_lnum;
UpdateData(FALSE);
m_num=0;
}
void CJisuanqiDlg::OnButtondelet()
{
// TODO: Add your control notification handler code here
int p;
p=m_num/10;
m_num=p;
UpdateData(FALSE);
}
void CJisuanqiDlg::OnButtonclear()
{
// TODO: Add your control notification handler code here
t=true;
i=10;
j=true;
m_num=0;
m_lnum=0;
UpdateData(FALSE);
}
void CJisuanqiDlg::OnButtonkaifang()
{
// TODO: Add your control notification handler code here
m_num=sqrt(m_num);
UpdateData(FALSE);
}
void CJisuanqiDlg::OnButtonziranduishu()
{
// TODO: Add your control notification handler code here
m_num=log(m_num);
UpdateData(FALSE);
}
void CJisuanqiDlg::OnButtonchangyongduishu()
{
// TODO: Add your control notification handler code here
m_num=log10(m_num);
UpdateData(FALSE);
}
c语言贷款计算器的源程序
/*
* main.c
*
* Created on: 2011-6-8
* Author: icelights
*/
#include stdio.h
#include stdlib.h
#include ctype.h
#include math.h
#define APR1 0.0747 /*1年(含1年)年利率*/
#define APR2 0.0756 /*1-3年(含3年)年利率*/
#define APR3 0.0774 /*3-5年(含5年)年利率*/
#define APR4 0.0783 /*5年以上年利率*/
#define A_TO_M 1/12 /*月利率 = 年利率 / 12*/
#define RTP 12 /*Reimbursement total periods还款总期数 =年限*12*/
#define LENGTH 80
struct LoanInfo
{
/*姓名*/
char name[LENGTH];
/*贷款总额*/
double LoanAmount;
/*贷款年限*/
double LoanYear;
/*月付*/
double MonthlyPayment;
/*总利息*/
double TotalInterest;
/*还款总额*/
double ReimbursementAmount;
/*年利率*/
double apr;
struct LoanInfo * next;
};
void CalcShow(struct LoanInfo * cur, struct LoanInfo * hd,
struct LoanInfo * prv);
int main(void)
{
int temp;
struct LoanInfo * head = NULL;
struct LoanInfo * prev, * current;
current = (struct LoanInfo *)malloc(sizeof(struct LoanInfo));
if (NULL == head)
{
head = current;
}
else
{
prev-next = current;
}/*End of if (NULL == head)*/
puts("请输入姓名");
gets(current-name);
fflush(stdin);
puts("请输入贷款数额(单位:万元)");
scanf("%lf", ¤t-LoanAmount);
fflush(stdin);
puts("请输入贷款年限");
scanf("%lf", ¤t-LoanYear);
fflush(stdin);
printf("姓名:%s,贷款年限:%lf, 贷款数额%lf",
current-name, current-LoanYear, current-LoanAmount);
prev = current;
puts("请确认Y/N");
temp = getchar();
switch(toupper(temp))
{
case 'Y' : CalcShow(current, head, prev);
break;
case 'N' : free(current);
main();
break;
default : puts("输入错误");
free(current);
break;
}
return 0;
}
void CalcShow(struct LoanInfo * cur, struct LoanInfo * hd,
struct LoanInfo * prv)
{
char lcv_temp;
if (cur-LoanYear = 1)
cur-apr = APR1;
else if (cur-LoanYear = 3)
cur-apr = APR2;
else if (cur-LoanYear = 5)
cur-apr = APR3;
else
cur-apr = APR4;
/*End of if (year = 1)*/
cur-LoanAmount = 10000 * cur-LoanAmount;
cur-ReimbursementAmount = cur-LoanAmount * pow((1 + cur-apr), cur-LoanYear);
cur-MonthlyPayment = cur-ReimbursementAmount / (cur-LoanYear * RTP);
cur-TotalInterest = cur-ReimbursementAmount - cur-LoanAmount;
printf("姓名:%s 贷款年限:%.0lf\n"
"贷款数额:%.2lf 每月还款额:%.2lf\n"
"利息合计:%.2lf 还款总额:%.2lf\n",
cur-name, cur-LoanYear, cur-LoanAmount,
cur-MonthlyPayment, cur-TotalInterest, cur-ReimbursementAmount);
puts("是否继续计算Y/N");
lcv_temp = getchar();
switch(toupper(lcv_temp))
{
case 'Y' : free(cur);
main();
break;
case 'N' : free(cur);
exit(0);
default : puts("输入错误");
free(cur);
main();
break;
}
system("pause");
}
C#计算器源代码
namespace jisuanji
{
public partial class jisuanqi : Form
{
public jisuanqi()
{
InitializeComponent();
}
private void jisuanqi_Load(object sender, EventArgs e)
{
txtMath.Text = "0.0";
}
//存放输入的数字
private string str1 = "";
//存放第二个数字
private string str2 = "";
//存放执行的什么操作 如:+,-,*,/
private string action = "";
//判断是否点击了“=”,默认是没有点击
private bool Equal_flag = false;
private void check(Button btnname)
{
if (action.Equals(""))
{
if (txtMath.Text != "0" || txtMath.Text != "0.0")
{
str1 += btnname.Text;
txtMath.Text = str1.ToString();
}
//如果是第一次输入数字
if (txtMath.Text.Equals("0.0") || txtMath.Text.Equals("0"))
{
txtMath.Text = btnname.Text;
str1 = btnname.Text.ToString();
}
}
//如果已经输入了数字且没有点击“=”
if(!action.Equals("") txtMath.Text.Length != 0 (!txtMath.Text.Equals("0.0")) (!txtMath.Text.Equals("0")))
{
str2 += btnname.Text;
txtMath.Text += btnname.Text;
}
//如果已经输入了数字并执行了加减乘除的操作,第二个数字输入时
else if ((!action.Equals("")) txtMath.Text.Length != 0 !txtMath.Text.Equals(0.0) (!txtMath.Text.Equals("0")))
{
txtMath.Text += btnname.Text;
//str2 = txtMath.Text.ToString();
str2 += btnname.Text;
}
else if (txtMath.Text.Equals("") (!action.Equals("")))
{
txtMath.Text += btnname.Text;
str2 = txtMath.Text;
}
}
private void btnZero_Click(object sender, EventArgs e)
{
if (Equal_flag)
{
//如果没有点击“+-*/”
if (action.Equals(""))
{
if (str1.Equals(""))
{
MessageBox.Show("您的操作有误", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
check(btnZero);
}
else
{
check(btnZero);
Equal_flag = false;
}
}
private void btnDot_Click(object sender, EventArgs e)
{
//点击过等号
if (Equal_flag)
{
//第二个数字没有输入的时候
if (str2.Equals(""))
{
//第一个数字已经有点号存在
if (str1.IndexOf('.') -1)
{
MessageBox.Show("您的操作有误", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtMath.Text = str1;
return;
}
check(btnDot);
}
//第二个数字输入了的时候
else
{
//第二个数字中不存在点号的时候
if (!(str2.IndexOf('.') -1))
{
check(btnDot);
return;
}
//第二个数字中存在点号的时候
MessageBox.Show("您的操作有误", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
//没有点击过等号
else
{
//第一个数字存在点号
if (str1.IndexOf('.') -1)
{
MessageBox.Show("您的操作有误", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtMath.Text = str1;
return;
}
//第一个数字不存在点号的时候
else
{
//如果第一个数字还是空的时候
if (!str1.Equals(""))
{
check(btnDot);
//Equal_flag = false;
return;
}
txtMath.Text = "0" + btnDot.Text;
str1 = txtMath.Text;
}
}
}
private void btnOne_Click(object sender, EventArgs e)
{
if (Equal_flag)
{
if (!str1.Equals(""))
{
if (action.Equals(""))
{
MessageBox.Show("请选择运算符", "信息提示");
return;
}
}
check(btnOne);
}
else
{
check(btnOne);
Equal_flag = false;
}
}
private void btnTwo_Click(object sender, EventArgs e)
{
if (Equal_flag)
{
if (!str1.Equals(""))
{
if (action.Equals(""))
{
MessageBox.Show("请选择运算符", "信息提示");
return;
}
}
check(btnTwo);
}
else
{
check(btnTwo);
Equal_flag = false;
}
}
private void btnthree_Click(object sender, EventArgs e)
{
if (Equal_flag)
{
if (!str1.Equals(""))
{
if (action.Equals(""))
{
MessageBox.Show("请选择运算符", "信息提示");
return;
}
}
check(btnthree);
}
else
{
check(btnthree);
Equal_flag = false;
}
}
private void btnFour_Click(object sender, EventArgs e)
{
if (Equal_flag)
{
if (action.Equals(""))
{
MessageBox.Show("请选择运算符", "信息提示");
return;
}
check(btnFour);
}
else
{
check(btnFour);
Equal_flag = false;
}
}
private void btnFive_Click(object sender, EventArgs e)
{
if (Equal_flag)
{
if (!str1.Equals(""))
{
if (action.Equals(""))
{
MessageBox.Show("请选择运算符", "信息提示");
return;
}
}
check(btnFive);
}
else
{
check(btnFive);
Equal_flag = false;
}
}
private void btnSix_Click(object sender, EventArgs e)
{
if (Equal_flag)
{
if (!str1.Equals(""))
{
if (action.Equals(""))
{
MessageBox.Show("请选择运算符", "信息提示");
return;
}
}
check(btnSix);
}
else
{
check(btnSix);
Equal_flag = false;
}
}
private void btnSeven_Click(object sender, EventArgs e)
{
if (Equal_flag)
{
if (!str1.Equals(""))
{
if (action.Equals(""))
{
MessageBox.Show("请选择运算符", "信息提示");
return;
}
}
check(btnSeven);
}
else
{
check(btnSeven);
Equal_flag = false;
}
}
private void btnEight_Click(object sender, EventArgs e)
{
if (Equal_flag)
{
if (!str1.Equals(""))
{
if (action.Equals(""))
{
MessageBox.Show("请选择运算符", "信息提示");
return;
}
}
check(btnEight);
}
else
{
check(btnEight);
Equal_flag = false;
}
}
private void btnNine_Click(object sender, EventArgs e)
{
if (Equal_flag)
{
if (!str1.Equals(""))
{
if (action.Equals(""))
{
MessageBox.Show("请选择运算符", "信息提示");
return;
}
}
check(btnNine);
}
else
{
check(btnNine);
Equal_flag = false;
}
}
private void btnQual_Click(object sender, EventArgs e)
{
str_check(btnQual);
str2 = "";
Equal_flag = true;
action = "";
}
private string calcute(string str1, string str2, string action)
{
switch (action)
{
case "+":
str1 = (double.Parse(str1) + double.Parse(str2)).ToString();
return str1;
case "-":
str1 = (double.Parse(str1) - double.Parse(str2)).ToString();
return str1;
case "*":
str1 = (double.Parse(str1) * double.Parse(str2)).ToString();
return str1;
case "/":
if (str2.Equals("0.0") || str2.Equals("0"))
{
MessageBox.Show("被除数不能为0", "警告");
return str1;
}
str1 = (double.Parse(str1) / double.Parse(str2)).ToString();
return str1;
default :
MessageBox.Show("操作错误!", "提示");
return "wrong";
}
}
private void str_check(Button btnname)
{
//完成上一次计算后点击运算按钮应将结果作为第一个数
if (Equal_flag)
{
//第二个数还没输入的时候
if ((!str1.Equals("")) (str2.Equals("")))
{
if (!(btnname.Text.IndexOf('=') -1))
{
action = btnname.Text;
txtMath.Text += btnname.Text;
}
}
//两个都不为空,第二个数已经输入,应将他们进行运算
if ((!str1.Equals("")) (!str2.Equals("")))
{
str1 = calcute(str1, str2, action);
txtMath.Text = str1.ToString();
}
//直接点击操作错误
else if (str1.Equals(""))
{
MessageBox.Show("请输入要进行运算的数字", "信息提示");
}
}
//没有点击“=”
else if (!Equal_flag)
{
//第二个数还没输入的时候
if ((!str1.Equals("")) (str2.Equals("")))
{
if (!(btnname.Text.IndexOf('=') -1))
{
action = btnname.Text;
txtMath.Text += btnname.Text;
}
}
//两个都不为空,第二个数已经输入,应将他们进行运算
if ((!str1.Equals("")) (!str2.Equals("")))
{
str1 = calcute(str1, str2, action);
txtMath.Text = str1.ToString();
}
//直接点击操作错误
else if (str1.Equals(""))
{
MessageBox.Show("请输入要进行运算的数字", "信息提示");
}
}
}
private void btnPlus_Click(object sender, EventArgs e)
{
str_check(btnPlus);
}
private void btnMinus_Click(object sender, EventArgs e)
{
str_check(btnMinus);
}
private void btnTimes_Click(object sender, EventArgs e)
{
str_check(btnTimes);
}
private void btnDivide_Click(object sender, EventArgs e)
{
str_check(btnDivide);
}
private void btnRest_Click(object sender, EventArgs e)
{
txtMath.Text = "0.0";
str1 = str2 = "";
action = "";
Equal_flag = false;
}
}
}
求一个 java 个人贷款还款计算器 的源代码,
import javax.swing.JOptionPane;
public class Pay {
public static void main(String args[]){
String loanString = JOptionPane.showInputDialog("请输入贷款本金( loanAmout):such as 20000.00") ;
double loanAmount= Double.parseDouble(loanString);
String dateString = JOptionPane.showInputDialog("请输入贷款期(loanDate):between 24-60");
int loanDate = Integer.parseInt(dateString);
String monthRateString = JOptionPane.showInputDialog("请输入月利率 (MonthRate):such as 0.00005");
double monthRate = Double.parseDouble(monthRateString);
double pay_Per_Month = (loanAmount+loanAmount * loanDate * monthRate)/loanDate;
JOptionPane.showMessageDialog(null, pay_Per_Month);
}
}
关于借贷计算器源代码和贷款计算器源码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
- 上一篇:安卓QQ侧栏代码(安卓侧栏代码大全)
- 下一篇:3d打印开源代码(3D打印代码)
相关推荐
- 04-29房天下源代码(房产系统源码)[20240429更新]
- 04-29网上书店网站源代码(网上书店html代码)[20240429更新]
- 04-29php学生管理系统源代码(php学生成绩管理系统源代码)[20240429更新]
- 04-29跑得快源代码(跑得快h5源码)[20240429更新]
- 04-29网站论坛源代码(论坛 源代码)[20240429更新]
- 04-29delphiaccess源代码(delphi createprocess)[20240429更新]
- 04-29java无参计算器代码(JAVA计算器代码)[20240429更新]
- 04-29web网页制作源代码(制作网页的代码)[20240429更新]
- 04-29关于crpg跳跃源代码的信息[20240429更新]
- 04-29.net小程序设计源代码(小程序开发代码大全)[20240429更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接