#include <iostreamh>
class Money{ int yuan,jiao,fen;
public:Money(int a,int b,int c)
{yuan=a;jiao=b;fen=c;}//构造函数
void Money_set(int a,int b,int c)
{yuan=a;jiao=b;fen=c;}//初始化
void Money_jisuan(Money a1,Money a2,char p,int shu);//计算函数的声明
void print()
{cout<<"Money is"<<yuan<<"元"<<jiao<<"角"<<fen<<"分"<<endl;}//输出
};
void Money::Money_jisuan(Money a1,Money a2,char p,int shu)//计算函数的定义
{double zhongzhi,zhongzhi1,zhongzhi2;
int m,n,k,newa,newb,newc;
zhongzhi1=a1yuan+a1jiao01+a1fen001;
zhongzhi2=a2yuan+a2jiao01+a2fen001;
if(p=='+')
zhongzhi=zhongzhi1+zhongzhi2;
if(p=='-')
{if((a1yuan<a2yuan)||((a1yuan==a2yuan)&&(a1jiao<a2jiao))||((a1yuan==a2yuan)&&(a1jiao==a2jiao)&&(a1fen<a2fen)))
{m=a1yuan;a1yuan=a2yuan;a2yuan=m;
n=a1jiao;a1jiao=a2jiao;a2jiao=n;
k=a1fen;a1fen=a2fen;a2fen=k;}
zhongzhi1=a1yuan+a1jiao01+a1fen001;
zhongzhi2=a2yuan+a2jiao01+a2fen001;
zhongzhi=zhongzhi1-zhongzhi2;};
if(p=='')
zhongzhi=zhongzhi1shu;
if((p=='/')&&(shu!=0))
zhongzhi=zhongzhi1/shu;
newa=(int)(zhongzhi100)/100;//计算后Money的yuan
newb=(int)(zhongzhi100)%100/10;//计算后Money的jiao
newc=(int)(zhongzhi100)%10;//计算后Money的fen
cout<<"运算后的值为:"<<newa<<"元"<<newb<<"角"<<newc<<"分"<<endl;
};
void main()
{ Money a1(10,6,9),a2(3,4,5);
a2Money_jisuan(a1,a2,'+',3);
a2Money_jisuan(a1,a2,'-',3);
a2Money_jisuan(a1,a2,'',3);
a2Money_jisuan(a1,a2,'/',3);
a1print();
a2print();
}
代码:
#include<stdioh>
#include<stdlibh>
intmain()
{
floatr,h,S,V;
printf("请输入圆柱体的半径\n");
scanf("%f",&r);
printf("请输入圆柱体的高\n");
scanf("%f",&h);
S=125663704rh,V=31415926rrh;
printf("圆柱体表面积是%f体积是%f",S,V);
return0;
}
扩展资料
C语言计算矩形面积(S),输入长(h),宽(w)定义为整形:
#include<iostream>
usingnamespacestd;
intmain(){
ints,h,w;
cin>>h>>w;
s=hw;
cout<<s;
return0;
}
#include <stdioh>
#include<stringh>
#define PI 314
void yuan(double L,double R);
int main()
{
double L,R;
printf("输入高度:");
scanf("%lf",&L);
printf("输入半径:");
scanf("%lf",&R);
yuan(L,R);
return 0;
}
void yuan(double L,double R){
double v,s;
s=2PIRL+2PIRR;
v=PIRRL;
printf("圆柱表面积:%2lf\n圆柱体积: %2lf\n",s,v);
}
可以参考代码:
def test(n):
if n[-1]=="R":
return str(int(n[0:-1])/65)+"D"
elif n[-1]=="D":
return str(int(n[0:-1])65)+"R"
或是可以使用input获取键盘输入的字符,而不是作为方法的传入参数n
以上就是关于Money 类的程序设计(C++程序设计)全部的内容,包括:Money 类的程序设计(C++程序设计)、用C语言编写程序,调用函数求一个圆柱体的表面积和体积、编写一个程序,调用函数求一个圆柱体的侧面积和体积等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)