int main() { init(); // read input cin >> n >> m; for (int i=0;i<m;i++) { for (int j=0;j<3;j++) cin >> e[i][j]; nextE[e[i][0]].push_back(i); nextE[e[i][1]].push_back(i); next[e[i][0]].push_back(e[i][1]); next[e[i][1]].push_back(e[i][0]); } // set up linear program nA=0; for (int i=0;i<n;i++) cycles(i); for (int i=0;i<m;i++) { A[nA][2*i+1]=1; b[nA]=e[i][2]; nA++; c[2*i]=-1; c[2*i+1]=1; } // solve Simplex s = Simplex(A, b, c, nA, 2*m); Fraction f = s.solve(); f = f.neg(); for (int i=0;i<m;i++) f = f.add(Fraction(e[i][2])); cout << f.str() << endl; return 0; }
//------------------------------------------------------------------- // funtion sum // Given an array of objects and it size, it will use the class // function "add" to calculate the summation of the objects. // Parameters: // -- A: the array // -- size: size of the array // Return/post-condition: // -- an object representing the sum as factor //------------------------------------------------------------------- Fraction sum(const Fraction A[], int size) { Fraction r; for(int i = 0; i < size ; i++) r = r.add(A[i]) ; return r; }
Fraction ArrayOfFractions::sum()const { Fraction fracSum = A[0]; for (int idx=1; idx<frac_count; idx++) { fracSum.print(); cout<< " + "; A[idx].print(); cout<< " = "; fracSum = fracSum.add(A[idx]); fracSum.print(); cout<< "\n"; } return fracSum; }
int main() { int n1, d1, n2, d2, op; cout << "Please enter the first fraction: Numerator <Enter> Denominator <Enter>" << endl; cin >> n1 >> d1; cout << "\n\nPlease enter the second fraction: Numerator <Enter> Denominator <Enter>" << endl; cin >> n2 >> d2; Fraction f1(n1, d1); Fraction f2(n2, d2); Fraction answer; cout << "\n\nPlease enter the number of the operation you would like to perform on these fractions:\n" << endl; cout << "1. Addition\n2. Subtraction\n3. Multiplication\n4. Division" << endl; cin >> op; switch (op) { case 1: answer.add(f1, f2); break; case 2: answer.subtract(f1, f2); break; case 3: answer.multiply(f1, f2); break; case 4: answer.divide(f1, f2); break; default: cerr << "You entered an invalid operation\n\n"; system("pause"); exit(0); break; } system("Pause"); return 0; }
int main() { Fraction myFraction; //Addition Test myFraction.setNumDenom(1,2); myFraction.add(1,2); myFraction.print(); //Subtract Test myFraction.setNumDenom(12,16); myFraction.subtract(1,4); myFraction.print(); // Multiply Test myFraction.setNumDenom(25, 100); myFraction.multiply(2, 1); myFraction.print(); //Divide Test myFraction.setNumDenom(1500, 1000); myFraction.divide(1, 2); myFraction.print(); return 0; };