SlideShare a Scribd company logo
1 of 7
Download to read offline
//The following is the (incomplete) header file for the class Fraction.
//You must complete the class header and implement all of its functions.
typedef unsigned int uint ;
class Fraction {
uint _numerator ;
uint _denominator ;
bool _isNegative ;
public :
//The sign of the first parameter determines the sign of the
//fraction
Fraction ( int pNum , uint pDen ) ;
//The denominator is assumed to be 1.
Fraction ( int pNum ) ;
//getters
uint numerator ( ) const ;
uint denominator ( ) const ;
//Returns the decimal result of performing the fraction's division
float value ( ) const ;
//Add prototypes here for:
//using the + operator to add two fractions.
//using the - operator to subtract two fractions.
//using < and > operators to compare fractions.
}
//Add the prototype here for the insertion operator.
Solution
#include
using namespace std;
class fraction
{
private:
int* num;
int* deno;
public:
fraction();
fraction(int,int);
fraction(const fraction&);
void printfrac();
fraction operator+(fraction);
fraction operator-(fraction);
fraction operator*(fraction);
fraction operator/(fraction);
void operator=(fraction);
};
void fraction::printfrac()
{
cout<<*(fraction::num)<<"/"<<*(fraction::deno);
}
inline fraction::fraction()
{
this->num=new int(0);
this->deno=new int(0);
}
inline fraction::fraction(int num,int deno)
{
this->num=new int(num);
this->deno=new int(deno);
}
inline fraction::fraction(const fraction&f)
{
fraction::num=new int;
fraction::deno=new int;
*(this->num)=*(f.num);
*(this->deno)=*(f.deno);
}
void swap(int &x,int &y)
{
int tmp=x;
x=y;
y=tmp;
}
int lcm(int l,int s)
{
if(lnum)=*(f.num);
*(this->deno)=*(f.deno);
}
fraction fraction::operator+(fraction f1)
{
int slcm=lcm(*(f1.deno),*(this->deno));
int num1=*(f1.num)*(slcm/ *(f1.deno));
int num2=*(this->num)*(slcm/ *(this->deno));
int num=num1+num2;
int t=num;
num=num/gcd(num,slcm);
slcm=slcm/gcd(t,slcm);
fraction f(num,slcm);
return f;
}
fraction fraction::operator-(fraction f2)
{
int slcm=lcm(*(this->deno),*(f2.deno));
int num2=*(f2.num)*(slcm / *(f2.deno));
int num1=*(this->num)*(slcm / *(this->deno));
int num=num1-num2;
int t=num;
num=num/gcd(num,slcm);
slcm=slcm/gcd(t,slcm);
fraction f(num,slcm);
return f;
}
fraction fraction::operator*(fraction f1)
{
int num1=*(f1.num)*(*(this->num));
int num2=*(f1.deno)*(*(this->deno));
int t=num1;
num1=num1/gcd(num1,num2);
num2=num2/gcd(t,num2);
fraction f(num1,num2);
return f;
}
fraction fraction::operator/(fraction f2)
{
int num1=*(this->num)*(*(f2.deno));
int num2=*(this->deno)*(*(f2.num));
int t=num1;
num1=num1/gcd(num1,num2);
num2=num2/gcd(t,num2);
fraction f(num1,num2);
return f;
}
int main()
{
int n1,n2,d1,d2,c;
char ch;
while(true)
{
cout<<" Enter numerator and denominator of 1st fraction:";
cin>>n1>>d1;
cout<<" Enter numerator and denominator of 2nd fraction:";
cin>>n2>>d2;
fraction f1(n1,d1);
fraction f2(n2,d2);
cout<<"Fraction 1: ";
f1.printfrac();
cout<<" Fraction 2: ";
f2.printfrac();
cout<<" ";
do
{
cout<<" Menu "<<"---------------- "<<"1.Addition 2.Multiplication 3.Subtraction
4.Division 5.Copy using copy constructor 6.Copy using assgnment operator ";
cout<<" Enter which operation you want to perform:";
cin>>c;
switch(c)
{
case 1:
{
fraction res=f1+f2;
cout<<" Result of addition:";
res.printfrac();
break;
}
case 2:
{
fraction res=f1*f2;
cout<<" Result of multiplication:";
res.printfrac();
break;
}
case 3:
{
fraction res=f1-f2;
cout<<" Result of subtraction:";
res.printfrac();
break;
}
case 4:
{
fraction res=f1/f2;
cout<<" Result of division:";
res.printfrac();
break;
}
case 5:
{
cout<<" New copy of 1st fraction:";
fraction res1=f1;
res1.printfrac();
cout<<" New copy of 2nd fraction:";
fraction res2=f2;
res2.printfrac();
break;
}
case 6:
{
cout<<" New copy of 1st fraction:";
fraction res1;
res1=f1;
res1.printfrac();
cout<<" New copy of 2nd fraction:";
fraction res2;
res2=f2;
res2.printfrac();
break;
}
default:
cout<<" Invalid choice!!!";
}
cout<<" Do you want to exit from program(Y/N):";
cin>>ch;
if(ch=='Y'||ch=='y')
return 0;
cout<<"Do you want to continue operation with these two fractions or want to continue with
two new fractions(Y/N):";
cin>>ch;
}while(ch=='Y'||ch=='y');
}
return 0;
}

More Related Content

Similar to The following is the (incomplete) header file for the class Fracti.pdf

Write a program that works with fractions. You are first to implemen.pdf
Write a program that works with fractions. You are first to implemen.pdfWrite a program that works with fractions. You are first to implemen.pdf
Write a program that works with fractions. You are first to implemen.pdfleventhalbrad49439
 
can someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdfcan someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdfvinaythemodel
 
Help in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdfHelp in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdfmanjan6
 
AnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfAnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfanurag1231
 
You will be implementing the following functions. You may modify the.pdf
You will be implementing the following functions. You may modify the.pdfYou will be implementing the following functions. You may modify the.pdf
You will be implementing the following functions. You may modify the.pdfmalavshah9013
 
When we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdfWhen we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdfarihantkitchenmart
 
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfQ1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfabdulrahamanbags
 
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdfPlease do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdfaioils
 
please help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfplease help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfnewfaransportsfitnes
 
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,pptAllNewTeach
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptxNagasaiT
 
#ifndef RATIONAL_H   if this compiler macro is not defined #def.pdf
#ifndef RATIONAL_H    if this compiler macro is not defined #def.pdf#ifndef RATIONAL_H    if this compiler macro is not defined #def.pdf
#ifndef RATIONAL_H   if this compiler macro is not defined #def.pdfexxonzone
 
Unit 4
Unit 4Unit 4
Unit 4siddr
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Mario Fusco
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7Rumman Ansari
 
function in in thi pdf you will learn what is fu...
function in  in thi pdf you will learn   what                           is fu...function in  in thi pdf you will learn   what                           is fu...
function in in thi pdf you will learn what is fu...kushwahashivam413
 

Similar to The following is the (incomplete) header file for the class Fracti.pdf (20)

Write a program that works with fractions. You are first to implemen.pdf
Write a program that works with fractions. You are first to implemen.pdfWrite a program that works with fractions. You are first to implemen.pdf
Write a program that works with fractions. You are first to implemen.pdf
 
can someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdfcan someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdf
 
Help in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdfHelp in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdf
 
AnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfAnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdf
 
You will be implementing the following functions. You may modify the.pdf
You will be implementing the following functions. You may modify the.pdfYou will be implementing the following functions. You may modify the.pdf
You will be implementing the following functions. You may modify the.pdf
 
When we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdfWhen we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdf
 
Functions
FunctionsFunctions
Functions
 
functions
functionsfunctions
functions
 
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfQ1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
 
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdfPlease do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
 
please help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfplease help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdf
 
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,ppt
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
 
#ifndef RATIONAL_H   if this compiler macro is not defined #def.pdf
#ifndef RATIONAL_H    if this compiler macro is not defined #def.pdf#ifndef RATIONAL_H    if this compiler macro is not defined #def.pdf
#ifndef RATIONAL_H   if this compiler macro is not defined #def.pdf
 
function_v1.ppt
function_v1.pptfunction_v1.ppt
function_v1.ppt
 
function_v1.ppt
function_v1.pptfunction_v1.ppt
function_v1.ppt
 
Unit 4
Unit 4Unit 4
Unit 4
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 
function in in thi pdf you will learn what is fu...
function in  in thi pdf you will learn   what                           is fu...function in  in thi pdf you will learn   what                           is fu...
function in in thi pdf you will learn what is fu...
 

More from 4babies2010

Find the domain of the function. (Enter your answer using interval no.pdf
Find the domain of the function. (Enter your answer using interval no.pdfFind the domain of the function. (Enter your answer using interval no.pdf
Find the domain of the function. (Enter your answer using interval no.pdf4babies2010
 
factors that are significant in the development of disease includ.pdf
factors that are significant in the development of disease includ.pdffactors that are significant in the development of disease includ.pdf
factors that are significant in the development of disease includ.pdf4babies2010
 
economic institutions 8. According to Thomas Piketty, what is the si.pdf
economic institutions 8. According to Thomas Piketty, what is the si.pdfeconomic institutions 8. According to Thomas Piketty, what is the si.pdf
economic institutions 8. According to Thomas Piketty, what is the si.pdf4babies2010
 
Discuss bio films , formation location etc Discuss bio films , .pdf
Discuss bio films , formation location etc Discuss bio films , .pdfDiscuss bio films , formation location etc Discuss bio films , .pdf
Discuss bio films , formation location etc Discuss bio films , .pdf4babies2010
 
Discuss the importance of documentation in the medical record.So.pdf
Discuss the importance of documentation in the medical record.So.pdfDiscuss the importance of documentation in the medical record.So.pdf
Discuss the importance of documentation in the medical record.So.pdf4babies2010
 
Determine the molecular geometry of CO32â».Solution .pdf
Determine the molecular geometry of CO32â».Solution           .pdfDetermine the molecular geometry of CO32â».Solution           .pdf
Determine the molecular geometry of CO32â».Solution .pdf4babies2010
 
Define each class of incident.types of incidents classifcationsr.pdf
Define each class of incident.types of incidents classifcationsr.pdfDefine each class of incident.types of incidents classifcationsr.pdf
Define each class of incident.types of incidents classifcationsr.pdf4babies2010
 
Complete a force field analysis for an organization with which you a.pdf
Complete a force field analysis for an organization with which you a.pdfComplete a force field analysis for an organization with which you a.pdf
Complete a force field analysis for an organization with which you a.pdf4babies2010
 
Write CC++ a program that inputs a weighted undirected graph and fi.pdf
Write CC++ a program that inputs a weighted undirected graph and fi.pdfWrite CC++ a program that inputs a weighted undirected graph and fi.pdf
Write CC++ a program that inputs a weighted undirected graph and fi.pdf4babies2010
 
Why was the iodide ion successful for the SN2 reactions What if you.pdf
Why was the iodide ion successful for the SN2 reactions What if you.pdfWhy was the iodide ion successful for the SN2 reactions What if you.pdf
Why was the iodide ion successful for the SN2 reactions What if you.pdf4babies2010
 
What were the triumphs and limitations of democracy in Periclean Ath.pdf
What were the triumphs and limitations of democracy in Periclean Ath.pdfWhat were the triumphs and limitations of democracy in Periclean Ath.pdf
What were the triumphs and limitations of democracy in Periclean Ath.pdf4babies2010
 
What process causes plant ion-uptake to acidify soil What soil pH r.pdf
What process causes plant ion-uptake to acidify soil What soil pH r.pdfWhat process causes plant ion-uptake to acidify soil What soil pH r.pdf
What process causes plant ion-uptake to acidify soil What soil pH r.pdf4babies2010
 
what is the name and stereochemistry of the compoundSolution.pdf
what is the name and stereochemistry of the compoundSolution.pdfwhat is the name and stereochemistry of the compoundSolution.pdf
what is the name and stereochemistry of the compoundSolution.pdf4babies2010
 
What are some of the architectural decisions that you need to make w.pdf
What are some of the architectural decisions that you need to make w.pdfWhat are some of the architectural decisions that you need to make w.pdf
What are some of the architectural decisions that you need to make w.pdf4babies2010
 
What are lichens What are foliose lichensSolutionAnswers .pdf
What are lichens  What are foliose lichensSolutionAnswers .pdfWhat are lichens  What are foliose lichensSolutionAnswers .pdf
What are lichens What are foliose lichensSolutionAnswers .pdf4babies2010
 
These are questions to be answered in a paper about the Chernobyl in.pdf
These are questions to be answered in a paper about the Chernobyl in.pdfThese are questions to be answered in a paper about the Chernobyl in.pdf
These are questions to be answered in a paper about the Chernobyl in.pdf4babies2010
 
The adjusted trial balance for Tybalt Construction as of December 31.pdf
The adjusted trial balance for Tybalt Construction as of December 31.pdfThe adjusted trial balance for Tybalt Construction as of December 31.pdf
The adjusted trial balance for Tybalt Construction as of December 31.pdf4babies2010
 
Summarize the case Surgery Iturralde v. Hilo Medical Center USA , i.pdf
Summarize the case Surgery Iturralde v. Hilo Medical Center USA , i.pdfSummarize the case Surgery Iturralde v. Hilo Medical Center USA , i.pdf
Summarize the case Surgery Iturralde v. Hilo Medical Center USA , i.pdf4babies2010
 
Suppose we draw 2 cards out of a deck of 52. Let A = “the first card.pdf
Suppose we draw 2 cards out of a deck of 52. Let A = “the first card.pdfSuppose we draw 2 cards out of a deck of 52. Let A = “the first card.pdf
Suppose we draw 2 cards out of a deck of 52. Let A = “the first card.pdf4babies2010
 
std deviationSolutionStandard deviation is the measure of disp.pdf
std deviationSolutionStandard deviation is the measure of disp.pdfstd deviationSolutionStandard deviation is the measure of disp.pdf
std deviationSolutionStandard deviation is the measure of disp.pdf4babies2010
 

More from 4babies2010 (20)

Find the domain of the function. (Enter your answer using interval no.pdf
Find the domain of the function. (Enter your answer using interval no.pdfFind the domain of the function. (Enter your answer using interval no.pdf
Find the domain of the function. (Enter your answer using interval no.pdf
 
factors that are significant in the development of disease includ.pdf
factors that are significant in the development of disease includ.pdffactors that are significant in the development of disease includ.pdf
factors that are significant in the development of disease includ.pdf
 
economic institutions 8. According to Thomas Piketty, what is the si.pdf
economic institutions 8. According to Thomas Piketty, what is the si.pdfeconomic institutions 8. According to Thomas Piketty, what is the si.pdf
economic institutions 8. According to Thomas Piketty, what is the si.pdf
 
Discuss bio films , formation location etc Discuss bio films , .pdf
Discuss bio films , formation location etc Discuss bio films , .pdfDiscuss bio films , formation location etc Discuss bio films , .pdf
Discuss bio films , formation location etc Discuss bio films , .pdf
 
Discuss the importance of documentation in the medical record.So.pdf
Discuss the importance of documentation in the medical record.So.pdfDiscuss the importance of documentation in the medical record.So.pdf
Discuss the importance of documentation in the medical record.So.pdf
 
Determine the molecular geometry of CO32â».Solution .pdf
Determine the molecular geometry of CO32â».Solution           .pdfDetermine the molecular geometry of CO32â».Solution           .pdf
Determine the molecular geometry of CO32â».Solution .pdf
 
Define each class of incident.types of incidents classifcationsr.pdf
Define each class of incident.types of incidents classifcationsr.pdfDefine each class of incident.types of incidents classifcationsr.pdf
Define each class of incident.types of incidents classifcationsr.pdf
 
Complete a force field analysis for an organization with which you a.pdf
Complete a force field analysis for an organization with which you a.pdfComplete a force field analysis for an organization with which you a.pdf
Complete a force field analysis for an organization with which you a.pdf
 
Write CC++ a program that inputs a weighted undirected graph and fi.pdf
Write CC++ a program that inputs a weighted undirected graph and fi.pdfWrite CC++ a program that inputs a weighted undirected graph and fi.pdf
Write CC++ a program that inputs a weighted undirected graph and fi.pdf
 
Why was the iodide ion successful for the SN2 reactions What if you.pdf
Why was the iodide ion successful for the SN2 reactions What if you.pdfWhy was the iodide ion successful for the SN2 reactions What if you.pdf
Why was the iodide ion successful for the SN2 reactions What if you.pdf
 
What were the triumphs and limitations of democracy in Periclean Ath.pdf
What were the triumphs and limitations of democracy in Periclean Ath.pdfWhat were the triumphs and limitations of democracy in Periclean Ath.pdf
What were the triumphs and limitations of democracy in Periclean Ath.pdf
 
What process causes plant ion-uptake to acidify soil What soil pH r.pdf
What process causes plant ion-uptake to acidify soil What soil pH r.pdfWhat process causes plant ion-uptake to acidify soil What soil pH r.pdf
What process causes plant ion-uptake to acidify soil What soil pH r.pdf
 
what is the name and stereochemistry of the compoundSolution.pdf
what is the name and stereochemistry of the compoundSolution.pdfwhat is the name and stereochemistry of the compoundSolution.pdf
what is the name and stereochemistry of the compoundSolution.pdf
 
What are some of the architectural decisions that you need to make w.pdf
What are some of the architectural decisions that you need to make w.pdfWhat are some of the architectural decisions that you need to make w.pdf
What are some of the architectural decisions that you need to make w.pdf
 
What are lichens What are foliose lichensSolutionAnswers .pdf
What are lichens  What are foliose lichensSolutionAnswers .pdfWhat are lichens  What are foliose lichensSolutionAnswers .pdf
What are lichens What are foliose lichensSolutionAnswers .pdf
 
These are questions to be answered in a paper about the Chernobyl in.pdf
These are questions to be answered in a paper about the Chernobyl in.pdfThese are questions to be answered in a paper about the Chernobyl in.pdf
These are questions to be answered in a paper about the Chernobyl in.pdf
 
The adjusted trial balance for Tybalt Construction as of December 31.pdf
The adjusted trial balance for Tybalt Construction as of December 31.pdfThe adjusted trial balance for Tybalt Construction as of December 31.pdf
The adjusted trial balance for Tybalt Construction as of December 31.pdf
 
Summarize the case Surgery Iturralde v. Hilo Medical Center USA , i.pdf
Summarize the case Surgery Iturralde v. Hilo Medical Center USA , i.pdfSummarize the case Surgery Iturralde v. Hilo Medical Center USA , i.pdf
Summarize the case Surgery Iturralde v. Hilo Medical Center USA , i.pdf
 
Suppose we draw 2 cards out of a deck of 52. Let A = “the first card.pdf
Suppose we draw 2 cards out of a deck of 52. Let A = “the first card.pdfSuppose we draw 2 cards out of a deck of 52. Let A = “the first card.pdf
Suppose we draw 2 cards out of a deck of 52. Let A = “the first card.pdf
 
std deviationSolutionStandard deviation is the measure of disp.pdf
std deviationSolutionStandard deviation is the measure of disp.pdfstd deviationSolutionStandard deviation is the measure of disp.pdf
std deviationSolutionStandard deviation is the measure of disp.pdf
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

The following is the (incomplete) header file for the class Fracti.pdf

  • 1. //The following is the (incomplete) header file for the class Fraction. //You must complete the class header and implement all of its functions. typedef unsigned int uint ; class Fraction { uint _numerator ; uint _denominator ; bool _isNegative ; public : //The sign of the first parameter determines the sign of the //fraction Fraction ( int pNum , uint pDen ) ; //The denominator is assumed to be 1. Fraction ( int pNum ) ; //getters uint numerator ( ) const ; uint denominator ( ) const ; //Returns the decimal result of performing the fraction's division float value ( ) const ; //Add prototypes here for: //using the + operator to add two fractions. //using the - operator to subtract two fractions. //using < and > operators to compare fractions. }
  • 2. //Add the prototype here for the insertion operator. Solution #include using namespace std; class fraction { private: int* num; int* deno; public: fraction(); fraction(int,int); fraction(const fraction&); void printfrac(); fraction operator+(fraction); fraction operator-(fraction); fraction operator*(fraction); fraction operator/(fraction); void operator=(fraction); }; void fraction::printfrac() { cout<<*(fraction::num)<<"/"<<*(fraction::deno); } inline fraction::fraction() { this->num=new int(0); this->deno=new int(0); } inline fraction::fraction(int num,int deno) { this->num=new int(num); this->deno=new int(deno); }
  • 3. inline fraction::fraction(const fraction&f) { fraction::num=new int; fraction::deno=new int; *(this->num)=*(f.num); *(this->deno)=*(f.deno); } void swap(int &x,int &y) { int tmp=x; x=y; y=tmp; } int lcm(int l,int s) { if(lnum)=*(f.num); *(this->deno)=*(f.deno); } fraction fraction::operator+(fraction f1) { int slcm=lcm(*(f1.deno),*(this->deno)); int num1=*(f1.num)*(slcm/ *(f1.deno)); int num2=*(this->num)*(slcm/ *(this->deno)); int num=num1+num2; int t=num; num=num/gcd(num,slcm); slcm=slcm/gcd(t,slcm); fraction f(num,slcm); return f; } fraction fraction::operator-(fraction f2) { int slcm=lcm(*(this->deno),*(f2.deno)); int num2=*(f2.num)*(slcm / *(f2.deno)); int num1=*(this->num)*(slcm / *(this->deno)); int num=num1-num2;
  • 4. int t=num; num=num/gcd(num,slcm); slcm=slcm/gcd(t,slcm); fraction f(num,slcm); return f; } fraction fraction::operator*(fraction f1) { int num1=*(f1.num)*(*(this->num)); int num2=*(f1.deno)*(*(this->deno)); int t=num1; num1=num1/gcd(num1,num2); num2=num2/gcd(t,num2); fraction f(num1,num2); return f; } fraction fraction::operator/(fraction f2) { int num1=*(this->num)*(*(f2.deno)); int num2=*(this->deno)*(*(f2.num)); int t=num1; num1=num1/gcd(num1,num2); num2=num2/gcd(t,num2); fraction f(num1,num2); return f; } int main() { int n1,n2,d1,d2,c; char ch; while(true) { cout<<" Enter numerator and denominator of 1st fraction:"; cin>>n1>>d1; cout<<" Enter numerator and denominator of 2nd fraction:"; cin>>n2>>d2;
  • 5. fraction f1(n1,d1); fraction f2(n2,d2); cout<<"Fraction 1: "; f1.printfrac(); cout<<" Fraction 2: "; f2.printfrac(); cout<<" "; do { cout<<" Menu "<<"---------------- "<<"1.Addition 2.Multiplication 3.Subtraction 4.Division 5.Copy using copy constructor 6.Copy using assgnment operator "; cout<<" Enter which operation you want to perform:"; cin>>c; switch(c) { case 1: { fraction res=f1+f2; cout<<" Result of addition:"; res.printfrac(); break; } case 2: { fraction res=f1*f2; cout<<" Result of multiplication:"; res.printfrac(); break; } case 3: { fraction res=f1-f2; cout<<" Result of subtraction:"; res.printfrac(); break; }
  • 6. case 4: { fraction res=f1/f2; cout<<" Result of division:"; res.printfrac(); break; } case 5: { cout<<" New copy of 1st fraction:"; fraction res1=f1; res1.printfrac(); cout<<" New copy of 2nd fraction:"; fraction res2=f2; res2.printfrac(); break; } case 6: { cout<<" New copy of 1st fraction:"; fraction res1; res1=f1; res1.printfrac(); cout<<" New copy of 2nd fraction:"; fraction res2; res2=f2; res2.printfrac(); break; } default: cout<<" Invalid choice!!!"; } cout<<" Do you want to exit from program(Y/N):"; cin>>ch; if(ch=='Y'||ch=='y') return 0;
  • 7. cout<<"Do you want to continue operation with these two fractions or want to continue with two new fractions(Y/N):"; cin>>ch; }while(ch=='Y'||ch=='y'); } return 0; }