这波肝出CASIO计算器
2026-08-11 17:11:57
发布于:广东
我写了3个多小时,检查了5遍才来(谁检查的就不说了hhh)
点一个宝贵的赞,加油💪
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1);
double ans=0;
bool hasans=false;
void guanji(){
cout<<"CASIO,boost your curiosity"<<endl;
exit(0);
}
double jia(double a,double b){
return a+b;
}
double jian(double a,double b){
return a-b;
}
double cheng(double a,double b){
return a*b;
}
double chu(double a,double b){
if(b==0){
cout<<"错误:除数不能为0"<<endl;
return 0;
}
return a/b;
}
double quyu(int a,int b){
if(b==0){
cout<<"错误:除数不能为0"<<endl;
return 0;
}
return a%b;
}
double cimi(double a,double b){
return pow(a,b);
}
double genhao(double a){
if(a<0){
cout<<"错误:负数不能开平方根"<<endl;
return 0;
}
return sqrt(a);
}
double jueduizhi(double a){
return fabs(a);
}
double zhishu(double a){
return exp(a);
}
double duishu(double a){
if(a<=0){
cout<<"错误:对数真数必须大于0"<<endl;
return 0;
}
return log(a);
}
double changyongduishu(double a){
if(a<=0){
cout<<"错误:对数真数必须大于0"<<endl;
return 0;
}
return log10(a);
}
double zhengxian(double a){
return sin(a);
}
double yuxian(double a){
return cos(a);
}
double zhengqie(double a){
return tan(a);
}
double yvqie(double a){
double t=tan(a);
if(t==0){
cout<<"错误:余切值不存在"<<endl;
return 0;
}
return 1/t;
}
double shuzuqiuhe(double a[],int n){
double s=0;
for(int i=0;i<n;i++){
s+=a[i];
}
return s;
}
double dengchaqiuhe(long long n){
return n*(n+1)/2;
}
double hanshuqiuhe(double (*f)(int),int l,int r){
double s=0;
for(int i=l;i<=r;i++){
s+=f(i);
}
return s;
}
double jvxingjifen(double (*f)(double),double a,double b,int n){
double h=(b-a)/n;
double s=0;
for(int i=0;i<n;i++){
s+=f(a+i*h);
}
return s*h;
}
double tixingjifen(double (*f)(double),double a,double b,int n){
double h=(b-a)/n;
double s=(f(a)+f(b))/2;
for(int i=1;i<n;i++){
s+=f(a+i*h);
}
return s*h;
}
double xinpusenji(double (*f)(double),double a,double b){
double mid=(a+b)/2;
return (b-a)/6*(f(a)+4*f(mid)+f(b));
}
double zishiyingxinpusen(double (*f)(double),double a,double b,double eps){
double mid=(a+b)/2;
double s1=xinpusenji(f,a,b);
double s2=xinpusenji(f,a,mid)+xinpusenji(f,mid,b);
if(fabs(s1-s2)<eps){
return s2;
}
return zishiyingxinpusen(f,a,mid,eps/2)+zishiyingxinpusen(f,mid,b,eps/2);
}
double zhongxinqiudao(double (*f)(double),double x,double h){
return (f(x+h)-f(x-h))/(2*h);
}
double qianxiangqiudao(double (*f)(double),double x,double h){
return (f(x+h)-f(x))/h;
}
double houxiangqiudao(double (*f)(double),double x,double h){
return (f(x)-f(x-h))/h;
}
struct fushu{
double shi;
double xu;
};
fushu fushujia(fushu a,fushu b){
fushu r;
r.shi=a.shi+b.shi;
r.xu=a.xu+b.xu;
return r;
}
fushu fushujian(fushu a,fushu b){
fushu r;
r.shi=a.shi-b.shi;
r.xu=a.xu-b.xu;
return r;
}
fushu fushucheng(fushu a,fushu b){
fushu r;
r.shi=a.shi*b.shi-a.xu*b.xu;
r.xu=a.shi*b.xu+a.xu*b.shi;
return r;
}
fushu fushuchu(fushu a,fushu b){
fushu r;
double mo=b.shi*b.shi+b.xu*b.xu;
if(mo==0){
cout<<"错误:复数除数为0"<<endl;
r.shi=0;
r.xu=0;
return r;
}
r.shi=(a.shi*b.shi+a.xu*b.xu)/mo;
r.xu=(a.xu*b.shi-a.shi*b.xu)/mo;
return r;
}
double fushumo(fushu a){
return sqrt(a.shi*a.shi+a.xu*a.xu);
}
void shuchufushu(fushu a){
if(a.xu>=0){
cout<<a.shi<<"+"<<a.xu<<"i"<<endl;
}
else{
cout<<a.shi<<a.xu<<"i"<<endl;
}
}
double ercifangcheng(double a,double b,double c,double &x1,double &x2,int &type){
if(a==0){
if(b==0){
if(c==0){
type=3;
return 0;
}
else{
type=0;
return 0;
}
}
else{
x1=-c/b;
type=1;
return 0;
}
}
double delta=b*b-4*a*c;
if(delta>0){
x1=(-b+sqrt(delta))/(2*a);
x2=(-b-sqrt(delta))/(2*a);
type=2;
}
else if(delta==0){
x1=-b/(2*a);
type=1;
}
else{
x1=-b/(2*a);
x2=sqrt(-delta)/(2*a);
type=-2;
}
return 0;
}
void jieercifangcheng(){
double a,b,c,x1,x2;
int type;
cout<<"输入a b c (ax^2+bx+c=0): ";
cin>>a>>b>>c;
ercifangcheng(a,b,c,x1,x2,type);
if(type==0){
cout<<"无解"<<endl;
}
else if(type==1){
cout<<"x="<<x1<<endl;
ans=x1;
hasans=true;
}
else if(type==2){
cout<<"x1="<<x1<<", x2="<<x2<<endl;
ans=x1;
hasans=true;
}
else if(type==3){
cout<<"无穷多解"<<endl;
}
else if(type==-2){
cout<<"x1="<<x1<<"+"<<x2<<"i, x2="<<x1<<"-"<<x2<<"i"<<endl;
fushu tmp;
tmp.shi=x1;
tmp.xu=x2;
ans=x1;
hasans=true;
}
}
void jiesancifangcheng(){
double a,b,c,d;
cout<<"输入a b c d (ax^3+bx^2+cx+d=0): ";
cin>>a>>b>>c>>d;
if(a==0){
double x1,x2;
int type;
ercifangcheng(b,c,d,x1,x2,type);
if(type==1){
cout<<"x="<<x1<<endl;
ans=x1;
hasans=true;
}
else if(type==2){
cout<<"x1="<<x1<<", x2="<<x2<<endl;
ans=x1;
hasans=true;
}
else if(type==-2){
cout<<"x1="<<x1<<"+"<<x2<<"i, x2="<<x1<<"-"<<x2<<"i"<<endl;
ans=x1;
hasans=true;
}
return;
}
double p=(3*a*c-b*b)/(3*a*a);
double q=(2*b*b*b-9*a*b*c+27*a*a*d)/(27*a*a*a);
double delta=q*q/4+p*p*p/27;
double u,v;
if(delta>=0){
double tmp1=-q/2+sqrt(delta);
double tmp2=-q/2-sqrt(delta);
if(tmp1>=0){
u=pow(tmp1,1.0/3);
}
else{
u=-pow(-tmp1,1.0/3);
}
if(tmp2>=0){
v=pow(tmp2,1.0/3);
}
else{
v=-pow(-tmp2,1.0/3);
}
double x1=u+v-b/(3*a);
cout<<"x1="<<x1<<endl;
ans=x1;
hasans=true;
double disc=pow(u-v,2)+3*pow(u+v,2);
if(disc<0){
double shi=-(u+v)/2-b/(3*a);
double xu=sqrt(-disc)/2;
cout<<"x2="<<shi<<"+"<<xu<<"i, x3="<<shi<<"-"<<xu<<"i"<<endl;
}
else{
double x2=-(u+v)/2+sqrt(disc)/2-b/(3*a);
double x3=-(u+v)/2-sqrt(disc)/2-b/(3*a);
cout<<"x2="<<x2<<", x3="<<x3<<endl;
}
}
else{
double r=sqrt(-p*p*p/27);
double theta=acos(-q/(2*r));
double x1=2*pow(r,1.0/3)*cos(theta/3)-b/(3*a);
double x2=2*pow(r,1.0/3)*cos((theta+2*pi)/3)-b/(3*a);
double x3=2*pow(r,1.0/3)*cos((theta+4*pi)/3)-b/(3*a);
cout<<"x1="<<x1<<", x2="<<x2<<", x3="<<x3<<endl;
ans=x1;
hasans=true;
}
}
void jiexianxingfangcheng(){
int n;
cout<<"输入未知数个数(2或3): ";
cin>>n;
if(n==2){
double a[2][3];
cout<<"输入增广矩阵(2行3列): "<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<3;j++){
cin>>a[i][j];
}
}
double det=a[0][0]*a[1][1]-a[0][1]*a[1][0];
if(det==0){
cout<<"方程组无唯一解"<<endl;
}
else{
double x1=(a[0][2]*a[1][1]-a[0][1]*a[1][2])/det;
double x2=(a[0][0]*a[1][2]-a[0][2]*a[1][0])/det;
cout<<"x1="<<x1<<", x2="<<x2<<endl;
ans=x1;
hasans=true;
}
}
else if(n==3){
double a[3][4];
cout<<"输入增广矩阵(3行4列): "<<endl;
for(int i=0;i<3;i++){
for(int j=0;j<4;j++){
cin>>a[i][j];
}
}
double det=a[0][0]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])
-a[0][1]*(a[1][0]*a[2][2]-a[1][2]*a[2][0])
+a[0][2]*(a[1][0]*a[2][1]-a[1][1]*a[2][0]);
if(fabs(det)<1e-9){
cout<<"方程组无唯一解"<<endl;
}
else{
double x1=(a[0][3]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])
-a[0][1]*(a[1][3]*a[2][2]-a[1][2]*a[2][3])
+a[0][2]*(a[1][3]*a[2][1]-a[1][1]*a[2][3]))/det;
double x2=(a[0][0]*(a[1][3]*a[2][2]-a[1][2]*a[2][3])
-a[0][3]*(a[1][0]*a[2][2]-a[1][2]*a[2][0])
+a[0][2]*(a[1][0]*a[2][3]-a[1][3]*a[2][0]))/det;
double x3=(a[0][0]*(a[1][1]*a[2][3]-a[1][3]*a[2][1])
-a[0][1]*(a[1][0]*a[2][3]-a[1][3]*a[2][0])
+a[0][3]*(a[1][0]*a[2][1]-a[1][1]*a[2][0]))/det;
cout<<"x1="<<x1<<", x2="<<x2<<", x3="<<x3<<endl;
ans=x1;
hasans=true;
}
}
else{
cout<<"只支持2元或3元线性方程组"<<endl;
}
}
double jisuanbiaodashi(string s){
double a,b;
char op;
stringstream ss(s);
ss>>a;
if(!(ss>>op)){
return a;
}
ss>>b;
if(op=='+'){
return jia(a,b);
}
else if(op=='-'){
return jian(a,b);
}
else if(op=='*'){
return cheng(a,b);
}
else if(op=='/'){
return chu(a,b);
}
else if(op=='%'){
return quyu((int)a,(int)b);
}
else if(op=='^'){
return cimi(a,b);
}
return 0;
}
void putongjisuan(){
string s;
cout<<"输入表达式 (如 3+5 或 3+5*2): ";
cin>>s;
double res=0;
if(s.find('+')!=string::npos||s.find('-')!=string::npos||
s.find('*')!=string::npos||s.find('/')!=string::npos||
s.find('%')!=string::npos||s.find('^')!=string::npos){
if(s.find('*')!=string::npos&&(s.find('+')!=string::npos||s.find('-')!=string::npos)){
int pos=s.find('*');
string left=s.substr(0,pos);
string right=s.substr(pos+1);
double a=atof(left.c_str());
double b=0;
char op2=0;
for(int i=0;i<right.size();i++){
if(right[i]=='+'||right[i]=='-'||right[i]=='*'||right[i]=='/'){
b=atof(right.substr(0,i).c_str());
op2=right[i];
break;
}
}
res=a*b;
if(op2=='+'){
res+=atof(right.substr(right.find(op2)+1).c_str());
}
else if(op2=='-'){
res-=atof(right.substr(right.find(op2)+1).c_str());
}
}
else{
res=jisuanbiaodashi(s);
}
}
else{
res=atof(s.c_str());
}
cout<<"结果: "<<res<<endl;
ans=res;
hasans=true;
}
void jisuanqi(){
cout<<"========================================"<<endl;
cout<<" Casio 科学计算器 v1.0"<<endl;
cout<<"========================================"<<endl;
cout<<"功能菜单:"<<endl;
cout<<"1. 普通计算 (+,-,*,/,%,^)"<<endl;
cout<<"2. 科学函数 (sin,cos,tan,cot,log,ln,abs,sqrt,e)"<<endl;
cout<<"3. 复数计算"<<endl;
cout<<"4. 一元二次方程"<<endl;
cout<<"5. 一元三次方程"<<endl;
cout<<"6. 线性方程组"<<endl;
cout<<"7. 数列求和"<<endl;
cout<<"8. 数值积分"<<endl;
cout<<"9. 数值求导"<<endl;
cout<<"10. 查看Ans"<<endl;
cout<<"11. 角度转弧度"<<endl;
cout<<"12. 关机"<<endl;
cout<<"========================================"<<endl;
}
void kexuehanshu(){
int ch;
double x;
cout<<"选择函数: 1.sin 2.cos 3.tan 4.cot 5.log 6.ln 7.abs 8.sqrt 9.e^x: ";
cin>>ch;
cout<<"输入数值: ";
cin>>x;
double res=0;
if(ch==1){
res=zhengxian(x);
}
else if(ch==2){
res=yuxian(x);
}
else if(ch==3){
res=zhengqie(x);
}
else if(ch==4){
res=yvqie(x);
}
else if(ch==5){
res=changyongduishu(x);
}
else if(ch==6){
res=duishu(x);
}
else if(ch==7){
res=jueduizhi(x);
}
else if(ch==8){
res=genhao(x);
}
else if(ch==9){
res=zhishu(x);
}
else{
cout<<"无效选择"<<endl;
return;
}
cout<<"结果: "<<res<<endl;
ans=res;
hasans=true;
}
void fushujisuan(){
fushu a,b,res;
char op;
cout<<"输入第一个复数(实部 虚部): ";
cin>>a.shi>>a.xu;
cout<<"输入运算符(+,-,*,/): ";
cin>>op;
cout<<"输入第二个复数(实部 虚部): ";
cin>>b.shi>>b.xu;
if(op=='+'){
res=fushujia(a,b);
}
else if(op=='-'){
res=fushujian(a,b);
}
else if(op=='*'){
res=fushucheng(a,b);
}
else if(op=='/'){
res=fushuchu(a,b);
}
else{
cout<<"无效运算符"<<endl;
return;
}
cout<<"结果: ";
shuchufushu(res);
ans=res.shi;
hasans=true;
}
void shulieqiuhe(){
int ch;
cout<<"1.数组求和 2.等差数列求和(1到n) 3.自定义函数求和: ";
cin>>ch;
if(ch==1){
int n;
cout<<"输入元素个数: ";
cin>>n;
double arr[1000];
cout<<"输入"<<n<<"个数: ";
for(int i=0;i<n;i++){
cin>>arr[i];
}
double res=shuzuqiuhe(arr,n);
cout<<"和: "<<res<<endl;
ans=res;
hasans=true;
}
else if(ch==2){
long long n;
cout<<"输入n: ";
cin>>n;
long long res=dengchaqiuhe(n);
cout<<"1到"<<n<<"的和: "<<res<<endl;
ans=res;
hasans=true;
}
else{
cout<<"自定义函数求和功能需在代码中定义函数"<<endl;
}
}
double jifentest(double x){
return x*x;
}
void shuzhijifen(){
int ch;
double a,b;
int n=1000000;
cout<<"积分函数f(x)=x^2"<<endl;
cout<<"输入积分下限a: ";
cin>>a;
cout<<"输入积分上限b: ";
cin>>b;
cout<<"选择方法: 1.矩形法 2.梯形法 3.自适应辛普森法: ";
cin>>ch;
double res=0;
if(ch==1){
res=jvxingjifen(jifentest,a,b,n);
}
else if(ch==2){
res=tixingjifen(jifentest,a,b,n);
}
else if(ch==3){
res=zishiyingxinpusen(jifentest,a,b,1e-6);
}
else{
cout<<"无效选择"<<endl;
return;
}
cout<<"积分结果: "<<res<<endl;
ans=res;
hasans=true;
}
double qiudaotest(double x){
return x*x;
}
void shuzhiqiudao(){
double x;
int ch;
cout<<"求导函数f(x)=x^2"<<endl;
cout<<"输入求导点x: ";
cin>>x;
cout<<"选择方法: 1.中心差分 2.前向差分 3.后向差分: ";
cin>>ch;
double res=0;
double h=1e-5;
if(ch==1){
res=zhongxinqiudao(qiudaotest,x,h);
}
else if(ch==2){
res=qianxiangqiudao(qiudaotest,x,h);
}
else if(ch==3){
res=houxiangqiudao(qiudaotest,x,h);
}
else{
cout<<"无效选择"<<endl;
return;
}
cout<<"导数: "<<res<<endl;
ans=res;
hasans=true;
}
void jiaoduzhuanhudu(){
double deg;
cout<<"输入角度: ";
cin>>deg;
double rad=deg*pi/180;
cout<<"弧度: "<<rad<<endl;
ans=rad;
hasans=true;
}
int main(){
while(true){
jisuanqi();
cout<<"请选择功能(1-12): ";
int ch;
cin>>ch;
if(ch==1){
putongjisuan();
}
else if(ch==2){
kexuehanshu();
}
else if(ch==3){
fushujisuan();
}
else if(ch==4){
jieercifangcheng();
}
else if(ch==5){
jiesancifangcheng();
}
else if(ch==6){
jiexianxingfangcheng();
}
else if(ch==7){
shulieqiuhe();
}
else if(ch==8){
shuzhijifen();
}
else if(ch==9){
shuzhiqiudao();
}
else if(ch==10){
if(hasans){
cout<<"Ans = "<<ans<<endl;
}
else{
cout<<"暂无Ans值"<<endl;
}
}
else if(ch==11){
jiaoduzhuanhudu();
}
else if(ch==12){
guanji();
}
else{
cout<<"无效选择,请重新输入"<<endl;
}
cout<<endl;
}
return 0;
}
1:1试图仿真了,来个赞!!!
这里空空如也




















有帮助,赞一个