February 1918

Throw codes calculator created in three popular languages. To create a program in Pascal compiler I used Turbo Pascal 7.0 (run by the Ctrl + F9) to C + +, used the Microsoft Visual Studio 2005 (F5 to compile and confirmation), and the code created in flash Luke Lakes ;) I have already gave a similar code written in the Code:: Blocks - to read I invite him here .

Here you can download the files. Pas. Cpp. Swf and. Html.

VN: F [1.9.3_1094]
Rating: 0.0 / 10 (0 votes cast)
VN: F [1.9.3_1094]
Rating: 0 (from 0 votes)

written by laptopik

October 1928

Sorting is one of the major problems in any programming language. Currently, on average, the most efficient sorting algorithm is QuickSort .
At the beginning, however, we will create your own algorithm. The principle of operation is simple. The program takes each element of the table in turn and compares it with every other element in the table. If you encounter any more than the item is located at the end of the array, converts it to the latter.

  1. # Include <iostream>
  2. using namespace std;
  3. int main () (
  4. / / Fill array declaration and
  5. = { 9 , 412 , 22 , 623 , 666 , 425 , 248589789 , 124 , 4572 , 148589789 } ; // 10 elementów int a [] = (9, 412, 22, 623, 666, 425, 248,589,789, 124, 4572, 148,589,789), / / 10 elements
  6. / / Sort
  7. / / Start the search for the largest number since the end of the array for each element, we step further written
  8. / / Q represents the index of an array element
  9. int q= 9 ; q> 0 ; q– ) { for (int q = 9, q> 0, q-) (
  10. / / Q is reduced, because we omit the verification of the number of which were identified as the biggest earlier, q represents the place where you place the greatest value of this course
  11. / / Variable "largest" stores the index in the array element with the highest value yet found
  12. / / Assume from the outset that this is 0, to start comparing from the beginning, it is the value contained in this element is compared with every
  13. ; int largest = 0;
  14. int d= 0 ; d<=q; d++ ) { for (int d = 0, d <= q, d + +) (
  15. / / Method ", each with each, for a given element, we take every other element of the array, up to q, for q we set in place the highest value found
  16. a [ d ] >a [ najwieksza ] ) najwieksza=d; if (a [d]> a [largest]) largest = d;
  17. / / If the element is greater than that currently stored as the biggest, we improve the index of highest value
  18. )
  19. / / Because the internal forze, overriden the largest found value in the latter part of the process (q)
  20. q ] ; int s = a [q];
  21. =a [ najwieksza ] ; a [q] = a [largest];
  22. = s; a [largest] = s;
  23. )
  24. / / Check
  25. / / Throw the already output sorted array elements
  26. int n= 0 ; i< 10 ; i++ ) cout<<a [ n ] <<endl; for (int n = 0 and <10 i + +) court <<a [n] <<endl;
  27. )

And now the fastest algorithm QuickSort:
It takes as arguments an array, index and index of the first element last element:

  1. int arr [ ] , int left, int right ) { void QuickSort (int arr [], int left, int right) (
  2. int i = left j = right;
  3. int tmp;
  4. left + right ) / 2 ] ; int pivot = arr [(left + right) / 2];
  5. / * Partition * /
  6. i <= j ) { while (i <= j) (
  7. arr [ i ] < pivot ) i++; while (arr [i] <pivot) i + +;
  8. arr [ j ] > pivot ) j–; while (arr [j]> pivot) j;
  9. i <= j ) { if (i <= j) (
  10. ; tmp = arr [i];
  11. = arr [ j ] ; arr [i] = arr [j];
  12. = tmp; arr [j] = tmp;
  13. i + +;
  14. j;
  15. )
  16. );
  17. / * Recursion * /
  18. left < j ) quickSort ( arr, left, j ) ; if (left <j) quicksort (arr, left, j);
  19. i < right ) quickSort ( arr, i, right ) ; if (i <right) QuickSort (arr, i, right);
  20. )

A detailed description of the QuickSort algorithm can be found here .

VN: F [1.9.3_1094]
Rating: 7.5 / 10 (2 votes cast)
VN: F [1.9.3_1094]
Rating: 0 (from 0 votes)

written by Don Daniello \ \ tags: , , ,

October 2003

Good question, such as write a calculator in C + +? Background :)

What is C + +?

C + +, cpp otherwise is a programming language comes from a very old C. This is almost the most powerful programming language, while having the greatest potential. Of course, for example, when writing in assembler, we get a little more efficient program (executing faster operations), but writing it takes much more time. On the other extreme, for example, writing a Visual Basic program will receive less efficient, but less will write it. Currently, it is quite common to use libraries written in assembly language programs written in C + + (so sensitive instructions are executed more quickly.) More about assembler here . We'll take care of C + +.

What you need to write a program in C + +?

A program written in C + + (source code), compile a special program called a compiler to get the output file (executable). After compiling the program could not get the source (a compilation can not be undone), so be sure not to lose the source code, otherwise it will be impossible to modify the program and will have to start from scratch. The code in C + + is the same for all operating systems.

Compiler

A good compiler, the command is now worthy of Code:: Blocks. It is an IDE (Integrated Development Environment -> Integrated Development Environment). Contains the basic library, friendly, kolorujacy text editor and compilers. It is very easy to use. Its home page is http://codeblocks.org , is available on Windows, Linux and MacOS'em.

We write Calculator

Reporting here, converter ready, because the best way of teaching by example. The code is "self-Explained", I put comments in the code, just read.

  1. /*--------+
  2. | Calculatorix |
  3. | V 1.0 |
  4. | By DonDaniello.com |
  5. +--------*/
  6. / / Everything is placed between / * and * / is not taken into account by the compiler, this is called. multiline comment. Each line starting with "/ /" is a commentary jednoliniowym (like this). It is possible to type a comment in the code as below. In this case, the code is taken into account only the "//".
  7. # Include <iostream> / / load the library I / O (input / output)
  8. # Include <cmath> / / load math library
  9. using namespace std; / / use standard libraries to our appeals
  10. // podstawowa funkcja programu, obowiązkowa int main () / / The main function of the program, compulsory
  11. (
  12. int operation, / / integer variable declaration called operation.
  13. double x, y, z, / / declaration of variable numbers of long, niecałkowitych named x, y, z.
  14. / / Note that almost every command ends with a quote.
  15. <<endl<<endl; court <<"Welcome to Calculatorix v 1.0" <<endl <<endl;
  16. / / Endl is a function that returns an end of the line. "Court <<" means to send something to standard output "
  17. true ) { // pętla zawsze spełniona while (true) (/ / loop forever satisfied
  18. / / Send text
  19. <<endl; court <<"Available actions:" <<endl;
  20. <<endl; court <<"1 - Adding" <<endl;
  21. <<endl; court <<"2 - Subtraction" <<endl;
  22. <<endl; court <<"3 - Multiplication" <<endl;
  23. <<endl; court <<"4 - Sharing" <<endl;
  24. <<endl; court <<"5 - Exponentiation" <<endl;
  25. <<endl; court <<"6 - elements" <<endl;
  26. <<endl<<endl; court <<"7 - absolute value" <<endl <<endl;
  27. ; court <<"Select Action to perform:";
  28. cin>> operation, / / we accept the choice of
  29. court <<endl;
  30. dzialanie ) { // wybór działania switch (operation) (/ / selection of action
  31. : // jeśli podano jeden to: case 1: / / if one is given:
  32. ; cin >> x; // cout << endl; court <<"Enter first number:" cin>> x / / court <<endl;
  33. ; cin >> y; // cout << endl; court <<"Enter second number:" cin>> y / / court <<endl;
  34. z = x + y / / count
  35. << y << " rowna sie" << z << "." << endl << endl; court <<x <<"plus" <<y <<"equal to" <<z <<"." <<endl <<endl;
  36. break; / / end if
  37. : case 2:
  38. ; cin >> x; // cout << endl; court <<"Enter first number:" cin>> x / / court <<endl;
  39. ; cin >> y; // cout << endl; court <<"Enter second number:" cin>> y / / court <<endl;
  40. with = x - y;
  41. << y << " rowna sie " << z << "." << endl << endl; court <<x <<"minus" <<y <<"equal to" <<z <<"." <<endl <<endl;
  42. break;
  43. : case 3:
  44. ; cin >> x; // cout << endl; court <<"Enter the first factor:" cin>> x / / court <<endl;
  45. ; cin >> y; // cout << endl; court <<"Enter the second factor:" cin>> y / / court <<endl;
  46. z = x * y;
  47. << y << " rowna sie " << z << "." << endl << endl; court <<x <<"times" <<y <<"equal to" <<z <<"." <<endl <<endl;
  48. break;
  49. : case 4:
  50. ; cin >> x; // cout << endl; court <<"Enter the number of brave:" cin>> x / / court <<endl;
  51. ; cin >> y; // cout << endl; court <<"Enter divisor:" cin>> y / / court <<endl;
  52. z = x / y;
  53. << y << " rowna sie " << z << "." << endl << endl; court <<x <<"divided by" <<y <<"equal to" <<z <<"." <<endl <<endl;
  54. break;
  55. : case 5:
  56. ; cin >> x; // cout << endl; court <<"Enter the might of the foundation:" cin>> x / / court <<endl;
  57. ; cin >> y; // cout << endl; court <<"Enter the exponent:" cin>> y / / court <<endl;
  58. ; z = pow (x, y);
  59. << y << " rowna sie " << z << "." << endl << endl; court <<x <<"squared" <<y <<"equal to" <<z <<"." <<endl <<endl;
  60. break;
  61. : case 6:
  62. ; cin >> x; // cout << endl; court <<"Enter the root of the foundation:" cin>> x / / court <<endl;
  63. ; z = sqrt (x);
  64. << y << " wynosi " << z << "." << endl << endl; court <<"root of" <<y <<"is" <<z <<"." <<endl <<endl;
  65. break;
  66. : case 7:
  67. ; cin >> x; // cout << endl; court <<"Enter the absolute foundation of values:" cin>> x / / court <<endl;
  68. ; z = abs (x);
  69. << y << " wynosi " << z << "." << endl << endl; court <<"The value of the absolute number of" <<y <<"is" <<z <<"." <<endl <<endl;
  70. break;
  71. ; return 0 ; break ; // jeśli podano coś innego, wysyłamy tekst i wyłączamy program default: court <<endl <<"Bye Bye!" return 0; break; / / if given something else, send the text and disable the program
  72. )
  73. )
  74. )

Code no comments for download here: Calculatorix

VN: F [1.9.3_1094]
Rating: 0.0 / 10 (0 votes cast)
VN: F [1.9.3_1094]
Rating: 0 (from 0 votes)

written by Don Daniello \ \ tags: , ,