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] written by laptopik 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. # Include <iostream> using namespace std; int main () ( / / Fill array declaration and = { 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 / / Sort / / Start the search for the largest number since the end of the array for each element, we step further written / / Q represents the index of an array element int q= 9 ; q> 0 ; q– ) { for (int q = 9, q> 0, q-) ( / / 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 / / Variable "largest" stores the index in the array element with the highest value yet found / / 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 ; int largest = 0; int d= 0 ; d<=q; d++ ) { for (int d = 0, d <= q, d + +) ( / / 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 a [ d ] >a [ najwieksza ] ) najwieksza=d; if (a [d]> a [largest]) largest = d; / / If the element is greater than that currently stored as the biggest, we improve the index of highest value ) / / Because the internal forze, overriden the largest found value in the latter part of the process (q) q ] ; int s = a [q]; =a [ najwieksza ] ; a [q] = a [largest]; = s; a [largest] = s; ) / / Check / / Throw the already output sorted array elements int n= 0 ; i< 10 ; i++ ) cout<<a [ n ] <<endl; for (int n = 0 and <10 i + +) court <<a [n] <<endl; )
And now the fastest algorithm QuickSort: It takes as arguments an array, index and index of the first element last element: int arr [ ] , int left, int right ) { void QuickSort (int arr [], int left, int right) ( int i = left j = right; int tmp; left + right ) / 2 ] ; int pivot = arr [(left + right) / 2]; / * Partition * / i <= j ) { while (i <= j) ( arr [ i ] < pivot ) i++; while (arr [i] <pivot) i + +; arr [ j ] > pivot ) j–; while (arr [j]> pivot) j; i <= j ) { if (i <= j) ( ; tmp = arr [i]; = arr [ j ] ; arr [i] = arr [j]; = tmp; arr [j] = tmp; i + +; j; ) ); / * Recursion * / left < j ) quickSort ( arr, left, j ) ; if (left <j) quicksort (arr, left, j); i < right ) quickSort ( arr, i, right ) ; if (i <right) QuickSort (arr, i, right); )
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] written by Don Daniello \ \ tags: algorithm , C + + , cpp , sort
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. /*--------+ | Calculatorix | | V 1.0 | | By DonDaniello.com | +--------*/ / / 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 "//". # Include <iostream> / / load the library I / O (input / output) # Include <cmath> / / load math library using namespace std; / / use standard libraries to our appeals // podstawowa funkcja programu, obowiązkowa int main () / / The main function of the program, compulsory ( int operation, / / integer variable declaration called operation. double x, y, z, / / declaration of variable numbers of long, niecałkowitych named x, y, z. / / Note that almost every command ends with a quote. <<endl<<endl; court <<"Welcome to Calculatorix v 1.0" <<endl <<endl; / / Endl is a function that returns an end of the line. "Court <<" means to send something to standard output " true ) { // pętla zawsze spełniona while (true) (/ / loop forever satisfied / / Send text <<endl; court <<"Available actions:" <<endl; <<endl; court <<"1 - Adding" <<endl; <<endl; court <<"2 - Subtraction" <<endl; <<endl; court <<"3 - Multiplication" <<endl; <<endl; court <<"4 - Sharing" <<endl; <<endl; court <<"5 - Exponentiation" <<endl; <<endl; court <<"6 - elements" <<endl; <<endl<<endl; court <<"7 - absolute value" <<endl <<endl; ; court <<"Select Action to perform:"; cin>> operation, / / we accept the choice of dzialanie ) { // wybór działania switch (operation) (/ / selection of action : // jeśli podano jeden to: case 1: / / if one is given: ; cin >> x; // cout << endl; court <<"Enter first number:" cin>> x / / court <<endl; ; cin >> y; // cout << endl; court <<"Enter second number:" cin>> y / / court <<endl; z = x + y / / count << y << " rowna sie" << z << "." << endl << endl; court <<x <<"plus" <<y <<"equal to" <<z <<"." <<endl <<endl; break; / / end if : case 2: ; cin >> x; // cout << endl; court <<"Enter first number:" cin>> x / / court <<endl; ; cin >> y; // cout << endl; court <<"Enter second number:" cin>> y / / court <<endl; with = x - y; << y << " rowna sie " << z << "." << endl << endl; court <<x <<"minus" <<y <<"equal to" <<z <<"." <<endl <<endl; break; : case 3: ; cin >> x; // cout << endl; court <<"Enter the first factor:" cin>> x / / court <<endl; ; cin >> y; // cout << endl; court <<"Enter the second factor:" cin>> y / / court <<endl; z = x * y; << y << " rowna sie " << z << "." << endl << endl; court <<x <<"times" <<y <<"equal to" <<z <<"." <<endl <<endl; break; : case 4: ; cin >> x; // cout << endl; court <<"Enter the number of brave:" cin>> x / / court <<endl; ; cin >> y; // cout << endl; court <<"Enter divisor:" cin>> y / / court <<endl; z = x / y; << y << " rowna sie " << z << "." << endl << endl; court <<x <<"divided by" <<y <<"equal to" <<z <<"." <<endl <<endl; break; : case 5: ; cin >> x; // cout << endl; court <<"Enter the might of the foundation:" cin>> x / / court <<endl; ; cin >> y; // cout << endl; court <<"Enter the exponent:" cin>> y / / court <<endl; ; z = pow (x, y); << y << " rowna sie " << z << "." << endl << endl; court <<x <<"squared" <<y <<"equal to" <<z <<"." <<endl <<endl; break; : case 6: ; cin >> x; // cout << endl; court <<"Enter the root of the foundation:" cin>> x / / court <<endl; ; z = sqrt (x); << y << " wynosi " << z << "." << endl << endl; court <<"root of" <<y <<"is" <<z <<"." <<endl <<endl; break; : case 7: ; cin >> x; // cout << endl; court <<"Enter the absolute foundation of values:" cin>> x / / court <<endl; ; z = abs (x); << y << " wynosi " << z << "." << endl << endl; court <<"The value of the absolute number of" <<y <<"is" <<z <<"." <<endl <<endl; break; ; 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 ) ) )
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] written by Don Daniello \ \ tags: c + + , Calculator , Programming
|