Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //zadanie 1
- #include "std_lib_facilities.hpp"
- int main()
- {
- string s = "Goodbye, cruel world! ";
- cout << s << '\n';
- }
- //zadanie 2
- #include "std_lib_facilities.hpp"
- int main()
- {
- int mile;
- cout << "Podaj ilość mil:";
- cin >> mile;
- cout << mile << " mila/mil/mile to " << mile*1.609 << "kilometrów.";
- }
- // zadanie 3: Wykonać "Exercise 4 oraz 5" ze strony 86 w książce.
- // 4. Write a program that prompts the user to enter two integer values. Store
- // these values in int variables named val1 and val2. Write your program to
- // determine the smaller, larger, sum, difference, product, and ratio of these
- // values and report them to the user.
- // 5. Modify the program above to ask the user to enter floating-point values
- // and store them in double variables. Compare the outputs of the two pro-
- // grams for some inputs of your choice. Are the results the same? Should
- // they be? What’s the difference?
- #include "std_lib_facilities.hpp"
- int main()
- {
- int val1;
- int val2;
- cin>>val1;
- cin>>val2;
- if (val1 > val2) cout << val1 << " > " << val2;
- else cout << val1 << " < " << val2 << "\n";
- cout << val1 << " + " << val2 << " = " << val1+val2 << "\n";
- cout << val1 << " - " << val2 << " = " << val1-val2 << "\n";
- cout << val1 << " * " << val2 << " = " << val1*val2 << "\n";
- cout << val1 << " / " << val2 << " = " << val1/val2 << "\n";
- }
- int main()
- {
- double val1;
- double val2;
- cin>>val1;
- cin>>val2;
- if (val1 > val2) cout << val1 << " > " << val2;
- else cout << val1 << " < " << val2 << "\n";
- cout << val1 << " + " << val2 << " = " << val1+val2 << "\n";
- cout << val1 << " - " << val2 << " = " << val1-val2 << "\n";
- cout << val1 << " * " << val2 << " = " << val1*val2 << "\n";
- cout << val1 << " / " << val2 << " = " << val1/val2 << "\n";
- }
- // zadanie 5: Wykonać "Exercise 10" ze strony 86 w książce.
- // Write a program that takes an operation followed by two operands and
- // outputs the result. For example:
- // + 100 3.14
- // * 4 5
- // Read the operation into a string called operation and use an
- // if-statement to figure out which operation the user wants, for example,
- // if (operation=="+"). Read the operands into variables of type double.
- // Implement this for operations called +, –, *, /, plus, minus, mul, and div
- // with their obvious meanings.
- #include "std_lib_facilities.hpp"
- int main()
- {
- string operation;
- double val1{0},val2{0};
- cin >> operation >> val1 >> val2;
- if(operation == "+") {
- cout << val1+val2 << "\n";
- }
- if(operation == "-") {
- cout << val1-val2 << "\n";
- }
- if(operation == "*") {
- cout << val1*val2 << "\n";
- }
- if(operation == "/") {
- cout << val1/val2 << "\n";
- }
- if(operation == "plus") {
- cout << val1+val2 << "\n";
- }
- if(operation == "minus") {
- cout << val1-val2 << "\n";
- }
- if(operation == "mul") {
- cout << val1*val2 << "\n";
- }
- if(operation == "div") {
- cout << val1/val2 << "\n";
- }
- cout << "end\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement