Intro to C++
Session 3- Five Sample C++ Programs
By Coding-Bootcamps.com
#############################################################
#############################################################
#############################################################

Program #1
//Program to just print a message on screen.

#include <iostream> //Preprocessor or headerfile for outputstatement
using namespace std; // Namespace declaration

int main() //Main function of the program
{
	cout << "World of C++" << endl; //Output statement
	return 0;
}
#############################################################
Program #2

//Program to swap the two numbers by using third variable
#include <iostream>
using namespace std;

int main()
{
	int a, b, c; // Declare Integer variables 
	a = 10; // Initialise with value
	b = 20;

	c = a;
	a = b; 
	b = c;

	cout << "The value of a is = " << a << endl; 
	cout <<"The value of b is = "<< b << endl;

	return 0;
}

#############################################################
Program #3
//Program to enter two numbers and shows their sum.
#include <iostream>
using namespace std;

int main()
{
	int first, second;
	int sum;

	cout << "Enter the value of first number = ";
	cin >> first; //Input statement 

	cout << "Enter the value of second number = ";
	cin >> second;

	sum = first + second; //Arithmetic Operation 
	cout << "The sum is = " << sum << endl;

	return 0;
}



#############################################################

Program #4
//Program to convert the temperature in Celcius.
#include <iostream>
using namespace std;

int main()
{
	float ftemp, ctemp; //Declare float variables 
	cout<<"Enter the temperature in Fahrenheit = "; 
	cin >> ftemp;
		
	ctemp = (ftemp - 32.0) * 5.0 / 9.0;
	cout << "The temperature in Celcius is = " << ctemp << endl;

	return 0;
}


#############################################################

Program #5
//Program to display the reverse number of a given year with four digits
#include <iostream>
using namespace std;

int main()
{
	unsigned int y, d4, d3, d2, d1, res; 
	cout << "Enter the year = "; 
	cin >> y; // example = 2020

	d1 = y / 1000; // gets you first digit = 2
	res = y % 1000; // % is used for remainder = 20

	d2 = res/100; // gets you second digit = 0
	res = res % 100; // remainder = 20
	
	d3 = res / 10; // gets you third digit = 2
	res = res % 10; // remainder = 0
	
	d4 = res / 1; // gets you fourth digit = 0
	cout << "The reverse number is = " << d4 << d3 << d2 << d1;

	return 0;
}


#############################################################


