结对2.03

#include<stdio.h>

#include <math.h>

#include<stdlib.h>

void fuli(){

    double F,P,I;

    int M,N;

    system("cls");

    printf(" 欢迎进入复利计算软件 ");

    printf("请输入存入本金:");

    scanf("%lf",&P);

    printf("请输入年利率:");

    scanf("%lf",&I);

    printf("请输入存入年限:");

    scanf("%d",&N);

    printf("请输入年复利次数:");

    scanf("%d",&M);

    printf("本金 年利率 存入年限 年复利次数 ");

    printf("%.2lf %.2lf %d %d",P,I,N,M);

    I=pow((1+I/M),M)-1;

    F=P*pow((1+I),N);

    printf(" 输出复利终值结果:%.2lf ",F);

}

void danli()

{

    

    double F,P,I;

    int N;

    system("cls");

    printf(" 欢迎进入单利计算软件 ");

    printf("请输入存入本金:");

    scanf("%lf",&P);

    printf("请输入年利率:");

    scanf("%lf",&I);

    printf("请输入存入年限:");

    scanf("%d",&N);

    printf("本金 年利率 存入年限 ");

    printf("%.2lf %.2lf %d ",P,I,N);

    F=P+P*I*N;

    printf(" 输出复利终值结果:%.2lf ",F);

}

void benjin()

{

    double F,P,I;

    int M,N;

    system("cls");

    printf(" 欢迎进入本金计算软件 ");

    printf("请输入终值:");

    scanf("%lf",&F);

    printf("请输入年利率:");

    scanf("%lf",&I);

    printf("请输入存入年限:");

    scanf("%d",&N);

    printf("请输入年复利次数:");

    scanf("%d",&M);

    printf("终值 年利率 存入年限 年复利次数 ");

    printf("%.2lf %.2lf %d %d",F,I,N,M);

    I=pow((1+I/M),M)-1;

    P=F/pow((1+I),N);

    printf(" 输出本金结果:%.2lf ",P);

}

void nianfen()

{

    double F,P,I,N;

    int M;

    system("cls");

    printf(" 欢迎进入投资年限计算软件 ");

    printf("请输入终值:");

    scanf("%lf",&F);

    printf("请输入年利率:");

    scanf("%lf",&I);

    printf("请输入本金:");

    scanf("%lf",&P);

    printf("请输入年复利次数:");

    scanf("%d",&M);

    printf("终值 年利率 本金 年复利次数 ");

    printf("%.2lf %.2lf %.2lf %d",F,I,P,M);

    I=pow((1+I/M),M)-1;

    N=log(F/P)/log(1+I);

    printf(" 输出投资年限估计:%lf ",N);

}

package fuli;

import java.sql.*;

public class mysql  {

    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";

    static final String DB_URL = "jdbc:mysql://localhost/test";

    static final String USER = "root";

    static final String PASS = "root";

    int i=1;

    double output(String gongsi,String putinto,String earnings,String year,String money) throws SQLException{

        Connection conn = null;

        Statement stmt = null;

         

        //STEP 2: Register JDBC driver

        try {

            Class.forName(JDBC_DRIVER);

        } catch (ClassNotFoundException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

        //STEP 3: Open a connection

        conn = DriverManager.getConnection(DB_URL,USER,PASS);

         

        //STEP 4: Execute a query

        stmt = conn.createStatement();

         

        String sql;

        sql = "SELECT * FROM touzi";

        ResultSet rs = stmt.executeQuery(sql);

         

        int r=1;

        double sum=0;

        //STEP 5: Extract data from result set

          while(null != rs && rs.next()){

             System.out.println(rs.getString("putinto"));

             System.out.println(rs.getString("earnings"));

             System.out.println(rs.getString("number"));

              

             System.out.println();

             r++;

             sum=Double.parseDouble(rs.getString("money"))+sum;

        }   

         

        String I = Integer.toString(i);

        String sql1 = "INSERT INTO touzi(number,gongsi,putinto,earnings,year,money) VALUES(";

        sql1=sql1+"'"+I+"'"+','+"'"+gongsi+"'"+','+"'"+putinto+"'"+','+"'"+earnings+"'"+','+"'"+year+"'"+','+"'"+money+"'"+')';

        

        i++;

        

        System.out.print(sql1);

        stmt.executeUpdate(sql1);

         

        rs.close();

        stmt.close();

        conn.close();

        return sum;

    }

     

void lilv()

{

    double F,P,I;

    int M,N;

    system("cls");

    printf(" 欢迎进入投资项目利率计算软件 ");

    printf("请输入终值:");

    scanf("%lf",&F);

    printf("请输入本金:");

    scanf("%lf",&P);

    printf("请输入存入年限:");

    scanf("%d",&N);

    printf("请输入年复利次数:");

    scanf("%d",&M);

    printf("终值 本金 存入年限 年复利次数 ");

    printf("%.2lf %.2lf %d %d",F,P,N,M);

    I=pow(pow(F/P,1.0/N),1.0/M)*M-M;

    printf(" 输出投资项目利率:%lf ",I);

}

void dingqi(){

    double F,P,I;

    int N;

    system("cls");

    printf(" 欢迎进入定期投资软件 ");

    printf("请输入年投入:");

    scanf("%lf",&P);

    printf("请输入年复合增长率:");

    scanf("%lf",&I);

    printf("请输入持续投入年数:");

    scanf("%d",&N);

    printf("年投入 年复合增长率 持续投入年数 ");

    printf("%.2lf %.2lf %d ",P,I,N);

    F=P*(1+I)*pow((1+I),N-1)/I;

    printf(" 输出结果:%.2lf ",F);

}

main()

{

    int i;

    printf(" 欢迎进入单复利计算软件3.0 ");

    printf(" 1.单利计算");

    printf(" 2.复利计算");

    printf(" 3.求本金");

    printf(" 4.求投资年限");

    printf(" 5.求投资项目利率估计");

    printf(" 6.定期投资");

    printf(" 请输出选择项:");

    scanf("%d",&i);

    switch(i)

    {

    case 1:

        danli();

        break;

    case 2:

        fuli();

        break;

    case 3:

        benjin();

        break;

    case 4:

        nianfen();

        break;

    case 5:

        lilv();

        break;

    case 6:

        dingqi();

        break;

    default:

        return 0;

    }

}

原文地址:https://www.cnblogs.com/wenting/p/5393449.html