Thursday, November 26, 2015

C++: Glossary and code snippets...

Good tools are first requisite of better programming. Here I list some of the tools, links that helped me hone my grasp over programming C++.
C++ originates from C, yet it has many features on top of it, such as classes, objects, templates, namespaces etc. 
-----------------------------------------------------
CodeLite is a good IDE to practice C, C++ and PHP. Linking a compiler is vital for itsproper working.
Create project.....src.......code_file (.cpp extension)
Perspectice----Restore default layout
-----------------------------------------------------
http://cpp.sh/   (Its a nice online compiler, you just need to copy paste your code.)
Some really nice tutorial can be found at:
http://www.cplusplus.com/
-----------------------------------
Function declaration
int main ()
main is the special function
-----------------------------------
class
ostream
-----------------------------------
object 
std::cin            (input)
std::cout          (output)
std::cer            (error)

std::clog           (logging)
-----------------------------------
operator
<< 
-----------------------------------
function
write
The sentence below is direction to preprocessor
#include <iostream>
########################
Should produce Hello World. Brace pair contain statement of the function.
#include <iostream>
int main()
{
 std::cout << "Hello World!";
 std::cout << "C++ is a nice language to learn!";
}
-----------------------------------
Another version of the above program (better than the above)
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
cout << "Its a C++ program";
}
########################
Calculations (declares variables, calculates and prints results before termination)
#include <iostream>
using namespace std;
int main ()
{
int a,b; int result;
a = 5; b = 3;
a = a+1; b = b+2;
result = a * b;
cout << result;
return 0;
}
-----------------------------------
Initializing variables ( here a,b,c,d)
#include <iostream>
using namespace std;
int main ()
{
int a =2; int b(4); int c{6}; int result;
a = a+b; result = a * c;
cout << result;
return 0;
}
########################
String manipulation
Printing one string
#include <iostream>
#include <string>
int main ()
{
string mystring;
mystring= "Programming is fun";
cout << mystring;
return 0;
}
-----------------------------------
Printing multiple strings
#include <iostream>
#include <string>
int main ()
{
string mystring;
mystring= "I like autumn season";
cout << mystring << endl;
mystring= "Because trees are colorful";
cout << mystring << endl;
mystring= "Also, the weather is crisp";
cout << mystring << endl;
return 0;
}
-----------------------------------

No comments:

Post a Comment