MATLAB: Most teachers of mathematics will tell you that is is important to have
ID: 3841141 • Letter: M
Question
MATLAB: Most teachers of mathematics will tell you that is is important to have a strong understanding of fractional mathematics. However, computers work with oating point number and not really with fractions. For example 1/2 is entered as 0.5 even if the user were to type 1/2 as the input line would do the math here.
Most teachers of mathematics will tell you that is is important to have a strong understanding of fractional mathematics. However, computers work with floating point number and not really with fractions. For example 1/2 is entered as 0.5 even if the user were to type 1/2 as the input line would do the math here. Design a detailed pseudo code algorithm to as the user for 4 numbers representing two fractions. For notation let the fractions be represented as numerator 2 numerator and denominator denominator2 Write a script which in order calculates and then clearly displays the sum, difference product and division of the first fraction with the second fraction. By hand execute your algorithm with the fractions 1/6 and 2/5 to create your test output. Note that you do have have to attempt to program any fraction reduction.Explanation / Answer
#include <iostream>
using namespace std;
void add();
void subtract();
void mul();
void division();
void user_choice();
int choice;
int x1,y1,x2,y2;
int num,denom;
int main()
{
cout<<"enter number for x1 and y1";
cin>>x1>>y1;
cout<<"value of x1 and y1"<<x1<<y1;
cout<<"enter number for x2 and y2";
cin>>x2>>y2;
cout<<"value of x2 and y2"<<x2<<y2;
cout<<"press1 to add,press2 to sub,3 fro mul,4 for div";
cin>>choice;
cout<<choice;
switch(choice)
{
case 1:
add();
break;
case 2:
subtract();
break;
case 3:
mul();
break;
case 4:
division();
break;
}
return 0;
}
void add()
{
num=((x1*y1)+(y1*x2));
denom=(y1*y2);
cout<<"num and denom"<<num<<"/"<<denom;
}
void subtract()
{
num=((x1*y2)-(y1*x2));
denom=(y1*y2);
cout<<"num and denom"<<num<<"/"<<denom;
}
void mul()
{
num=(x1*x2);
denom=(y1*y2);
cout<<"num and denom"<<num<<"/"<<denom;
}
void division()
{
num=(x1*y2);
denom=(y1*x2);
cout<<"num and denom"<<num<<"/"<<denom;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.