Visual C++ :: Structures Function - Comparing Two Fraction
Nov 5, 2014
I'm writing a function that compares two fraction. if the fractions are equal it returns 0. If the fraction in the first parameter is less than the fraction in the second parameter it returns a negative number. Otherwise it returns a positive number. in doing so convert the fraction to a floating point number.
typedef struct fracion {
int numo;
int denom;
}fraction;
int compareFractions (fracion, fraction);
I'm having a problem when i convert from fraction to string. When I run my program it runs fine I'm supposed to get an output of the fraction ex (2/5) and the decimal 0.4 the problem is that it does not output the fraction all I get it / and 0.4
the code for converting from fraction to string is the following std::string string; char numerator[100]/* = {0}*/; char denominator[100]/* = {0}*/; _itoa_s(numerator_, numerator, 10); _itoa_s(denominator_, denominator, 10);
I'm writing a function that compares two fraction. if the fractions are equal it returns 0. If the fraction in the first parameter is less than the fraction in the second parameter it returns a negative number. Otherwise it returns a positive number. in doing so convert the fraction to a floating point number.
completing the function to run
typedef struct fracion { int numo; int denom; }fraction;
We're assigned a project working with classes and fractions. My goal is to display a fraction in proper from based on 2 arguments passed to a class member function proper();
My strategy was to utilize the greatest common factor between the 2 arguements, then divide both the numerator and denominator by that number and then it would display.
The program actually runs, but only seems to divide the numerator and not the denominator. This in return makes my other class member functions have incorrect comparisons and sums.
Code: #include<iostream> #include<conio.h> class Fraction { friend void compare(Fraction a, Fraction b); friend void sum(Fraction a, Fraction b);
We're designing a new software and we want it to be customizable without code. That, for us, mean we can change the software behaviour without re-writing code. All will be developed using C and .NET.
One of our goals is to have what we are calling "dynamic tables". This means that these database tables may have different fields depending on the customization. We got to know it using high-level ERPs like SAP or CRM's system like VTIGER or even SalesForce. Let me give an example:
CUSTOMER TABLE:
FIELDS: ID, NAME, ADDRESS, PHONE.
This would be the standard Customer Table.
Now, a new customer needs to add FINANCE SCORE and RANKING to the database. We them would like to go to our application (not the database itself) and adding these new fields. After that, all of my input forms and reports would start to show and process these new fields.
I am having a slight issue with the strcmp function. I am comparing string data from two different files. I want the function to output a set of information if the strings are the same and a different set of data if the strings are different. My issue is, the function outputs the data that's the same but not different.
I had an else statement that compared the data if it was NOT equal but it only duplicated the data in the file.
One file is a listing of 100 books with 10 lines of information and an assigned market. The second file is a listing of the markets contained in the books file. However, the books file has a market that is not located in the markets file. The "missing" market is what is not priting or displaying.
I am writing a employee payroll program using structures. My program is running but its only showing some of the data.
HERES MY CODE
Code: #include <iostream> #include <cstdio> #include <fstream> #include <string> #include <iomanip> #include <cstring> using namespace std; const int SZ = 20; // size of arrays to hold scores struct payrollStruct {
[Code] ....
And it doesn't show anything from txt file
Code: 40.0 10.00 A1234 Jane Adams 50.0 10.00 L8765 Mary Lincoln 25.5 10.85 W7654 Martha Washington 52.0 15.75 A9876 John Adams 45.0 25.00 W1235 George Washington
i am having issues converting a fraction to a decimal, i think the code would go in the istream because it is working with input data but i just cant figure it out.
#include <cstdio> #include <string> #include <iostream> using namespace std;
I am trying to create a program that calculates fraction of time remaining when a student leaves during the middle of the semester. I have to use function files here. I am having trouble with the division in function long double tuitionfrac(int, int, int). No matter what numbers are entered, fractime gives an output of 0. I don't understand that.
long double tuitionfrac(int opening, int leaving, int semend) { int lefttime = semend - leaving; cout << "Left time " << lefttime << endl; //for error checking int tottime = semend - opening + 1; cout << "Total time " << tottime << endl; long double fractime = lefttime/tottime; cout << "fractional time " << fractime << endl; //always returns as 0. return fractime; }
I am trying to write a Fraction class and getting the following warning when compiling my code :
Fraction.cpp: In constructor 'Fraction::Fraction(double)': Fraction.cpp:8: warning :converting to 'int' from 'double'
My Fraction.cpp class looks like :
#include "Fraction.h" Fraction::Fraction(int n, int d):num(n),den(d) { cout << This is double param constructor <<endl; } Fraction::Fraction(double d):num(d),den(0)
I have asked a related question before, and it was resolved successfully. In the past, when I wanted to use std::max_element in order to find the maximum element (or even sort by using std::sort) of a vector of structures according to one of the members of the structure, all I had to do was to insert a specially designed comparison function as the third argument of the function std::max::element. But the latter comparison function naturally accepts two arguments internally.
For instance, here is a test program that successfully finds the maximum according to just one member of the structure:
And the output was this, as expected: Maximum element S.a of vector<S> vec is at: 9 [I]max element of vec.a between slot 3 and slot 6 is: 6, and its index is: 6 vec[6].a = 6 [I]max element of vec.a between slot 4 and slot 7 is: 7, and its index is: 7 vec[7].a = 7 [I]max element of vec.a between slot 5 and slot 8 is: 8, and its index is: 8 vec[8].a = 8 [I]max element of vec.a between slot 6 and slot 9 is: 9, and its index is: 9 vec[9].a = 9
However, I now need to search and find an element of vector<myStruct> according to just one member of myStruct, instead of finding the maximum or sorting as before. This presents a problem because the function std::find does not accept such a comparison function as its third argument.
This was the description of the std::find function that I found: find - C++ Reference
Code: template <class InputIterator, class T> InputIterator find (InputIterator first, InputIterator last, const T& val);
I could also find another function called std::find_if, but this only accepts a unary predicate like this: find_if - C++ Reference
Code: template <class InputIterator, class UnaryPredicate> InputIterator find_if (InputIterator first, InputIterator last, UnaryPredicate pred);
And once again this is either inadequate of I don't see how to use it directly, because for the third argument I would like to insert a function that takes two arguments with a syntax like this:
Code: int x=7; std::vector<S>::iterator result; result = std::find(vec.begin(), vec.end(), []( const (int x, const S & S_1) { return ( x == S_1.a ) ; } ) ;
Is there another std function that I can use to make search and find an element according to just one member of myStruct?
Or perhaps there is a clever way to pass two arguments to the unary predicate.
Write a class definition for a Fraction class. Its member fields are num and den, both of type int. The constructor builds the default fraction 1/1. It has the following operations:
void plusEquals(Fraction second); //Adds the second fraction to this fraction like the operator += void minusEquals (Fraction second); //Subtracts the second fraction from this fraction void timesEquals (Fraction second); //Divides this fraction by the second fraction void dividesEquals (Fraction second); // Divides this fraction by the second fraction void reduce(); // Reduces this fraction to lowest terms double todecimal(); //returns the decimal value of this fraction void scan(istream&); //scans a fraction written with a slash as in ¾ void print(ostream&); //prints a fraction using a slash Fraction(); //constructs a default fraction with denominator 1, numerator 0 Fraction(int n, int d); //constructs a fraction given value for num and den
2. Write a menu-driven driver program designed to allow thorough testing of your Fraction class.
error C3867: 'WordParsor::Form1::PutUpfrmIO': function call missing argument list; use '&WordParsor::Form1::PutUpfrmIO' to create a pointer to memberc:userskingc++wordparsorwordparsorForm1.h... and the suggestion fix generate another error.
One person suggested the gcroot<> object wrapper... but I do not know how to modify/declair the function or its argument type.
I'm a novice with C programming and i have to solve an error in the following code. The code works like you enter a password called "uoc" and it shows as OK. But surprisely when you entered another password as "Cambridge" it works fine too.
I think that the problem is in the array declaration but i'm checking resources and no success!
double x=1.00,y=2,z=4; if (y/z||++x) x+=y/z; printf("%f ",x); So (y/z||++x)
is true if at least one expression is true, that is either (y/z)!=0 or (++x)!=0 or both. I wonder how the comparison is done? Is (y/z) be truncated to integer or 0 be promoted to double?
I am trying to make a game where you have a secret code that is coded with colors like ROYG (red,orange,yellow,green) and I am having trouble when it tells you when you have a right color in the right spot or a right color in the wrong spot when you guess a color. How can I change my code under the function int comparearray where it will compare pointers to pointers and not integers and give me the correct number of "almost" and "correct".