Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. // File: triArea.cpp
  2. // Created by: Naeem Shareef
  3. // Modified by: ?????
  4. // Modified on: ?????
  5.  
  6. /*
  7. A program to compute and output the area of three triangles:
  8. First triangle has base 1 and height 5;
  9. Second triangle has base 4 and height 3;
  10. Third triangle has base 3 and height 6.
  11.  
  12. Each output should be on a separate line.
  13.  
  14. */
  15.  
  16. #include <iostream>
  17. #include <cmath>
  18. #include <iomanip>
  19. using namespace std;
  20. int main() {
  21. int aInitial(0);
  22. int aCount(0);
  23. int bInitial(0);
  24. int bCount(0);
  25. int precise(0);
  26. double logCalc(0);
  27. int width = 10;
  28. bool deltaBig = false;
  29.  
  30.  
  31. cout << "Enter start value for base a: ";
  32. cin >> aInitial;
  33. cout << "Enter how many base values: ";
  34. cin >> aCount;
  35. cout << "Enter start value for b: ";
  36. cin >> bInitial;
  37. cout << "Enter how many b values: ";
  38. cin >> bCount;
  39. cout << "Enter precision: ";
  40. cin >> precise;
  41. cout << endl;
  42.  
  43. if (bCount > 10) {
  44. deltaBig = true;
  45. }
  46.  
  47. cout << "Table starts at logarithm of b = " << bInitial << " with base a = " << aInitial << endl;
  48. cout << setw(width) << "Log values";
  49. for (int i = 0; i < bCount; i++) {
  50. if (i == 0) cout << setw(precise + 3) << "b + " << i;
  51. else cout << setw(precise + 4) << "b + " << i;
  52. }
  53. cout << endl; // Now we start on the a + x vals and do the calculation
  54. for (int x = 0; x < aCount; x++) {
  55. if ( x < 10) cout << setw(width-1) << "a + " << x; // Want first col to have width 10 and right justified
  56. else cout << setw(width-2) << "a + " << x;
  57. for (int j = 0; j < bCount; j++) {
  58. // DO CALC HERE
  59. logCalc = (log10(bInitial + j)) / (log10(aInitial + x));
  60. if ((j >= 10) && deltaBig) {
  61. cout << right << fixed << setprecision(precise) << setw(precise + 5) << logCalc;
  62. }
  63. else {
  64. cout << right << fixed << setprecision(precise) << setw(precise + 4) << logCalc;
  65. }
  66. if (j < (bCount - 1)) cout << " ";
  67. }
  68. cout << endl;
  69. }
  70. return 0;
  71. }
  72. //10 15 7 14 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement