Example: biology

Summary of basic C++-commands

Summary of basic C++-commandsCompilingTo compile a C++-program, you can use eitherg++orc++.g++ ++ ++ -o C++ C++ the following commands you can find at the end of this Summary command in C++ is followed by ; . Carriage return has no meaningin C++.CommentsEssential for the writing of clear programs are comments, which are explana-tions for your program, and which are ignored by the *..*/puts the text..into comment (more than one line possible)//..puts text..for rest of same line into commentData TypesData TypeDeclaration (Example)Assignment (Example)integershort i1,i2;i1 = 3;int i1,i2;long i1,i2;unsigned i1,i2;unsigned long i1,i2;realfloat f1,f2;f1 = ; f2 = ;double f1,f2;long double f1,f2;single characterchar c1,c2;c1 = R string of charactersstring s1,s2;s1 = Farmer logicalbool b1,b2;b1 = true; b2 = falseInput And OutputInput/Output With Screen:To be able to use the following commands you need to write#include <iostream>using namespace std;at the beginning of your program:output:cout << string of characters ;cout << variable; << endl;input:cin >> variable;Input/Output With Files:To be able to use the following commands you need to write#include <fstream>at the beginning of your program:output:ofstreamoutfilevariable( outputfilename ,ios::out);outfilevariable<<.

Summary of basic C++-commands Compiling To compile a C++-program, you can use either g++or c++. g++ -oexecutable filename.out sourcefilename.cc

Tags:

  Basics, Summary, Command, Summary of basic c commands

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Summary of basic C++-commands

1 Summary of basic C++-commandsCompilingTo compile a C++-program, you can use eitherg++orc++.g++ ++ ++ -o C++ C++ the following commands you can find at the end of this Summary command in C++ is followed by ; . Carriage return has no meaningin C++.CommentsEssential for the writing of clear programs are comments, which are explana-tions for your program, and which are ignored by the *..*/puts the text..into comment (more than one line possible)//..puts text..for rest of same line into commentData TypesData TypeDeclaration (Example)Assignment (Example)integershort i1,i2;i1 = 3;int i1,i2;long i1,i2;unsigned i1,i2;unsigned long i1,i2;realfloat f1,f2;f1 = ; f2 = ;double f1,f2;long double f1,f2;single characterchar c1,c2;c1 = R string of charactersstring s1,s2;s1 = Farmer logicalbool b1,b2;b1 = true; b2 = falseInput And OutputInput/Output With Screen:To be able to use the following commands you need to write#include <iostream>using namespace std;at the beginning of your program:output:cout << string of characters ;cout << variable; << endl;input:cin >> variable;Input/Output With Files:To be able to use the following commands you need to write#include <fstream>at the beginning of your program:output:ofstreamoutfilevariable( outputfilename ,ios::out);outfilevariable<<.

2 Will write into file with name outputfilenameinput:ifstreaminfilevariab le( inputfilename ,ios::in);infilevariable>>..will read from file with name outputfilenameArithmetic CalculationsOperations:+ /Functions:To be able to use all of the following functions you need to to write at thebeginning of your program:#include <cmath>#include <cstdlib>pow(x,y)xysin(x)cos(x)tan(x)asin(x)sin 1(x)in range[ /2, /2]acos(x)cos 1(x)in range[0, ]atan(x)tan 1(x)in range[ /2, /2]sinh(x)cosh(x)tanh(x)exp(x)exlog(x)ln (x)sqrt(x) xfabs(x)|x|floor(x)largest integer not greater than x;example:floor( ) = 5ceil(x)smallest integer not less than x;example:ceil( ) = 6fmod(x,y)floating-point remainder ofx/ywith the same sign as xx % yremainder ofx/y, bothxandyare integers;example:7%5=2 Decision StatementsComparison Operators:===example:i1 == i2!=6=i1 != i2>>i1 > i2<<i1 < i2>= i1 >= i2<= i1 <= i2&&and(i1 != i2)&& (i1 == i3)||and/or(i1 == i2) || (i1 == i3)Statements:if(condition){statements}i f(condition){statements}else{statements} if(condition){statements}else if{statements}else{statements}switch (casevariable){casevalue1a:casevalue1b:{ statements}break;casevalue2a:casevalue2b :{statements}break;default:{statements}} Repetitionswhile (conditions){statements}for (init;conditions;update){statements}do{s tatementsthese statements are done before the while statement check}while (condition) ;functionsA function is a set of commands.

3 It is useful to write a user-defined function, your own function, whenever you need to do the same task many times inthe program. All programs start execution at the function main. For Functionsyou need steps 1-3:Step 1:At the beginning of your program you need to declare any functions:functiontype functionname (typesofparameterlist);example 1:double feetinchtometer (int,double);example 2:void metertofeetinch (double, int&, double&);The functiontype declares which variable is passed back from the function(voidmeans none via the functiontype). The variables without & are allinput parameters, only passed to the function and are not changed withinthe function. The variables with & may be passed both to andfrom thefunction and may be changed in the 2:In the program you use the function with:functionname (actualparameterlist);example 1:feetinchtometer( , );example 2:metertofeetinch( ,feet,inch);Step 3:Aftermain{..}define your function:functiontype functionname (parametertypesandnames){declarations andstatements}example 1:double feetinchtometer(int feet, double inch){.}

4 };example 2:void metertofeetinch (double m, int& feet, double& inch){..};ArraysData TypeDeclaration (Example)Assignment (Example)arrayint street[100];street[0]=0; street[50]=7;double matrix[7];matrix[6]= ; arrayint lattice[10][10];lattice[0][1]=1;double wateruse[5][3][2];wateruse[3][1][0]=.


Related search queries