What Will I Learn?
You are going to learn a programming language called C++ (most heard but not coded often :P).
- You will learn every bit of C++ in the series.
- You will learn Object Oriented Programming (OOP) in particular.
- You will learn to increase C++ computing performance by modifying code accordingly (very important for a distributed network like Blockchain).
- Eventually, you will learn to write smart contract using C++ language.
Requirements
These are the following requirements for following this video tutorial:
- Basic Maths logic - Addition, Subtraction, Division, ....
- C++ IDE setup required for practising the tutorial
Difficulty
This is a basic level tutorial.
Description
This is a tutorial series on learning C++ programming language.
I am deeply involved with Blockchain technology. So, this is an endeavor to make Developers equipped with the power of coding any applications using C++ 's Object Oriented Programming (OOP) tool.
Additionally in the end of this series, I will be covering some IEEE papers on improving C++ codes' computing performance using some shortcuts.
Tutorial Contents
Installation guide -
This is for Windows & Ubuntu lovers in particular. Run linux subsystem over Windows OS using WSL.
- And editor like Sublime Text 3
- Use gcc compiler for Linux (ubuntu). Install it using
sudo apt-get install g++
- Compile C++ codes (.cpp format) e.g. File - "hello.cpp" using
g++ hello.cpp -o hello.out
command & then - Execute using
./hello.out
command
This tutorial covers basic concepts which are very easy to understand.
The questions along with solutions is as follows: -
1. Hello World
Question:
Print "Hello World"
Solution:
/*C++ Program to Print "Hello World"*/
#include
int main()
{
std::cout<<"Hello World"<<std::endl;
return 0;
}
2. Print Numbers
Question:
Enter any integer and print that number
Solution:
/*C++ Program to Print Number Entered by User*/
#include
int main()
{
int num;
//input the number
std::cout<<"Enter an integer \n";
std::cin>>num;
// Print the number
std::cout<<"You entered "<<num<<std::endl;
return 0;
}
3. Add 2 numbers
Question:
Program to add 2 Numbers.
Solution:
/*C++ Program to Add 2 Numbers*/
#include
int main()
{
int a, b, c;
// Enter a
std::cout<<"Enter a: \n";
std::cin>>a;
// Enter b
std::cout<< "Enter b: \n";
std::cin>>b;
c = a + b;
std::cout<<"The addition of "<<a<<" and "<<b<<" is "<<c <<std::endl;
return 0;
}
4. Area of Circle
Question:
Program to calculate Area of Circle.
Solution:
/*C++ Program on Area of Circle*/
#include
int main()
{
int r; // radius of the circle
double area;
std::cout<<"Enter the radius :\n";
std::cin>> r;
// the area
area = 3.14 * r * r;
std::cout<<"The area of the circle: "<< area<<std::endl;
return 0;
}
5. Divisor & Dividend
Question:
Program to find Divisor and Dividend
Solution:
/*C++ Program to find Divisor and Dividend*/
#include
int main()
{
int dividend, divisor, quotient, remainder;
// dividend
std::cout<<"Enter the dividend: \n";
std::cin>>dividend;
// divisor
std::cout<<"Enter the divisor: \n";
std::cin>>divisor;
quotient = dividend/divisor; //quotient
remainder = dividend % divisor; //remainder
std::cout<<"The quotient is "<<quotient<<std::endl;
std::cout<<"The remainder is "<<remainder<<std::endl;
return 0;
}
6. Convert *C to *F
Question:
Program to convert Celsius and Fahrenheit
Solution:
/*C++ Program to convert Celsius and Fahrenheit*/
#include
int main()
{
float celsius, fahrenheit;
std::cout<<"Enter temperature in Celsius: \n";
std::cin>>celsius;
fahrenheit = celsius * (9.0/5.0) + 32;
std::cout<<"The temperature in Celsius is "<< celsius<<std::endl;
std::cout<<"The temperature in Fahrenheit is "<< fahrenheit<<std::endl;
return 0;
}
7. Leap Year
Question:
Program to check a leap year
HINT:
(Source)
To determine whether a year is a leap year, follow these steps:
- If the year is evenly divisible by 4, go to step 2. ...
- If the year is evenly divisible by 100, go to step 3. ...
- If the year is evenly divisible by 400, go to step 4. ...
- The year is a leap year (it has 366 days).
- The year is not a leap year (it has 365 days).
Solution:
/*C++ Program to check a leap year*/
#include
int main()
{
int year;
std::cout<<"Enter a year: \n";
std::cin>>year;
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0) {
std::cout<<"It is a leap year"<<std::endl;
}
else {
std::cout<<"It is NOT a leap year"<<std::endl;
}
}
else
{
std::cout<<"It is NOT a leap year"<<std::endl;
}
}
else
{
std::cout<<"It is NOT a leap year"<<std::endl;
}
return 0;
}
8. ASCII
Question:
Program to Print ASCII value
Solution:
/*C++ Program to Print ASCII value*/
#include
int main()
{
char c;
std::cout<<"Enter a char: \n";
std::cin>>c;
std::cout<<"The ASCII value of "<<c<< " is "<< int(c)<<std::endl;
return 0;
}
9. Switch statement
Question:
Program to understand Switch statement
Solution:
/*C++ Program to understand Switch*/
#include
int main()
{
int choice;
std::cout<<"Enter an integer number (1-5): \n";
std::cin>>choice;
switch(choice){
case(1): std::cout<<"You entered 1"<<std::endl;
break;
case(2): std::cout<<"You entered 2"<<std::endl;
break;
case(3): std::cout<<"You entered 3"<<std::endl;
break;
case(4): std::cout<<"You entered 4"<<std::endl;
break;
case(5): std::cout<<"You entered 5"<<std::endl;
break;
default:
std::cout<<"Invalid choice."<<std::endl;
break;
}
return 0;
}
10. If-else Statement
Question:
Program to understand If-else
Solution:
/*C++ Program to understand If-else*/
#include
int main()
{
int n;
std::cout<<"Enter an integer: \n";
std::cin>>n;
if(n % 2 == 0){
std::cout<<"The number is EVEN."<<std::endl;
} else {
std::cout<<"The number is ODD."<<std::endl;
}
return 0;
}
Follow the codes in the Tutorial Notebook.
Curriculum
There is no related tutorial as it is the first one in the series.
Posted on Utopian.io - Rewarding Open Source Contributors