This will make sense only if you want to refresh your memory on C++ syntax.
cout << "Enter two integers:" << endl; // output to screen
cin >> n >> m;
// Note: Using endl prints out a newline and flushes the output buffer.
cout << "number of digits in char: " << numeric_limits::digits << 'n';
if (n > m) { // if n is bigger than m, swap them
int temp = n; // declare temp and initialize it
n = m; // assign value of m to n
m = temp; // assign value of temp to m
}
long iii = i; // implicit conversion from int to long
iii = long(i); // explicit conversion from int to long
for (double d = 1.1; d <= 9.9; d += 0.2) sum += sin(d);
using namespace std;
#include
int main() {
using namespace std;
}
const int mxdigits = 999500;
int* p = &n;
int m = 200;
*p = m;
double* tryd = new double (x);
unsigned int jj = ii;
cout.width(2);
cout << i;
struct point2d {
char nm;
float x;
float y;
};
point2d pt2 = { 'A', 3.14, -38 };
union val {
int i;
double d;
char c;
};
double* tmv = new double[n];
int n = atoi(argv[1]); // first integer is assigned to n
int* local = new int;
*local = 555;
namespace Vec {
const int maxsize = 100000; // a const number
double onenorm(double*, int); // L 1 norm
}
double Vec::onenorm(double* v, int size) {
}
std::cout <<"Approx root near 7.7 by newton method is: " << root << 'n';
---
std::srand(time(0)); // seed the random number generator
for (int i = 0; i< n; i++) dp[i] = std::rand()%1000;
std::sort(dp, dp+n);
---
double d = - 12345.678987654321;
cout.setf(ios_base::scientific, ios_base::floatfield); // scientific format
cout.setf(ios_base::uppercase);
cout.width(25);
cout.precision(15);
cout.setf(ios_base::left, ios_base::adjustfield); // adjust to left
cout << d << "n";
--------
double sum(int num, ...);
va_list argPtr;
va_start(argPtr, num); // initialize argPrt. num is the last known argument
double sum = 0;
for( ; num; num--) {
sum += va_arg(argPtr, double); // argument of type double is returned
}
va_end(argPtr); // deallocate stack pointed to by argPtr
return sum;
--
struct point2d {
double x;
double y;
friend double norm(point2d p) { // a friend
return sqrt(p.x*p.x + p.y*p.y); // distance to origin
}
};
----
class triangle {
point2d* vertices;
public:
triangle(point2d, point2d, point2d); // constructor
~triangle() {
} // destructor
double area() const; // a function member
};
----
class triple { // a triple of numbers
float* data;
public:
triple(float a, float b, float c); // constructor
~triple() { } // destructor, also defined here
friend triple add(const triple&, const triple&); // add is a friend
};
inline triple::triple(const triple& t) {
data = new float [3];
for (int i = 0; i < 3; i++) data[i] = t.data[i];
}
-----
operator overloading
class Cmpx { // class for complex numbers
private:
double re; // real part of a complex number
double im; // imaginal part of a complex number
public:
Cmpx(double x = 0, double y = 0) { re =x; im =y; } // constructor
Cmpx& operator+=(Cmpx); // operator +=, eg z1 += z2
Cmpx& operator-=(Cmpx); // operator -=, eg z1 -= z2
Cmpx& operator++(); // prefix, z1 = ++z
Cmpx operator++(int); // postfix, z1 = z++
friend Cmpx operator*(Cmpx, Cmpx); // binary *, z = z1 * z2
friend std::ostream& operator<<(std::ostream&, Cmpx); // operator <<
friend std::istream& operator>>(std::istream&, Cmpx&); // operator >>
};
----------------
template class Vcr {
int lenth; // number of entries in vector
T* vr; // entries of the vector
public:
Vcr(int, T*); // constructor
Vcr(const Vcr&); // copy constructor
~Vcr(){ delete[] vr; } // destructor
};
// partial specialization
template class Vcr< complex > {
int lenth; // number of entries in vector
complex* vr; // entries of the vector
public:
Vcr(int, complex*); // constructor
Vcr(const Vcr&); // copy constructor
~Vcr(){ delete[] vr; } // destructor
};
// complete specialization
template<>
class Vcr< complex > {
int lenth; // number of entries in vector
complex* vr; // entries of the vector
public:
Vcr(int, complex*); // constructor
Vcr(const Vcr&); // copy constructor
~Vcr(){ delete[] vr; } // destructor
};
----------
complex aa = complex(3, 5);
---
list nodes; // a list of integers for nodes
nodes.push_front(10); // add 10 at the beginning
nodes.push_back(5); // add 5 at the end
nodes.pop_back(); // remove last element
nodes.remove(10); // remove element 10
for (list::iterator j = nodes.begin(); j != nodes.end(); j++)
cout << *j << " "; // *j is the element at position j
nodes.sort();
nodes.unique();
nodes.reverse();
nodes.insert(i, 2); // insert before element that i refers to
nodes.insert(i, 5, 7); // insert 5 copies of 7
nodes.erase(i);
ft.merge(sd); // ft has the merged list, sd will be empty
list::iterator ii = find(ft.begin(), ft.end(), 5.5);
sd.splice(sd.begin(), ft, ii);
----
VECTOR
std::vector vi(10);
for (int i = 0; i < 10; i++) vi[i] = (i-5)*i;
std::sort(vi.begin(),vi.end());
std::unique(vi.begin(),vi.end());
From: http://sitestree.com/?p=3525
Categories:Programming, C++
Tags:
Post Data:2016-07-07 16:00:12
Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada
