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, 01: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, 08: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, 11:35 AM
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.


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




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

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




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 9 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek