s1.fnEnterFractionValue();
s2.fnDisplayFraction(): This function prompts the user to enter 1 to see the fraction in fraction format or 2 to see to see the fraction in a decimal format.
I compile the program without any problems BUT only the first function got executed…WHAT I MISSING HERE? I am new at this
/******************************************************************************
This main function contains two functions that are declare
in the fraction_class:
fnEnterFractionValue()
fnDisplayFraction()
fnEnterFractionValue: Prompt the user to enter the value of the numerator
and denominator
fnDisplayFraction: If the User enter 1: display the fraction as 1/4
2 : display the fraction as a decimal
0.25
*********************************************************************************/
#include "stdafx.h"
#include <iostream>
#include "fraction_class.h"
#include <iomanip>
using namespace std;
/*--------------------------------------------------------------------------
Name: main
Purpose:
--------------------------------------------------------------------------*/
int main()
{
fraction_class s1,s2; // defines an object of class fraction_class.h
{
s1.fnEnterFractionValue();
cout << " *****************************************************************************"<<endl;
cout << " * Please Enter the numerator and the denominator for the fraction, *" <<endl;
cout << " * If you entered 0 as denominator the program will display *" <<endl;
cout << " * and error and will allow you to continue entering numbers until you enter*" <<endl;
cout << " * a number that is greater than o **ENJOY** *" <<endl;
cout << " ****************************************************************************" <<endl;
cout << " " <<endl;
cout << "Enter Numerator : ";
cin >> s1.num1,
cout << "Enter denominator : ";
cin >> s1.dem1; cout << '\n';
if (s1.num1 == 0 ||s1.dem1 == 0)
{
cout << "I can not divide by 0. Please enter a number > 0: " <<endl;
cin>> s1.dem1;
}
s2.fnDisplayFraction();
return 0;
} // end of s1.fnEnterFractionValue()
s2.fnDisplayFraction();
{
//int numb1;
//int nresult1;
double result;
cout << " *****************************************************************************"<<endl;
cout << " * Please Enter number 1 if you want to see the fraction in a fraction format " <<endl;
cout << " * Enter number 2 if you want to see the fraction as a decimal " <<endl;
cout << " ****************************************************************************" <<endl;
cout << " " <<endl;
cout << "Enter Number, Remember 1 OR 2: ";
cin >> s2.numb1;cout << '\n';
if (s2.numb1 == 1)
cout << "You Just Entered: "; cout << s2.num1, cout << " / " , cout << s2.dem1;
cout << '\n';
cout << " ********************************************** ";
if (s2.numb1 == 2)
result = s2.num1 / s2.dem1;
cout << "You Just Entered: "; cout << result;
return 0;
system ("pause");
}
}; // end of main
Here is the CLASS: (I am doing other things with this class, it works for otherf programs
// fraction_class.h
// Fractions calculator
// This program define a class called func_cal (function calculater)
// This programs contains public data that hold integers the num1,num2
// and dem1 and dem2.
// The program also contains the following public members fuctions
// instructUser(),GetData(), doDivideZero
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class fraction_class // define the class
{
public :
int num1,num2,
dem1,dem2;
int nMaxDenominator, m_Denominator;;
int numb1, nresult1;
double result;
//Function to get InstrUser
void InstructUser()
{ }
// Function Get Data
int GetData()
{return 0; }
// Function to Get Data for the Array Fractions
int GetDataArrFra()
{return 0;}
//Function to calculate MaxDenoninator in the Array Function
int FindMaxDeno()
{return 0;}
int fnEnterFractionValue()
{ return 0;}
int fnDisplayFraction()
{return 0;}
};

New Topic/Question
Reply




MultiQuote




|