Advertisement
Guest User

zadanka

a guest
Feb 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. //zadanie 1
  2. #include "std_lib_facilities.hpp"
  3. int main()
  4. {
  5. string s = "Goodbye, cruel world! ";
  6. cout << s << '\n';
  7. }
  8.  
  9. //zadanie 2
  10. #include "std_lib_facilities.hpp"
  11. int main()
  12. {
  13. int mile;
  14. cout << "Podaj ilość mil:";
  15. cin >> mile;
  16. cout << mile << " mila/mil/mile to " << mile*1.609 << "kilometrów.";
  17. }
  18.  
  19. // zadanie 3: Wykonać "Exercise 4 oraz 5" ze strony 86 w książce.
  20. // 4. Write a program that prompts the user to enter two integer values. Store
  21. // these values in int variables named val1 and val2. Write your program to
  22. // determine the smaller, larger, sum, difference, product, and ratio of these
  23. // values and report them to the user.
  24. // 5. Modify the program above to ask the user to enter floating-point values
  25. // and store them in double variables. Compare the outputs of the two pro-
  26. // grams for some inputs of your choice. Are the results the same? Should
  27. // they be? What’s the difference?
  28.  
  29. #include "std_lib_facilities.hpp"
  30.  
  31. int main()
  32. {
  33. int val1;
  34. int val2;
  35.  
  36. cin>>val1;
  37. cin>>val2;
  38.  
  39. if (val1 > val2) cout << val1 << " > " << val2;
  40. else cout << val1 << " < " << val2 << "\n";
  41.  
  42.  
  43. cout << val1 << " + " << val2 << " = " << val1+val2 << "\n";
  44. cout << val1 << " - " << val2 << " = " << val1-val2 << "\n";
  45. cout << val1 << " * " << val2 << " = " << val1*val2 << "\n";
  46. cout << val1 << " / " << val2 << " = " << val1/val2 << "\n";
  47. }
  48.  
  49. int main()
  50. {
  51. double val1;
  52. double val2;
  53.  
  54. cin>>val1;
  55. cin>>val2;
  56.  
  57. if (val1 > val2) cout << val1 << " > " << val2;
  58. else cout << val1 << " < " << val2 << "\n";
  59.  
  60.  
  61. cout << val1 << " + " << val2 << " = " << val1+val2 << "\n";
  62. cout << val1 << " - " << val2 << " = " << val1-val2 << "\n";
  63. cout << val1 << " * " << val2 << " = " << val1*val2 << "\n";
  64. cout << val1 << " / " << val2 << " = " << val1/val2 << "\n";
  65. }
  66.  
  67. // zadanie 5: Wykonać "Exercise 10" ze strony 86 w książce.
  68. // Write a program that takes an operation followed by two operands and
  69. // outputs the result. For example:
  70. // + 100 3.14
  71. // * 4 5
  72. // Read the operation into a string called operation and use an
  73. // if-statement to figure out which operation the user wants, for example,
  74. // if (operation=="+"). Read the operands into variables of type double.
  75. // Implement this for operations called +, –, *, /, plus, minus, mul, and div
  76. // with their obvious meanings.
  77.  
  78. #include "std_lib_facilities.hpp"
  79.  
  80. int main()
  81. {
  82. string operation;
  83. double val1{0},val2{0};
  84. cin >> operation >> val1 >> val2;
  85. if(operation == "+") {
  86. cout << val1+val2 << "\n";
  87. }
  88. if(operation == "-") {
  89. cout << val1-val2 << "\n";
  90. }
  91. if(operation == "*") {
  92. cout << val1*val2 << "\n";
  93. }
  94. if(operation == "/") {
  95. cout << val1/val2 << "\n";
  96. }
  97. if(operation == "plus") {
  98. cout << val1+val2 << "\n";
  99. }
  100. if(operation == "minus") {
  101. cout << val1-val2 << "\n";
  102. }
  103. if(operation == "mul") {
  104. cout << val1*val2 << "\n";
  105. }
  106. if(operation == "div") {
  107. cout << val1/val2 << "\n";
  108. }
  109. cout << "end\n";
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement