第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

定義分數(shù)類,數(shù)據(jù)成員a和b表示分數(shù)的分子和分母,類中定義成員函數(shù)能夠實現(xiàn)分數(shù)的加減乘除運算

定義分數(shù)類,數(shù)據(jù)成員a和b表示分數(shù)的分子和分母,類中定義成員函數(shù)能夠實現(xiàn)分數(shù)的加減乘除運算

C C++
haligongoj 2017-03-04 13:36:07
input 首先是一個正整數(shù)n,表示有n組數(shù)據(jù)。每一組數(shù)據(jù)中由4個整形數(shù)組成,分別表示第一個分數(shù)的分子和分母和第二個分數(shù)的分子和分母。 output 兩個加減乘除的結果 sampleinput 3 2 -4 3 5 1 2 3 4 4 3 2 -1 sampleoutput 1/10 11/10 -3/10 -5/6 5/4 -1/4 3/8 2/3 -2/3 10/3 -8/3 -2/3
查看完整描述

1 回答

已采納
?
asd8532

TA貢獻143條經驗 獲得超187個贊

#include<iostream>
?#include<cmath>
?using?namespace?std;
??
class?fraction{
public:
??int?above;
??int?below;
??void?reduction();
??void?makeCommond(fraction&);
?public:
??fraction(int?a=0,int?b=1){
???above=a;below=b;
??}
??fraction?add(fraction);
??fraction?sub(fraction);
??fraction?mul(fraction);
??fraction?div(fraction);
??void?display();
?};
?void?fraction::reduction(){
	??int?a,b,temp;
	??if(below<0){
	???above=-above;
	???below=-below;
	??}
	??a=abs(above);
	??b=abs(below);
	??while(a%b){
	???temp=a;
	???a=b;
	???b=temp%b;
	??}
	??above/=b;
	??below/=b;
?}
?void?fraction::makeCommond(fraction&?b){
	??int?temp;
	??reduction();
	??b.reduction();
	??above*=b.below;
	??b.above*=below;
	??temp=below*b.below;
	??below=b.below=temp;
?}
?fraction?fraction::add(fraction?b){
	??fraction?temp;
	??makeCommond(b);
	??
	??temp.above=above+b.above;
	??temp.below=below;
	??temp.reduction();
	??
	??return?temp;
?}
?fraction?fraction::sub(fraction?b){
	??fraction?temp;
	??makeCommond(b);
?
	??temp.above=above-b.above;
	??temp.below=below;
	??temp.reduction();
	??return?temp;
?}
?fraction?fraction::mul(fraction?b){
	??fraction?temp;
	??
	??temp.above=above*b.above;
	??temp.below=below*b.below;
	??temp.reduction();
	??return?temp;
?}
?fraction?fraction::div(fraction?b){
	??fraction?temp;
	??if(b.above==0){
	???cout<<"零不能作除數(shù)!"<<endl;
	???exit(1);
	??}
	??temp.above=above*b.below;
	??temp.below=below*b.above;
	??temp.reduction();
	??return?temp;
?}
?void?fraction::display(){
??reduction();
??cout<<above<<"/"<<below<<"?";
?}

?int?main(){
??int?n;
??cin>>n;
??while(n>=1){
??	fraction?f1,f2;
??	cin>>f1.above>>f1.below>>f2.above>>f2.below;
????fraction?f3=f1.add(f2);	
????fraction?f4=f1.sub(f2);	
????fraction?f5=f1.mul(f2);	
????fraction?f6=f1.div(f2);	
??	f3.display();
??	f4.display();
??	f5.display();
??	f6.display();
??	cout<<endl;
??}
??return?0;
?}


查看完整回答
1 反對 回復 2017-03-14
  • 1 回答
  • 0 關注
  • 3556 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號