Reguli: - In a constructor, always initialize all data types within a member initialization list. - Dynamically allocated objects must be explicitly deleted when no longer needed by a program. Always set a pointer to 0 (myPointer = 0;), after the delete is called. - private data, public interface. Intrebari: - cum definesti si folosesti o matrice de dimensiune necunoscuta (Dynamic Memory Allocation; new operator) ? Fundamentale:
- A definition allocates space for a variable; a declaration simply gives the compiler information about its type. - Operator Overloading: c = a + b; <-> c = a.operator+(b); ************************************************************************************************************ Basic Data Types:
Type Name |
Bytes |
Other Names |
Range of Values |
Description |
int |
4 |
signed |
–2,147,483,648 to 2,147,483,647 |
|
bool |
1 |
none |
false or true |
|
char |
1 |
none |
-128 to 127 |
The char type is used to store the integer value of a member of the representable character set. That integer value is the ASCII code corresponding to the specified character. |
short |
2 |
short int, signed short int |
–32,768 to 32,767 |
|
long |
4 |
long int, signed long int |
–2,147,483,648 to 2,147,483,647 |
|
enum |
4 |
none |
same as int |
|
float |
4 |
none |
3.4E +/- 38 (7 digits) !!! |
|
double |
8 |
none |
1.7E +/- 308 (15 digits) !!! |
Detalii: ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_vclang/html/3691ceca-05fb-4b82-b1ae-5c4618cda91a.htm ************************************************************************************************************ Arrays: Declaration: datatype arrayName[size]; Definition: arrayName[i] = j; explicit initialization list: datatype arrayName[size] = {val, val,...,val} Member Functions: - fill_n(ArrayName,ArrayDim,TheElement) este folosita pentru a initializa o matrice cu o anumita valoare
Multidimensional Arrays: Declaration: type arrName [V1][V2]; Initialization: for (i = 0; i < V1; i++) {for (j = 0; j < V2; j++) { arrName[i][j] = val ; } } Build In Data Types: - char nameArrChar[] = "some string"; = declaratie si definitie pt o matrice de caractere ************************************************************************************************************ Convert Data Types: - String -> Int16 Ex: using namespace System; int x = Convert::ToInt16("123"); - std::string -> System::String Ex: String ^systemstring = gcnew String(stdString.c_str()); ************************************************************************************************************ Input/Output: - to write a text file see: ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_vccore/html/39ecdba6-84e0-485c-a202-84cf6d7b8d4a.htm ************************************************************************************************************ Generic algorithm - Declaration: #include <algorithm> : find: Prototype: InputIterator find(InputIterator start, InputIterator end,const T& value); count: Prototype: size_t count(InputIterator start, InputIterator end,const T& value); sort: Prototype: sort(start_iterator, end_iterator); imi aranjeasa in ordine crescatoare datele dintr-un vector ************************************************************************************************************ ofstream Class: used for writing files header: ifstream Initialization: ofstream _myFile("path"); Return type of the object _myFile is bool ifstream Class: used for reading files header: ifstream ************************************************************************************************************ ************************************************************************************************************ ************************************************************************************************************ - Pointer: Declaration: type* pVar,parray; Definition: pVar = &Var; parray = &array[0]; <=> parray = array; ************************************************************************************************************ - Iterators (classes): Def1: vector<type>::iterator IterName = nameV.begin(); //sets this iterator to the beginning of the vector Access: *iteratorName; ************************************************************************************************************ ************************************************************************************************************ Standard types: - size_t unsigned_integer; = Result of sizeof operator
************************************************************************************************************
String Class:
Declaration: #include <string>
Initialization & Assignment: string S1; string S2("string"); S1 = S2;
String Operations:
[] = to access or set individual elements (characters) of a string.
+ = string concatenation
> = comparing strings as nr. of elements
Member Functions:
- append(string) = ataseaza substringul la string
- c_str()[i] = extrage charactere din sir in functie de pozitia lor (variabila „i”).
- clear() = Erases the entire string.
- length() = nr de charactere din string.
- erase(x,y) = sterge incepand cu caracterul x, un nr y de caractere
- bool empty() const; = Tests whether the string is contains characters or not
- size_type find(string) = Searches for the first occurrence of a substring that matches a specified sequence of characters; returns an interator.
- void push_back(value_type _Ch ); = Adds an element to the end of the string.
- replace(iterator _first, iterator _last, string& _str); = Replaces elements in a string from _first to _last with the specified characters ("string").
- void swap(basic_string& _Str); = Exchange the contents of two strings. Ex: S1.swap(S3); S3 = "bau"; S1 = "miau"
Help:
- basic_string Members: ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_vcstdlib/html/eedbc461-5ea0-49c3-b65c-a508b693e5fb.htm
************************************************************************************************************
- Vectors (container class):
Declaration: #include <vector>
Definition: vector<type> nameV(size);
Vector constructors: vector<type> nameV(size,val_for_each_element); vector<type> nameV(arrName, arrName+sizeArr) //copy array -> vector
Methods:
at(index) | Returns a reference to a vector element at the location specified by index |
front() | Returns a reference to the first element of the vector |
back() | Returns a reference to the element at the end of the vector |
pop_back() | Deletes the element at the end of the vector |
back() | Returns a reference to the element at the end of the vector. |
push_back (const type &val) | Adds an element to the end of the vector. |
size() | Returns the number of elements in the vector |
begin() | Returns an iterator to the start of the vector |
insert(iterator where, const type &val) insert(iterator where, size_type number, const type &val) insert(iterator where, iterator input_begin, iterator input_end) |
Inserts a value or values into a vector at the specified position(s). |
erase(iterator where) erase(iterator first, iterator last) |
Removes a single element or range of elements |
size() | Returns the number of elements in the vector. |
= | Assigns one vector to another |
ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_vcstdlib/html/91c8cabc-403d-419a-9ff8-612f16671f9a.htm ************************************************************************************************************ Operators: - b = a++ <-> a = b; a = a + 1; //Postfix increment - b = ++a <-> a = a + 1; b = a; //Prefix increment - b += a <-> b = b + a; ************************************************************************************************************ - end Legenda: - tipul de data -> stil Italic; functia, cuvinte cheie -> Bold; numele -> _nume; Ex void _functie (int _x); - arrName = array name - nameV = vector name - val = some value. - V1, V2 = first value, second value.