You are on page 1of 7

Unit -1

Basic Concept on Computer Programming language

Programming with C++

Programming Language:- The computer system is simply a machine and hence it cannot perform any work;
therefore, in order to make it functional different languages are developed, which are
known as programming languages or simply computer languages.
Following are the major categories of Programming Languages −

• Machine Language
• Assembly Language
• High Level Language
• Scripting Language

1. Machine language is a collection of binary digits or bits that the computer reads and interprets. Machine
language is the only language a computer is capable of understanding.

2. Assembly language Each personal computer has a microprocessor that manages the computer's arithmetical,
logical, and control activities.
Each family of processors has its own set of instructions for handling various operations such as getting
input from keyboard, displaying information on screen and performing various other jobs. These set of
instructions are called 'machine language instructions'.

Advantages of Assembly Language

Having an understanding of assembly language makes one aware of −

• How programs interface with OS, processor, and BIOS;


• How data is represented in memory and other external devices;
• How the processor accesses and executes instruction;
• How instructions access and process data;
• How a program accesses external devices.

3. A high-level language (HLL) is a programming language such as C, C++, Java, FORTRAN, or Pascal that
enables a programmer to write programs that are more or less independent of a particular type of computer.
Such languages are considered high-level because they are closer to human languages and further
from machine languages.
ADVANTAGES OF HIGH-LEVEL LANGUAGES
The main advantage of high-level languages over low-level languages is that they are easier to read, write, and maintain.
Ultimately, programs written in a high-level language must be translated into machine language by
compiler or interpreter.

Difference between high level and low level languages:


High Level Language Low Level Language
It is programmer It is a machine friendly
1. friendly language. language.

High level language is Low level language is


2. less memory efficient. high memory efficient.

It is easy to
3. understand. It is tough to understand.

It is complex to debug
4. It is simple to debug. comparatively.

It is simple to It is complex to maintain


5. maintain. comparatively.

6. It is portable. It is non-portable.

It can run on any


7. platform. It is machine-dependent.

It needs compiler or
interpreter for It needs assembler for
8. translation. translation.

It is not commonly used


It is used widely for now-a-days in
9. programming. programming.
What is a Scripting Language?

Scripting language (also known as scripting, or script) is a series of commands that are able to be executed
without the need for compiling. While all scripting languages are programming languages, not all
programming languages are scripting languages. PHP, Perl, and Python are common examples of scripting
languages.
Scripting languages use a program known as an interpreter to translate commands and are directly interpreted
from source code, not requiring a compilation step. Other programming languages, on the other hand, may
require a compiler to translate commands into machine code before it can execute those commands.

Server-Side Scripting Languages

The following are examples of server-side scripting languages.

Language Comments

PHP The most popular server-side language used on the web.

ASP.NET Web-application framework developed by Microsoft.

Can run on a multitude of platforms, including Windows, Linux,


Node.js
Unix, Mac, etc.

Used in everything from your car stereo’s Bluetooth to NASA


Java
applications.

Ruby Dynamic. Focuses heavily on simplicity.

Perl A bit of a mashup between C, shell script, AWK, and sed.

Python Great for beginners to learn. Uses shorter code.

Client-Side Scripting Languages

The following are examples of client-side scripting languages.

Language Comments

HTML The foundation of web development.

CSS Improves appearance and graphics on pages in your web browser.

Though typically client-side, can occasionally be used on server-


JavaScript
side as well.
Simple programme in C Languge:-

#include <stdio.h>
int main()
{
/* printf function displays the content that is
* passed between the double quotes.
*/
printf("Hello World");
return 0;
}

1. #include <stdio.h> – This statement tells compiler to include this stdio.h file in the program. This is a standard input output
file that contains the definitions of common input output functions such as scanf() and printf(). In the above program we are
using printf() function.

2. int main() – Here main() is the function name and int is the return type of this function. Every C program must have this
function because the execution of program begins with the main() function. The 0 return value of this function represents
successful execution of program while the return value 1 represents the unsuccessful execution of program. This is the reason
we have return 0; statement at the end of this main function.

3. printf("Hello World"); – This function displays the content within double quotes as it is on the screen.

4. return 0; – As mentioned above, the value 0 means successful execution of main() function

Program to check whether the input integer number is even or odd using the modulus operator (%)
#include<stdio.h>
int main()
{
int num;

printf("Enter an integer: ");


scanf("%d",&num);

if ( num%2 == 0 )
printf("%d is an even number", num);
else
printf("%d is an odd number", num);

return 0;
}

Program to find sum of natural numbers using for loop


#include <stdio.h>
int main()
{
int n, count, sum = 0;
printf("Enter the value of n(positive integer): ");
scanf("%d",&n);

for(count=1; count <= n; count++)


{
sum = sum + count;
}

printf("Sum of first %d natural numbers is: %d",n, sum);

return 0;
}
Output:

Enter the value of n(positive integer): 6


Sum of first 6 natural numbers is: 21

Program to add two integer numbers


#include <stdio.h>
int main()
{
int num1, num2, sum;
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);

sum = num1 + num2;


printf("Sum of the entered numbers: %d", sum);
return 0;
}
Output:

Enter first number: 20


Enter second number: 19
Sum of the entered numbers: 39

What is C++
C++ is a general purpose, case-sensitive, free-form programming language that supports object-oriented, procedural and generic
programming.

Object-Oriented Programming (OOPs)


C++ supports the object-oriented programming, the four major pillar of object-oriented programming (OOPs) used in C++ are:

1. Inheritance
2. Polymorphism
3. Encapsulation
4. Abstraction

Usage of C++
By the help of C++ programming language, we can develop different types of secured and robust applications:

o Window application
o Client-Server application
o Device drivers
o Embedded firmware etc
o Add two Numbers of Integer Type in C++.

#include<iostream>
using namespace std;

int main()
{
int num1, num2, add;
cout<<"Enter Two Numbers: ";
cin>>num1>>num2;
add = num1+num2;
cout<<"\nResult = "<<add;
cout<<endl;
return 0;
}

Make a Calculator in C++

#include<iostream>
using namespace std;
int main()
{
float numOne, numTwo, res;
int choice;
do
{
cout<<"1. Addition\n";
cout<<"2. Subtraction\n";
cout<<"3. Multiplication\n";
cout<<"4. Division\n";
cout<<"5. Exit\n\n";
cout<<"Enter Your Choice(1-5): ";
cin>>choice;
if(choice>=1 && choice<=4)
{
cout<<"\nEnter any two Numbers: ";
cin>>numOne>>numTwo;
}
switch(choice)
{
case 1:
res = numOne+numTwo;
cout<<"\nResult = "<<res;
break;
case 2:
res = numOne-numTwo;
cout<<"\nResult = "<<res;
break;
case 3:
res = numOne*numTwo;
cout<<"\nResult = "<<res;
break;
case 4:
res = numOne/numTwo;
cout<<"\nResult = "<<res;
break;
case 5:
return 0;
default:
cout<<"\nWrong Choice!";
break;
}
cout<<"\n------------------------\n";
}while(choice!=5);
cout<<endl;
return 0;
}
OUTPUT

Data Types in C++

You might also like