473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

somebody help, time is limited till 10pm

9
ok i have the following c++ and need help to develope a function of the following description :

void addRational(int& ansNum, int& ansDenom)

This function will get 2 rational numbers from the user by calling getRational(), addsthose values and sets the result in ansNum (answer numerator) and ansDenom. It finally
calls displayRational to display the answer.

now i have created the getRational and displayFunction() , i just need to create the function body of addRational(). In my case it is the case 5: on the switch function.


so here is my c++, of what i have so far:

#include<iostream> //Needed for cout and cin
using namespace std;
void menu(); //Menu-function prototype
void getRational(int&,int&); //Function1 protype
void displayRational(int&,int&);
void addRational(int&,int&);
void decimalEquivalent(int&, int&);
int main(){

//Declare variables
int choice1,x,y;
static int numer;
static int denom;

do{ // Reiterates switch command until exited

menu();//Call function menu for menu

//Prompt the user for menu choice
cout<<endl<< "Choose one of the option listed above"<<endl;
cin>>choice1;


switch(choice1){

case 0: cout<<endl<<endl<<"The program will now exit"<<endl<<endl;
exit(1);
break;
case 1: getRational(numer,denom);//Prompts the user to input numerator and denominator
break;

case 2:
{ if(numer<=0 || denom<=0)//Prompt user to input rational
getRational(numer,denom);
displayRational(numer,denom);//Displays the Rational
break;

}
case 3: addRational(numer,denom);
break;



}

}while(choice1!=0);



return 0;
}

void menu()//Menu Function--displays main menu
{
cout<<endl<<endl<<"1) GetRational "<<endl<<"2) Display Rational "<<endl<<"3) Add Rational "<<endl;
cout<<"4) Subtract Rational "<<endl<<"5) Decimal Equivalent "<<endl<<"0) Exit "<<endl<<endl<<endl;

return;
}

void getRational(int& numer, int& denom)//This function prompts user for inputs of numerator and denominator.
{

cout<<endl<<" Please enter the numerator and then the denominator: "<<endl;
cin>>numer>>denom;

return;

}
void displayRational(int& numer, int& denom)
{
cout<<"Your number in rational form is : ";
cout<<numer<<"/"<<denom<<endl;


return;
}
void addRational(int& ansNum, int& ansDenom){

return;
}



void decimalEquivalent(int& numer, int& denom)
{
cout<<"The decimial equivalent of your rational is :";
cout<<(double)numer/denom<<endl;
return;
}
Nov 2 '08 #1
2 1296
ashitpro
542 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. void addRational(int &ansNum,int &ansDeno)
  2. {
  3.     int firstNum,firstDenom,secondNum,secondDenom;
  4.     getRational(firstNum,firstDenom);
  5.     getRational(secondNum,secondDenom);
  6.     ansNum = <snipped>;
  7.     ansDenom = <snipped>;
  8. }
  9.  
This should work for you....
Resulted rational number is not in normal form. i.e. You must implement logic for reducing rational number, Of course if needed.

Regards,
Ash
Nov 3 '08 #2
Banfa
9,065 Expert Mod 8TB
README,

Do you know how to add fractions? Can you add 1/3 + 1/5 on paper without resorting to using a calculator?

If not then I suggest you start by reading this which will explain how addition of fractions works. You will need to follow the links at the bottom of the page to learn how to combine the denominators.

Having read that (or if you can already do the sum I gave earlier) then examine how you add 2 fractions and write a computer algorithm that does the same thing.
Nov 3 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Brian | last post by:
I have 4 sites sharing an account on a server that is in the US Eastern time zone. 3 of those sites are for businesses/persons who live in the same time zone, but one is for a restaurant in the US...
1
by: Gerry | last post by:
Help needed with this: I have had a guestbook-page in Europe and will now have to move it to a US based-server. This makes the time-function showing time 6 hours wrong. The time should be GMT...
4
by: Gerry | last post by:
As I'm not a PHP-prgrammer at all, I just need Help with this: I have had a guestbook-page in Europe and will now have to move it to a US based-server. This makes the time-function showing time...
6
by: lostinspace | last post by:
After four+ years of using FrontPage in a limited capacity and having created over 600 pages on my sites, I've finally (at least for the most part) abandoned FP, to begin the process of converting...
13
by: Mike | last post by:
Normally scheduling a job is a very elementary operation but for some hidden reason I've been unable to schedule a job which runs on a 28 day cycle, even though I have at least 16 other jobs...
4
by: Chris | last post by:
Hello, I am attempting to build a MS SQL query that will return data from "today"; today being current day 8:00AM-10:00PM today. My goal is to return the data from a table that is written to...
2
by: le0 | last post by:
Hello Guys, I have this dropdown box and the options is TimeShift (6a-2pm, 2p-10p, 10p-6a ), im getting this data in a table (Acess DB) . My problem is how can i display (option selected) the...
10
by: shakefu | last post by:
I'm new to python and I was wondering if there are any intelligent date/time parsing modules out there. I've looked at strptime (or whichever it is) and mxDateTime from the eGenix package. I need...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.