Advertisement
Cinestra

Homework3

Apr 14th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. /*
  2.  
  3. Nick Ku PIC10A Intro. to Programming
  4.  
  5. ID: 304491540 Spring 2016
  6.  
  7. Email: cinestra@ucla.edu HW #3
  8.  
  9. Section: 3A
  10.  
  11. Honesty Pledge:
  12.  
  13.  
  14.  
  15. I, Nichokas Ku, pledge that this is my own independent work, which conforms to
  16.  
  17. the guidelines of academic honesty as described in the course syllabus.
  18.  
  19. List of none bugs: None.
  20.  
  21. */
  22.  
  23.  
  24.  
  25. #include<iostream>
  26.  
  27. #include<iomanip>
  28.  
  29. #include <string>
  30.  
  31.  
  32.  
  33. using namespace std;
  34.  
  35.  
  36.  
  37. int main(){
  38.  
  39. int n1;
  40.  
  41. int n2;
  42.  
  43. string first_category;
  44.  
  45. string second_category;
  46.  
  47. cout << "How many in the first category? ";
  48.  
  49. cin >> n1 >> first_category;
  50.  
  51. cout << "How many in the first category? ";
  52.  
  53. cin >> n2 >> second_category;
  54.  
  55.  
  56.  
  57. cout << setw(10) << first_category << setw(10) << n1 << endl;
  58.  
  59. cout << setw(10) << second_category << setw(10) << n2 << endl;
  60.  
  61.  
  62.  
  63. double a;
  64. a = n1;
  65. double b;
  66. b = n2;
  67.  
  68.  
  69.  
  70. double ratio1;
  71. ratio1 = a / b;
  72. double ratio2;
  73. ratio2 = b / a;
  74.  
  75.  
  76.  
  77. string s1;
  78. s1 = first_category + "-to-" + second_category + "ratio";
  79. string s2;
  80. s2 = second_category + "-to-" + first_category + "ratio";
  81.  
  82.  
  83.  
  84. cout << fixed;
  85.  
  86. cout << setprecision(2) << setw(10) << s1 << " " << setw(10) << ratio1 << endl;
  87.  
  88. cout << setprecision(2) << setw(10) << s2 << " " << setw(10) << ratio2 << endl;
  89.  
  90.  
  91.  
  92. system("pause");
  93.  
  94. return 0;
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement