ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 8th, 2009, 02:00 PM
potts73 potts73 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 2 potts73 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 9 sec
Reputation Power: 0
Question ASP 1.0 - Needing some help with my C++ program.

Hey guys I'm haveing trouble with a c++ program I'm trying to creat it has to deal with fractions and a menu to choose to add subtract multiply and dived or just to simply exit. Also i need to simply the fractions to the lowest form. It compiles but doesnt simplify or actually choose the right number you input where the menu part is. I'll place a copy of it on the bottom of this if you can help it would be very appreciated.
Thank you.

#include <iostream>
#include <conio.h>
#include <iomanip>
using namespace std;

class fracType
{
private:
int numerator, denominator, n1, n2, d1, d2;
void simplify ();

public:
fracType (int = 2, int = 3);
~fracType(){cout << "\nDestructor is Running";}
void add (const fracType&, const fracType&);
void subtract (const fracType&, const fracType&);
void multiply (const fracType&, const fracType&);
void divide (const fracType&, const fracType&);
void showFrac () const ;
void setFrac () ;
};


fracType::fracType(int n, int d)
{
numerator = n;
denominator = d;
}

void fracType::add(const fracType& frac1, const fracType& frac2)
{
numerator = (frac1.n1 * frac2.d2 + frac2.n2 * frac1.d1);

denominator = (frac1.d1 * frac2.d2);
}

void fracType::subtract(const fracType & frac1, const fracType & frac2)
{
numerator = (frac1.n1 * frac2.d2 - frac2.n2 * frac1.d1);

denominator = (frac1.d1 * frac2.d2);
}

void fracType::multiply(const fracType & frac1, const fracType & frac2)
{
numerator = (frac1.n1 * frac2.n2);

denominator = (frac1.d1 * frac2.d2);
}
void fracType::divide(const fracType & frac1, const fracType & frac2)
{
numerator = (frac1.n1 * frac2.d2);

denominator = (frac1.d1 * frac2.n2);
}

void fracType::setFrac()
{
cout << "Enter a Numerator and a Denominator of a Fraction: ";
cin >> n1 >> d1;

cout << "\n\nEnter another Numerator and a Denominator of a Fraction: ";
cin >> n2 >> d2;
}
void fracType::showFrac() const
{
cout << "The Option you have choosen has Equaled: "
<< numerator << "/" << denominator;
}


int main()
{
char c;
fracType x0, x1, ADD, SUB, MULT, DIV;

x1.setFrac();

cout << setw(30) << "Fraction Calculation Menu: \n";

cout << setw(5) << "1 -- ADDITION \n"
<< setw(5) << "2 -- SUBTRACTION \n"
<< setw(5) << "3 -- MULTIPLICATION \n"
<< setw(5) << "4 -- DIVISION \n"
<< setw(5) << "5 -- EXIT \n"
<< setw(5) << "Enter a Number of 1-5: ";
cin >> c;

if(1)
{
ADD.add(x0,x1);
ADD.showFrac();
}
else if (2)
{
SUB.subtract(x0,x1);
SUB.showFrac();
}
else if (3)
{
MULT.multiply(x0,x1);
MULT.showFrac();
}
else if (c = 4)
{
DIV.divide(x0,x1);
DIV.showFrac();
}
else if (5)
{
cout << "Good Bye";
_getch();
}
else
{
x0.showFrac();
}

_getch ();
return 0;
}

Reply With Quote
  #2  
Old May 11th, 2009, 09:55 PM
potts73 potts73 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 2 potts73 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 9 sec
Reputation Power: 0
Question still cant figure out what im doing wrong plz help?

Hey everyone thats looking at this.. ive been working on it all weekend and i still cant figure it out.. plz if u can help me id really apprecait it.. please help ty for all thats looking at my forum though..

Reply With Quote
  #3  
Old May 12th, 2009, 12:35 PM
Daderk Daderk is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2009
Posts: 19 Daderk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 35 m 56 sec
Reputation Power: 0
yo

you were close, just needed to make things match up.

#include <iostream>
#include <conio.h>
#include <iomanip>
using namespace std;

class fracType
{
private:
int numerator, denominator, n, d, fn, fd, wn;
void simplify ();

public:
fracType (int = 0, int = 1);
~fracType(){cout << "\nDestructor is Running";}
void add (const fracType&, const fracType&);
void subtract (const fracType&, const fracType&);
void multiply (const fracType&, const fracType&);
void divide (const fracType&, const fracType&);
void showFrac () const ;
void setFrac () ;
};


fracType::fracType(int numerator, int denominator)
{
fn = numerator;
fd = denominator;
}

void fracType::add(const fracType& frac1, const fracType& frac2)
{
fn = (frac1.n * frac2.d + frac2.n * frac1.d);

fd = (frac1.d * frac2.d);
}

void fracType::subtract(const fracType & frac1, const fracType & frac2)
{
fn = (frac1.n * frac2.d - frac2.n * frac1.d);

fd = (frac1.d * frac2.d);
}

void fracType::multiply(const fracType & frac1, const fracType & frac2)
{
fn = (frac1.n * frac2.n);

fd = (frac1.d * frac2.d);
}
void fracType::divide(const fracType & frac1, const fracType & frac2)
{
fn = (frac1.n * frac2.d);

fd = (frac1.d * frac2.n);
}

void fracType::setFrac()
{
char x;
cout << "Enter a Numerator and a Denominator of a Fraction: ";
cin >> n >> x >> d;

}
void fracType::showFrac() const
{
cout << "The Option you have choosen has Equaled: "
<< fn << "/" << fd;
}




int main()
{
int c;
fracType x0, x1, ADD, SUB, MULT, DIV;



cout << setw(30) << "Fraction Calculation Menu: \n";

cout << setw(5) << "1 -- ADDITION \n"
<< setw(5) << "2 -- SUBTRACTION \n"
<< setw(5) << "3 -- MULTIPLICATION \n"
<< setw(5) << "4 -- DIVISION \n"
<< setw(5) << "5 -- EXIT \n"
<< setw(5) << "Enter a Number of 1-5: ";
cin >> c;
x0.setFrac();
x1.setFrac();
if(c == 1)
{
ADD.add(x0,x1);
ADD.showFrac();
}
else if (c == 2)
{
SUB.subtract(x0,x1);
SUB.showFrac();
}
else if (c == 3)
{
MULT.multiply(x0,x1);
MULT.showFrac();
}
else if (c == 4)
{
DIV.divide(x0,x1);
DIV.showFrac();
}
else if (c == 5)
{
cout << "Good Bye";
_getch();
}
else
{
cout << "Enter valid menu choice: ";
cin >> c;
}

_getch ();
return 0;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > ASP 1.0 - Needing some help with my C++ program.


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap