Essay/Term paper: Fractable.cpp

Essay, term paper, research paper:  High School Essays

Free essays available online are good but they will not follow the guidelines of your particular writing assignment. If you need a custom term paper on High School Essays: FracTable.cpp, you can hire a professional writer here to write you a high quality authentic essay. While free essays can be traced by Turnitin (plagiarism detection program), our custom written essays will pass any plagiarism test. Our writing service will save you time and grade.

//FracTable



#include <iostream>

#include <cmath>

#include <conio.h> //required for getch()

#include <iomanip> //required for setw()

using namespace std;



class fraction //fraction class

{

private:

int num,den;

public:



fraction(): num(0),den(0){}



fraction(int n,int d):num(n),den(d) {}



void display() {cout<<num<<"/";cout.setf(ios::left);cout<<setw(4)<<den;}





fraction mult(fraction&, fraction&);



void dispheader()

{cout <<num <<"/";cout.setf(ios::left);cout<<setw(4)<<den;}



void lowterms();



};





//----------------------Source copy from textbook----------------------------





void fraction::lowterms() // Change ourself to lowest terms

{

long tnum, tden, temp, gcd;



tnum = labs(num); // use non-negative copies

tden = labs(den); // (needs cmath)



if(tden == 0) // check for 0/n

{

cout << "Illegal fraction: division by 0"; exit(1);

}

else if(tnum==0) //check for 0/n

{

num = 0; den = 1; return;

}



//This 'while' loop finds the gcd of tnum tden



while(tnum != 0)

{

if(tnum < tden) // ensure numerator larger

{

temp = tnum; tnum = tden; tden = temp; //swam them

}

tnum = tnum - tden; // subtract them

}

gcd = tden; // this is greates comon divisor

num = num / gcd; // divide both num and den by gcd

den = den / gcd; // to reduce frac to lowest terms

}





//-----------------------End of source copy from textbook-------------------



int get_den() //get denominator from user

{



int valid =2;

int denom;

cout<< "Enter a denominator:a ";

cin>>denom; cout<<endl;

if (denom < valid)

do //loop until valid entry

{

cout<< "Invalid entry. Try again."<<endl;

cout<< "Enter a denominator:a " ;

cin>> denom; cout<<endl;

}

while(denom < valid);



return denom;

}

/*----------------------------------------------------------------*/

fraction fraction::mult(fraction& x,fraction& y)

{



fraction temp;



temp.num = x.num * y.num;

temp.den = x.den * y.den;



return temp;

}

/*----------------------------------------------------------------*/

int main()

{



int atemp,btemp,din;

int headmax(8);

int dashmax(7);







din=(get_den());

cout<<setw(headmax)<<" ";





for (atemp=1; atemp < din ; atemp++)

{

fraction x(atemp,din);

x.lowterms();

x.dispheader();



}

cout <<endl;

for (int temp = 1; temp <(din*dashmax); temp++)

{

cout<<"-";

}







for (atemp=1; atemp < din ; atemp++)

{

fraction x(atemp,din);

cout<<endl;



if (atemp < din)

{

x.lowterms();

x.display();

cout<<"| ";

}

for (btemp=1; btemp < din; btemp++)

{

fraction y(btemp,din);



fraction z= z.mult(x,y);



z.lowterms();

z.display();

}





}











cout<< endl<< "Press any key to terminate program.a";

getch(); //keep window open until key pressed



return 0;

}



















 

Excellent work, highly recommended
Apo, New York, United States
Writer 8700 is excellent. He helped me document all the references and is very professional. I would not recommend writer 6958 because she is not reliable and copied everything from writer 8700. Writer 8700 is very professional and I recommend the writer highly. I would recommend that the writers be more specific about references and web sites that they use. These need to be documented in the essay \"Works cited\" because otherwise the client does not know where the citations came from.
West Roxbury, Massachusetts, United States
The writer did a very good representation. He or she wrote very elegant.
Riverside, Ohio, United States
I want to thank you for the assistance with this project. I will use the site in the future for projects I need to complete. great work
Coraopolis, Pennsylvania, United States
Only competent & proven writers
Original writing — no plagiarism
Our papers are never resold or reused, period
Satisfaction guarantee — free unlimited revisions
Client-friendly money back guarantee
Total confidentiality & privacy
Guaranteed deadlines
Live Chat & 24/7 customer support
All academic and professional subjects
All difficulty levels
12pt Times New Roman font, double spaced, 1 inch margins
The fastest turnaround in the industry
Fully documented research — free bibliography guaranteed
Fax (additional info): 866-332-0244
Fax (additional info): 866-308-7123
Live Chat Support
Need order related assistance?—Click here to submit a inquiry
© Dreamessays.com. All Rights Reserved.
Dreamessays.com is the property of MEDIATECH LTD