SlideShare a Scribd company logo
1 of 3
Download to read offline
Write a C++ program which create a class for working with mixed fractions. MUST BE MIXED,
NOT IMPROPER. GIVEN: The main.
class Fraction {
public:
Fraction(int = 1, int = 1, int = 1);
void printData();
void add(Fraction, Fraction);
void sub(Fraction, Fraction);
void mult(Fraction, Fraction);
void divide(Fraction, Fraction);
Fraction recip();
void reduce();
private:
int whole, num, den;
};
int main()
{
Fraction f1(8, 12, 14), f2(3, 4, 6), sum, diff, prod, quo;
cout << "The fractions are " << endl;
f1.printData();
cout << " and ";
f2.printData();
cout << endl << endl;
sum.add(f1, f2);
diff.sub(f1, f2);
prod.mult(f1, f2);
quo.divide(f1, f2);
cout << "Sum is ";
sum.printData();
cout << endl << endl;
cout << "Difference is ";
diff.printData();
cout << endl << endl;
cout << "Product is ";
prod.printData();
cout << endl << endl;
cout << "Quotient is ";
quo.printData();
cout << endl << endl;
f1.recip();
f2.recip();
cout << "The reciprocals are ";
f1.printData();
cout << " ";
f2.printData();
cout << endl << endl;
system("PAUSE");
return 0;
}
Output should have MIXED FRACTIONS ONLY. Not improper fractions.
Solution
PROGRAM CODE:
/*
* main.cpp
*
* Created on: 31-Oct-2016
* Author: kaju
*/
#include
using namespace std;
class Fraction {
public:
Fraction(int = 1, int = 1, int = 1);
void printData();
void add(Fraction, Fraction);
void sub(Fraction, Fraction);
void mult(Fraction, Fraction);
void divide(Fraction, Fraction);
Fraction recip();
void reduce();
private:
int whole, num, den;
};
void Fraction::reduce()
{
while(num%2 == 0 && den%2 == 0)
{
num = num/2;
den = den/2;
}
while(num%3 == 0 && den%3 == 0)
{
num = num/3;
den = den/3;
}
while(num%5 == 0 && den%5 == 0)
{
num = num/5;
den = den/5;
}
}
Fraction::Fraction(int whole, int num, int den)
{
this->den = den;
this->whole = whole;
this->num = num;
reduce();
}
void Fraction::printData()
{
if(whole == 0)
cout<

More Related Content

Similar to Write a C++ program which create a class for working with mixed frac.pdf

Esg111 midterm review
Esg111 midterm reviewEsg111 midterm review
Esg111 midterm reviewmickeynickey1
 
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfPROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfezonesolutions
 
Interfacepackage PJ1; public interface SimpleFractionInterface.pdf
Interfacepackage PJ1; public interface SimpleFractionInterface.pdfInterfacepackage PJ1; public interface SimpleFractionInterface.pdf
Interfacepackage PJ1; public interface SimpleFractionInterface.pdfsutharbharat59
 
Java Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfJava Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfaroramobiles1
 
Make sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdfMake sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdfadityastores21
 
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
 
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
 
Java Program- Wrtie a Fraction classGiven the main method of a dri.pdf
Java Program- Wrtie a Fraction classGiven the main method of a dri.pdfJava Program- Wrtie a Fraction classGiven the main method of a dri.pdf
Java Program- Wrtie a Fraction classGiven the main method of a dri.pdfarchanaemporium
 
The following code is an implementation of the producer consumer pro.pdf
The following code is an implementation of the producer consumer pro.pdfThe following code is an implementation of the producer consumer pro.pdf
The following code is an implementation of the producer consumer pro.pdfmarketing413921
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxtristans3
 
import java.util.Scanner;public class Fraction {   instan.pdf
import java.util.Scanner;public class Fraction {    instan.pdfimport java.util.Scanner;public class Fraction {    instan.pdf
import java.util.Scanner;public class Fraction {   instan.pdfapleathers
 
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
 

Similar to Write a C++ program which create a class for working with mixed frac.pdf (20)

Esg111 midterm review
Esg111 midterm reviewEsg111 midterm review
Esg111 midterm review
 
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfPROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
 
Interfacepackage PJ1; public interface SimpleFractionInterface.pdf
Interfacepackage PJ1; public interface SimpleFractionInterface.pdfInterfacepackage PJ1; public interface SimpleFractionInterface.pdf
Interfacepackage PJ1; public interface SimpleFractionInterface.pdf
 
Java Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfJava Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdf
 
Make sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdfMake sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdf
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
 
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
 
Qno 1 (d)
Qno 1 (d)Qno 1 (d)
Qno 1 (d)
 
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
 
Labsheet 5
Labsheet 5Labsheet 5
Labsheet 5
 
Java Program- Wrtie a Fraction classGiven the main method of a dri.pdf
Java Program- Wrtie a Fraction classGiven the main method of a dri.pdfJava Program- Wrtie a Fraction classGiven the main method of a dri.pdf
Java Program- Wrtie a Fraction classGiven the main method of a dri.pdf
 
13 Jo P Jan 08
13 Jo P Jan 0813 Jo P Jan 08
13 Jo P Jan 08
 
The following code is an implementation of the producer consumer pro.pdf
The following code is an implementation of the producer consumer pro.pdfThe following code is an implementation of the producer consumer pro.pdf
The following code is an implementation of the producer consumer pro.pdf
 
Functions
FunctionsFunctions
Functions
 
C questions
C questionsC questions
C questions
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docx
 
Vcs15
Vcs15Vcs15
Vcs15
 
import java.util.Scanner;public class Fraction {   instan.pdf
import java.util.Scanner;public class Fraction {    instan.pdfimport java.util.Scanner;public class Fraction {    instan.pdf
import java.util.Scanner;public class Fraction {   instan.pdf
 
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...
 
7 functions
7  functions7  functions
7 functions
 

More from leventhalbrad49439

Which of the following are true when comparing TCPIP to the OSI Ref.pdf
Which of the following are true when comparing TCPIP to the OSI Ref.pdfWhich of the following are true when comparing TCPIP to the OSI Ref.pdf
Which of the following are true when comparing TCPIP to the OSI Ref.pdfleventhalbrad49439
 
What is the reason for having most of the blood volume distributed w.pdf
What is the reason for having most of the blood volume distributed w.pdfWhat is the reason for having most of the blood volume distributed w.pdf
What is the reason for having most of the blood volume distributed w.pdfleventhalbrad49439
 
What is eutectic reaction What is eutectoid reaction What is perife.pdf
What is eutectic reaction What is eutectoid reaction What is perife.pdfWhat is eutectic reaction What is eutectoid reaction What is perife.pdf
What is eutectic reaction What is eutectoid reaction What is perife.pdfleventhalbrad49439
 
What are the possible types of interfund transactions What are.pdf
What are the possible types of interfund transactions What are.pdfWhat are the possible types of interfund transactions What are.pdf
What are the possible types of interfund transactions What are.pdfleventhalbrad49439
 
What are Sociocultural issues when it come to body imageSolutio.pdf
What are Sociocultural issues when it come to body imageSolutio.pdfWhat are Sociocultural issues when it come to body imageSolutio.pdf
What are Sociocultural issues when it come to body imageSolutio.pdfleventhalbrad49439
 
Water can absorb and store a large amount of heat while increasing on.pdf
Water can absorb and store a large amount of heat while increasing on.pdfWater can absorb and store a large amount of heat while increasing on.pdf
Water can absorb and store a large amount of heat while increasing on.pdfleventhalbrad49439
 
True or false1 Anabolism results in increased production of biomas.pdf
True or false1 Anabolism results in increased production of biomas.pdfTrue or false1 Anabolism results in increased production of biomas.pdf
True or false1 Anabolism results in increased production of biomas.pdfleventhalbrad49439
 
The diploid number of the hypothetical animal Geneticus introductus .pdf
The diploid number of the hypothetical animal Geneticus introductus .pdfThe diploid number of the hypothetical animal Geneticus introductus .pdf
The diploid number of the hypothetical animal Geneticus introductus .pdfleventhalbrad49439
 
The Antoine equation often is used to describe vapor pressures lnP .pdf
The Antoine equation often is used to describe vapor pressures lnP .pdfThe Antoine equation often is used to describe vapor pressures lnP .pdf
The Antoine equation often is used to describe vapor pressures lnP .pdfleventhalbrad49439
 
The converson of the English to Christianity began a rich period of .pdf
The converson of the English to Christianity began a rich period of .pdfThe converson of the English to Christianity began a rich period of .pdf
The converson of the English to Christianity began a rich period of .pdfleventhalbrad49439
 
Table 19. Highest Level of Type of organization germ layers .pdf
Table 19. Highest Level of Type of organization germ layers .pdfTable 19. Highest Level of Type of organization germ layers .pdf
Table 19. Highest Level of Type of organization germ layers .pdfleventhalbrad49439
 
Question 12 (5 points)The reason that mitosis can result in the pr.pdf
Question 12 (5 points)The reason that mitosis can result in the pr.pdfQuestion 12 (5 points)The reason that mitosis can result in the pr.pdf
Question 12 (5 points)The reason that mitosis can result in the pr.pdfleventhalbrad49439
 
peripheral circuit functions built-in to the HC12 microcontroller, t.pdf
peripheral circuit functions built-in to the HC12 microcontroller, t.pdfperipheral circuit functions built-in to the HC12 microcontroller, t.pdf
peripheral circuit functions built-in to the HC12 microcontroller, t.pdfleventhalbrad49439
 
Mendez Corporation has 10,000 shares of its $100 par value, 7 percen.pdf
Mendez Corporation has 10,000 shares of its $100 par value, 7 percen.pdfMendez Corporation has 10,000 shares of its $100 par value, 7 percen.pdf
Mendez Corporation has 10,000 shares of its $100 par value, 7 percen.pdfleventhalbrad49439
 
If the dpy-11 and unc-31 genes are linked on the same chromosome, how.pdf
If the dpy-11 and unc-31 genes are linked on the same chromosome, how.pdfIf the dpy-11 and unc-31 genes are linked on the same chromosome, how.pdf
If the dpy-11 and unc-31 genes are linked on the same chromosome, how.pdfleventhalbrad49439
 
How does a wave formation influence the resultant waveSolution.pdf
How does a wave formation influence the resultant waveSolution.pdfHow does a wave formation influence the resultant waveSolution.pdf
How does a wave formation influence the resultant waveSolution.pdfleventhalbrad49439
 
How are health services paid for Provide a definition for the term .pdf
How are health services paid for Provide a definition for the term .pdfHow are health services paid for Provide a definition for the term .pdf
How are health services paid for Provide a definition for the term .pdfleventhalbrad49439
 
Given the information regarding mitosis and meiosis, clearly and con.pdf
Given the information regarding mitosis and meiosis, clearly and con.pdfGiven the information regarding mitosis and meiosis, clearly and con.pdf
Given the information regarding mitosis and meiosis, clearly and con.pdfleventhalbrad49439
 
First, look to determine what is the earliest era that fossils have .pdf
First, look to determine what is the earliest era that fossils have .pdfFirst, look to determine what is the earliest era that fossils have .pdf
First, look to determine what is the earliest era that fossils have .pdfleventhalbrad49439
 
Figure out and write down a definition of a translation that does no.pdf
Figure out and write down a definition of a translation that does no.pdfFigure out and write down a definition of a translation that does no.pdf
Figure out and write down a definition of a translation that does no.pdfleventhalbrad49439
 

More from leventhalbrad49439 (20)

Which of the following are true when comparing TCPIP to the OSI Ref.pdf
Which of the following are true when comparing TCPIP to the OSI Ref.pdfWhich of the following are true when comparing TCPIP to the OSI Ref.pdf
Which of the following are true when comparing TCPIP to the OSI Ref.pdf
 
What is the reason for having most of the blood volume distributed w.pdf
What is the reason for having most of the blood volume distributed w.pdfWhat is the reason for having most of the blood volume distributed w.pdf
What is the reason for having most of the blood volume distributed w.pdf
 
What is eutectic reaction What is eutectoid reaction What is perife.pdf
What is eutectic reaction What is eutectoid reaction What is perife.pdfWhat is eutectic reaction What is eutectoid reaction What is perife.pdf
What is eutectic reaction What is eutectoid reaction What is perife.pdf
 
What are the possible types of interfund transactions What are.pdf
What are the possible types of interfund transactions What are.pdfWhat are the possible types of interfund transactions What are.pdf
What are the possible types of interfund transactions What are.pdf
 
What are Sociocultural issues when it come to body imageSolutio.pdf
What are Sociocultural issues when it come to body imageSolutio.pdfWhat are Sociocultural issues when it come to body imageSolutio.pdf
What are Sociocultural issues when it come to body imageSolutio.pdf
 
Water can absorb and store a large amount of heat while increasing on.pdf
Water can absorb and store a large amount of heat while increasing on.pdfWater can absorb and store a large amount of heat while increasing on.pdf
Water can absorb and store a large amount of heat while increasing on.pdf
 
True or false1 Anabolism results in increased production of biomas.pdf
True or false1 Anabolism results in increased production of biomas.pdfTrue or false1 Anabolism results in increased production of biomas.pdf
True or false1 Anabolism results in increased production of biomas.pdf
 
The diploid number of the hypothetical animal Geneticus introductus .pdf
The diploid number of the hypothetical animal Geneticus introductus .pdfThe diploid number of the hypothetical animal Geneticus introductus .pdf
The diploid number of the hypothetical animal Geneticus introductus .pdf
 
The Antoine equation often is used to describe vapor pressures lnP .pdf
The Antoine equation often is used to describe vapor pressures lnP .pdfThe Antoine equation often is used to describe vapor pressures lnP .pdf
The Antoine equation often is used to describe vapor pressures lnP .pdf
 
The converson of the English to Christianity began a rich period of .pdf
The converson of the English to Christianity began a rich period of .pdfThe converson of the English to Christianity began a rich period of .pdf
The converson of the English to Christianity began a rich period of .pdf
 
Table 19. Highest Level of Type of organization germ layers .pdf
Table 19. Highest Level of Type of organization germ layers .pdfTable 19. Highest Level of Type of organization germ layers .pdf
Table 19. Highest Level of Type of organization germ layers .pdf
 
Question 12 (5 points)The reason that mitosis can result in the pr.pdf
Question 12 (5 points)The reason that mitosis can result in the pr.pdfQuestion 12 (5 points)The reason that mitosis can result in the pr.pdf
Question 12 (5 points)The reason that mitosis can result in the pr.pdf
 
peripheral circuit functions built-in to the HC12 microcontroller, t.pdf
peripheral circuit functions built-in to the HC12 microcontroller, t.pdfperipheral circuit functions built-in to the HC12 microcontroller, t.pdf
peripheral circuit functions built-in to the HC12 microcontroller, t.pdf
 
Mendez Corporation has 10,000 shares of its $100 par value, 7 percen.pdf
Mendez Corporation has 10,000 shares of its $100 par value, 7 percen.pdfMendez Corporation has 10,000 shares of its $100 par value, 7 percen.pdf
Mendez Corporation has 10,000 shares of its $100 par value, 7 percen.pdf
 
If the dpy-11 and unc-31 genes are linked on the same chromosome, how.pdf
If the dpy-11 and unc-31 genes are linked on the same chromosome, how.pdfIf the dpy-11 and unc-31 genes are linked on the same chromosome, how.pdf
If the dpy-11 and unc-31 genes are linked on the same chromosome, how.pdf
 
How does a wave formation influence the resultant waveSolution.pdf
How does a wave formation influence the resultant waveSolution.pdfHow does a wave formation influence the resultant waveSolution.pdf
How does a wave formation influence the resultant waveSolution.pdf
 
How are health services paid for Provide a definition for the term .pdf
How are health services paid for Provide a definition for the term .pdfHow are health services paid for Provide a definition for the term .pdf
How are health services paid for Provide a definition for the term .pdf
 
Given the information regarding mitosis and meiosis, clearly and con.pdf
Given the information regarding mitosis and meiosis, clearly and con.pdfGiven the information regarding mitosis and meiosis, clearly and con.pdf
Given the information regarding mitosis and meiosis, clearly and con.pdf
 
First, look to determine what is the earliest era that fossils have .pdf
First, look to determine what is the earliest era that fossils have .pdfFirst, look to determine what is the earliest era that fossils have .pdf
First, look to determine what is the earliest era that fossils have .pdf
 
Figure out and write down a definition of a translation that does no.pdf
Figure out and write down a definition of a translation that does no.pdfFigure out and write down a definition of a translation that does no.pdf
Figure out and write down a definition of a translation that does no.pdf
 

Recently uploaded

The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfcupulin
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MysoreMuleSoftMeetup
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 

Recently uploaded (20)

The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 

Write a C++ program which create a class for working with mixed frac.pdf

  • 1. Write a C++ program which create a class for working with mixed fractions. MUST BE MIXED, NOT IMPROPER. GIVEN: The main. class Fraction { public: Fraction(int = 1, int = 1, int = 1); void printData(); void add(Fraction, Fraction); void sub(Fraction, Fraction); void mult(Fraction, Fraction); void divide(Fraction, Fraction); Fraction recip(); void reduce(); private: int whole, num, den; }; int main() { Fraction f1(8, 12, 14), f2(3, 4, 6), sum, diff, prod, quo; cout << "The fractions are " << endl; f1.printData(); cout << " and "; f2.printData(); cout << endl << endl; sum.add(f1, f2); diff.sub(f1, f2); prod.mult(f1, f2); quo.divide(f1, f2); cout << "Sum is "; sum.printData(); cout << endl << endl; cout << "Difference is "; diff.printData(); cout << endl << endl; cout << "Product is "; prod.printData();
  • 2. cout << endl << endl; cout << "Quotient is "; quo.printData(); cout << endl << endl; f1.recip(); f2.recip(); cout << "The reciprocals are "; f1.printData(); cout << " "; f2.printData(); cout << endl << endl; system("PAUSE"); return 0; } Output should have MIXED FRACTIONS ONLY. Not improper fractions. Solution PROGRAM CODE: /* * main.cpp * * Created on: 31-Oct-2016 * Author: kaju */ #include using namespace std; class Fraction { public: Fraction(int = 1, int = 1, int = 1); void printData(); void add(Fraction, Fraction); void sub(Fraction, Fraction); void mult(Fraction, Fraction); void divide(Fraction, Fraction); Fraction recip();
  • 3. void reduce(); private: int whole, num, den; }; void Fraction::reduce() { while(num%2 == 0 && den%2 == 0) { num = num/2; den = den/2; } while(num%3 == 0 && den%3 == 0) { num = num/3; den = den/3; } while(num%5 == 0 && den%5 == 0) { num = num/5; den = den/5; } } Fraction::Fraction(int whole, int num, int den) { this->den = den; this->whole = whole; this->num = num; reduce(); } void Fraction::printData() { if(whole == 0) cout<