Skip to content

Commit 81c61e7

Browse files
committed
参数估计 最小二乘法 与 曲线拟合 最小二乘法 有什么区别
参数估计 最小二乘法 与 曲线拟合 最小二乘法 有什么区别 这里先 标记 参数估计 最大似然估计 数学原理。。。。
1 parent d0bb3c0 commit 81c61e7

39 files changed

+4079
-3
lines changed

C2U.cpp

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
//
2+
// C2U.cpp
3+
// CPPB20180806
4+
//
5+
// Created by admindyn on 2018/8/16.
6+
// Copyright © 2018年 admindyn. All rights reserved.
7+
//
8+
9+
#include "C2U.hpp"
10+
11+
12+
13+
//
14+
// CU.cpp
15+
// CPPB20180806
16+
//
17+
// Created by admindyn on 2018/8/7.
18+
// Copyright © 2018年 admindyn. All rights reserved.
19+
//
20+
21+
22+
#include <new>
23+
#include "illegalParameterValue.hpp"
24+
25+
26+
27+
28+
C2U::C2U(signType theSign,unsigned long theDollars,unsigned int theCents)
29+
{
30+
//创建一个Currency 类对象
31+
setValue(theSign, theDollars, theCents);
32+
}
33+
34+
void C2U::setValue(signType theSign, unsigned long theDollars, unsigned int theCents)
35+
{
36+
//给调用对象的数据成员赋值
37+
if (theCents>99) {
38+
throw illegalParameterValue("Cents should be < 100");
39+
}
40+
41+
amount = theDollars*100+theCents;
42+
43+
if (theSign==minusv) {
44+
amount=-amount;
45+
}
46+
47+
48+
49+
}
50+
51+
void C2U::setValue(double theAmount)
52+
{
53+
//给调用对象的数据成员赋值
54+
55+
56+
//提取整数部分
57+
/*
58+
59+
数据类型 向下转型
60+
61+
大内存空间 double 到 unsigned long
62+
63+
float 到 int
64+
65+
数组指针 首地址 可以 转为首元素指针 首元素地址
66+
67+
子类 向父类转型
68+
69+
*/
70+
71+
72+
if (theAmount<0) {
73+
amount=(long)((theAmount-0.001)*100);
74+
}else
75+
{
76+
amount=(long)((theAmount-0.001)*100);
77+
}
78+
79+
80+
81+
}
82+
83+
signType C2U::getSign()const
84+
{
85+
if (amount<0) {
86+
return minusv;
87+
}else{
88+
return plusv;
89+
}
90+
}
91+
92+
unsigned long C2U::getDollars()const
93+
{
94+
if (amount<0) {
95+
return (-amount)/100;
96+
}else
97+
{
98+
return amount/100;
99+
}
100+
101+
}
102+
103+
unsigned int C2U::getCents()const
104+
{
105+
if (amount<0) {
106+
return -amount-getDollars()*100;
107+
}else
108+
{
109+
return amount-getDollars()*100;
110+
}
111+
}
112+
113+
/*
114+
操作符重载
115+
*/
116+
117+
C2U C2U::operator+(const C2U &x) const
118+
{
119+
/*把参数对象x和调用对象*this相加*/
120+
C2U result;
121+
result.amount = amount + x.amount;
122+
return result;
123+
}
124+
125+
C2U& C2U::operator+=(const C2U &x)
126+
{
127+
amount =amount + x.amount;
128+
129+
return *this;
130+
}
131+
/*这里对流插入操作符 也是重载 但是没有作为成员函数重载而已 但是即便修改也是作为 友元函数重载*/
132+
ostream& operator<<(ostream&out,const C2U&x)
133+
{
134+
x.output(out);
135+
136+
return out;
137+
}
138+
139+
/**/
140+
void C2U::output(ostream&out)const
141+
{
142+
long theAmount = amount;
143+
144+
if (theAmount<0) {
145+
out<<"-";
146+
theAmount = - theAmount;
147+
}
148+
long dollars = theAmount/100;//美元
149+
150+
out<<"$"<<dollars<<".";
151+
152+
int cents = theAmount-dollars*100;//美分
153+
if (cents<10) {
154+
out<<"0";
155+
}
156+
out<<cents;
157+
}
158+
159+
160+
C2U::~C2U()
161+
{
162+
163+
}
164+
165+
166+
167+
168+
169+
170+
171+
172+

C2U.hpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// C2U.hpp
3+
// CPPB20180806
4+
//
5+
// Created by admindyn on 2018/8/16.
6+
// Copyright © 2018年 admindyn. All rights reserved.
7+
//
8+
9+
#ifndef C2U_hpp
10+
#define C2U_hpp
11+
#include "ENUMTYPE.hpp"
12+
#include <iostream>
13+
#include <stdio.h>
14+
using namespace std;
15+
/*
16+
对现有类实现操作符重载
17+
18+
实现+ +=操作符重载 并定义为成员函数
19+
20+
实现<<流插入操作符 但未定义为成员函数
21+
22+
但是添加成员函数output 成员函数 辅助对<<流插入操作符的使用
23+
24+
因为 非成员函数不能访问类实例对象的私有成员
25+
*/
26+
class C2U {
27+
28+
29+
public:
30+
//构造函数
31+
C2U(signType theSign = plusv,unsigned long theDollars = 0,unsigned int theCents=0);
32+
//析构函数
33+
~C2U();
34+
35+
void setValue(signType,unsigned long,unsigned int);
36+
37+
void setValue(double);
38+
39+
signType getSign() const;
40+
41+
42+
unsigned long getDollars() const;
43+
44+
unsigned int getCents() const;
45+
46+
C2U operator+(const C2U&) const;
47+
48+
C2U& operator+=(const C2U&);
49+
50+
void output(ostream&) const;
51+
52+
private:
53+
long amount;
54+
55+
};
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
#endif /* C2U_hpp */

0 commit comments

Comments
 (0)