Biggest of 3 Numbers Using Ternary Operator: C++

Video tutorial to find the biggest of the three integer numbers in C++, using if-else control statements and Ternary Operator.

Before watching this video, please make sure to watch and understand this short video: Find Biggest of 3 Numbers: C++

Full Source Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream .h>
#include<conio .h>
 
void main()
{
int a, b, c;
clrscr();
 
cout< <"Enter 3 no's\n";
cin>>a>>b>>c;
 
int big =  ( a>b && a>c )?a:(b>c?b:c);
/*
if( a > b && a > c )
  big = a;
else if( b > c )
  big = b;
else
  big = c;
*/cout< <"\nAmong "<<a<<" , "<<b<<" , "<<c<<" Biggest is "<<big;
getch();
}

In this program we take 3 integer values from the user and using ternary operator decide the biggest of 3 numbers.

int big =  ( a>b && a>c )?a:(b>c?b:c);

if ( a > b && a > c ) is true, then value of a will be stored in variable big; else ( b > c ? b : c ) will be evaluated. Here, if value of b is greater than c, value of b will be stored in variable big else value of c will be stored in the variable big.

Video Tutorial: Biggest of 3 Integer Numbers


[youtube https://www.youtube.com/watch?v=gfmqT4PwfY0]

YouTube Link: https://www.youtube.com/watch?v=gfmqT4PwfY0 [Watch the Video In Full Screen.]



Output
Enter 3 no’s
10
20
30
Among 10, 20, 30 Biggest is 30

Find Biggest of 3 Numbers: C++

Video tutorial to find the biggest of the three integer numbers in C++, using if-else control statements.

Full Source Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream .h>
#include<conio .h>
 
void main()
{
int a, b, c;
clrscr();
 
cout< <"Enter 3 no\n";
cin>>a>>b>>c;
 
int big;
 
if( a > b )
 big = a;
else
{
 if( b > c )
  big = b;
 else
  big = c;
}
cout< <"\nBiggest is: "<<big;
getch();
}

In this program we get three integer variables from the user.
If value of variable a is bigger, then we store it inside the variable big; else we compare b with c. Now will store the biggest number inside the variable big.
Video Tutorial: Biggest of 3 Integer Numbers


[youtube https://www.youtube.com/watch?v=YRkCpS_GMFw]

YouTube Link: https://www.youtube.com/watch?v=YRkCpS_GMFw [Watch the Video In Full Screen.]



Output
Enter 3 no’s
404
501
301
Biggest is: 501

Biggest of Two Numbers Using Ternary Operator: C++

Video tutorial to find the biggest of the two integer numbers in C++, using Ternary Operator.

To find biggest of Two numbers using if-else control structure: Find Biggest of 2 Numbers: C++

Full Source Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include < iostream .h >
#include < conio .h >
 
void main()
{
 int a, b;
 clrscr();
 
 cout< <"Enter 2 numbers\n";
 cin>>a>>b;
 
 int big;
 
 big = a > b ? a : b;
 
/*
 if( a > b )
  big = a;
 else
  big = b;
*/ 
 cout< <"\nBig is: "<<big;
 
 getch();
}

In this program we take 2 integer values from the user and using ternary operator decide the biggest of 2 numbers.

 big = a > b ? a : b;

if ( a > b ) is true, then value of a will be stored in variable big; else value of b will be stored in big.

Video Tutorial: Biggest of 2 Integer Numbers Using Ternary Operator


[youtube https://www.youtube.com/watch?v=ni2btFMBmlA]

YouTube Link: https://www.youtube.com/watch?v=ni2btFMBmlA [Watch the Video In Full Screen.]




Output
Enter 3 no’s
404
302
Big is: 404

Addition of 2 Numbers: C++

This video tutorial illustrates a simple program of adding two integer numbers.

Full Source Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<iostream .h>
#include<conio .h>
 
void main()
{
 
 int a, b;
 clrscr();
 
 cout< <"Enter two no\n";
 cin>>a>>b;
 
 int sum = a + b;
 
 cout< <endl<<"Sum is: "<<sum;
 
 getch();
 
}

We can declare variables anywhere in a cpp program.

Video Tutorial: Addition of 2 Integer Numbers


[youtube https://www.youtube.com/watch?v=GBbOJZLkBBA&ap=%2526fmt%3D22]

YouTube Link: https://www.youtube.com/watch?v=GBbOJZLkBBA [Watch the Video In Full Screen.]



In this program we take input from the user, add it and then echo the result back to the screen.

Output
Enter two no
100
200

Sum is: 300

Object Oriented Programming: C++

To understand and switch from C to C++, you need to know some of the basic similarities and differences between the two.

Sample C Program:

#include<stdio.h>

void main()
{
  printf("Welcome To C");
}

Here stdio.h header file is included inorder to make use of printf and scanf functions.

Sample Cpp Program:

#include<iostream.h>

void main()
{
  cout<<"Welcome To Cpp";
}

Here iostream.h header file is included inorder to make use of cout and cin objects.

cout is an object of class ostream.
cin is an object of class istream.

Both these ostream and istream classes are present inside iostream.h file.

In both C and C++, execution of the program starts from main() function.

The difference is, printf and scanf are functions; while cout and cin are objects.

<< is called Insertion Operator. To show result on output window.
>> is called Extraction Operator. To get input from the user(keyboard).

Structures In C:

struct Student
{
  char name[20];
  int age;
}s1;

To access members of structure:

s1.name;
s1.age;

Video Tutorial: Basics of C++


[youtube https://www.youtube.com/watch?v=GuZFpc0diJ4&ap=%2526fmt%3D22]

YouTube Link: https://www.youtube.com/watch?v=GuZFpc0diJ4 [Watch the Video In Full Screen.]



Class In Cpp:

#include<iostream.h>
#include<conio.h>

class Student
{
  int a, b, c;

  public:
  void read() { cin>>a>>b>>c; }
  void show() { cout<<"\nEntered Numbers are "<<a<<" , "<<b<<" , "<<c; }
};

int main()
{
  A a;
  clrscr();

  cout<<"\nEnter 3 nums\n";

  a.read();
  a.show();

  getch();
 
}

member functions are accessed with the help of objects.

object.member

This way data binding is done and a level of security is imparted to the data.

Binding of Data and method into a single unit is called ENCAPSULATION.