Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // File: triArea.cpp
- // Created by: Naeem Shareef
- // Modified by: ?????
- // Modified on: ?????
- /*
- A program to compute and output the area of three triangles:
- First triangle has base 1 and height 5;
- Second triangle has base 4 and height 3;
- Third triangle has base 3 and height 6.
- Each output should be on a separate line.
- */
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- int main() {
- int aInitial(0);
- int aCount(0);
- int bInitial(0);
- int bCount(0);
- int precise(0);
- double logCalc(0);
- int width = 10;
- bool deltaBig = false;
- cout << "Enter start value for base a: ";
- cin >> aInitial;
- cout << "Enter how many base values: ";
- cin >> aCount;
- cout << "Enter start value for b: ";
- cin >> bInitial;
- cout << "Enter how many b values: ";
- cin >> bCount;
- cout << "Enter precision: ";
- cin >> precise;
- cout << endl;
- if (bCount > 10) {
- deltaBig = true;
- }
- cout << "Table starts at logarithm of b = " << bInitial << " with base a = " << aInitial << endl;
- cout << setw(width) << "Log values";
- for (int i = 0; i < bCount; i++) {
- if (i == 0) cout << setw(precise + 3) << "b + " << i;
- else cout << setw(precise + 4) << "b + " << i;
- }
- cout << endl; // Now we start on the a + x vals and do the calculation
- for (int x = 0; x < aCount; x++) {
- if ( x < 10) cout << setw(width-1) << "a + " << x; // Want first col to have width 10 and right justified
- else cout << setw(width-2) << "a + " << x;
- for (int j = 0; j < bCount; j++) {
- // DO CALC HERE
- logCalc = (log10(bInitial + j)) / (log10(aInitial + x));
- if ((j >= 10) && deltaBig) {
- cout << right << fixed << setprecision(precise) << setw(precise + 5) << logCalc;
- }
- else {
- cout << right << fixed << setprecision(precise) << setw(precise + 4) << logCalc;
- }
- if (j < (bCount - 1)) cout << " ";
- }
- cout << endl;
- }
- return 0;
- }
- //10 15 7 14 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement