Powered by Blogger.

Tuesday, 24 January 2023

How to installation c++ programming on linux

 

                        

    • Linux Installation: We will install the GNU GCC compiler on Linux. To install and work with the GCC compiler on your Linux machine, proceed according to below steps: 
      • You have to first run the below two commands from your Linux terminal window: 
sudo apt-get update
sudo apt-get install gcc
sudo apt-get install g++
  • This command will install the GCC compiler on your system. You may also run the below command: 
sudo apt-get install build-essential
  • This command will install all the libraries which are required to compile and run a C++ program. 
     
  • After completing the above step, you should check whether the GCC compiler is installed in your system correctly or not. To do this you have to run the below-given command from Linux terminal: 
g++ --version
  • If you have completed the above two steps without any errors, then your Linux environment is set up and ready to be used to compile C++ programs. In further steps, we will learn how to compile and run a C++ program on Linux using GCC compiler. 
     
  • Write your program in a text file and save it with any file name and.CPP extension. We have written a program to display “Hello World” and saved it in a file with the filename “helloworld.cpp” on desktop. 
     
  • Now you have to open the Linux terminal and move to the directory where you have saved your file. Then you have to run the below command to compile your file: 
g++ filename.cpp -o any-name
  • filename.cpp is the name of your source code file. In our case, the name is “helloworld.cpp” and any-name can be any name of your choice. This name will be assigned to the executable file which is created by the compiler after compilation. In our case, we choose any-name to be “hello”. 
    We will run the above command as: 
g++ helloworld.cpp -o hello
  • After executing the above command, you will see a new file is created automatically in the same directory where you have saved the source file and the name of this file is the name you chose as any-name
    Now to run your program you have to run the below command: 
./hello
  • This command will run your program in the terminal window.
Published: By: Code Tutorial - January 24, 2023

Setting up C++ Development Environment

 

C++ is a general-purpose programming language and widely used nowadays for competitive programming. It has imperative, object-oriented and generic programming features. 
C++ runs on lots of platform like Windows, Linux, Unix, Mac, etc. Before we start programming with C++. We will need an environment to be set-up on our local computer to compile and run our C++ programs successfully. If you do not want to set up a local environment you can also use online IDEs for compiling your program.
Using online IDE: IDE stands for integrated development environment. IDE is a software application that provides facilities to a computer programmer for developing software. There are many online IDEs available which you can use to compile and run your programs easily without setting up a local development environment.




Setting up local environment

For setting up your own personal development environment on your local machine you need to install two important softwares: 

  1. Text Editor: Text Editors are type of programs used to edit or write texts. We will use text-editors to type our C++ programs. The normal extension of a text file is (.txt) but a text file containing C++ program should be saved with ‘.CPP’ or ‘.C’ extension. Files ending with the extension ‘.CPP’ and ‘.C’ are called source code files and they are supposed to contain source code written in C++ programming language. These extension helps the compiler to identify that the file contains a C++ program. 
    Before beginning programming with C++, one must have a text-editor installed to write programs. 
     
  2. C++ Compiler: Once you have installed text-editor and typed and save your program in a file with ‘.CPP’ extension, you will need a C++ compiler to compile this file. A compiler is a computer program which converts high-level language into machine understandable low-level language. In other words, we can say that it converts the source code written in a programming language into another computer language which the computer understands. For compiling a C++ program we will need a C++ compiler which will convert the source code written in C++ into machine codes. Below are the details about setting up compiler on different platforms.

Published: By: Code Tutorial - January 24, 2023

Introduction to C++ Programming Language

 Use of C++ Programming Language

C++ is a general-purpose programming language that was developed as an enhancement of the C language to include object-oriented paradigm. It is an imperative and a compiled language. 






C++ is a middle-level language rendering it the advantage of programming low-level (drivers, kernels) and even higher-level applications (games, GUI, desktop apps etc.). The basic syntax and code structure of both C and C++ are the same. 

Some of the features & key-points to note about the programming language are as follows:

  • Simple: It is a simple language in the sense that programs can be broken down into logical units and parts, has a rich library support and a variety of data-types.
  • Machine Independent but Platform Dependent: A C++ executable is not platform-independent (compiled programs on Linux won’t run on Windows), however they are machine independent.
  • Mid-level language: It is a mid-level language as we can do both systems-programming (drivers, kernels, networking etc.) and build large-scale user applications (Media Players, Photoshop, Game Engines etc.)
  • Rich library support: Has a rich library support (Both standard ~ built-in data structures, algorithms etc.) as well 3rd party libraries (e.g. Boost libraries) for fast and rapid development.
  • Speed of execution: C++ programs excel in execution speed. Since, it is a compiled language, and also hugely procedural. Newer languages have extra in-built default features such as garbage-collection, dynamic typing etc. which slow the execution of the program overall. Since there is no additional processing overhead like this in C++, it is blazing fast.
  • Pointer and direct Memory-Access: C++ provides pointer support which aids users to directly manipulate storage address. This helps in doing low-level programming (where one might need to have explicit control on the storage of variables).
  • Object-Oriented: One of the strongest points of the language which sets it apart from C. Object-Oriented support helps C++ to make maintainable and extensible programs. i.e. Large-scale applications can be built. Procedural code becomes difficult to maintain as code-size grows.
  • Compiled Language: C++ is a compiled language, contributing to its speed.

Applications of C++: 
C++ finds varied usage in applications such as:

  • Operating Systems & Systems Programming. e.g. Linux-based OS (Ubuntu etc.)
  • Browsers (Chrome & Firefox)
  • Graphics & Game engines (Photoshop, Blender, Unreal-Engine)
  • Database Engines (MySQL, MongoDB, Redis etc.)
  • Cloud/Distributed Systems

Some interesting facts about C++: 
Here are some awesome facts about C++ that may interest you:

  1. The name of C++ signifies the evolutionary nature of the changes from C. “++” is the C increment operator.
  2. C++ is one of the predominant languages for the development of all kind of technical and commercial software.
  3. C++ introduces Object-Oriented Programming, not present in C. Like other things, C++ supports the four primary features of OOP: encapsulation, polymorphism, abstraction, and inheritance.
  4. C++ got the OOP features from Simula67 Programming language.
  5. A function is a minimum requirement for a C++ program to run.(at least main() function)
Published: By: Code Tutorial - January 24, 2023

Use of C++ Programming Language

 

Use of C++ Programming Language

Here are some prime uses of C++ Programming Language:



Operating Systems:


Wheater it is Microsoft Windows or Mac OSX or Linux – all of the operating systems have some parts which are programmed in C++. It is the backbone of all the well-known OSs as C++ is a strongly typed and quick programming language, that makes it an ideal choice for developing an operating system.


Games:


Because of the fact that it is one of the fastest programming languages, C++ is widely used in programming of game development engines. C++ can easily manipulate hardware resources and it can also provide procedural programming for CPU intensive functions.


Browsers:


The rendering engines of various web browsers are programmed in C++ because of the speed it offers.


Libraries:


Many high-level libraries use C++ as the core programming language. For example, several Machine Learning libraries use C++ in the backend because of its speed.


Graphics:


C++ is widely used in almost all graphics applications that require fast rendering, image processing, real-time physics and mobile sensors.


Banking Applications:


One of the most popularly used core-banking systems – Infosys Finacle, uses C++ as the backend programming language. Banking applications need to process millions of transactions on a daily basis and require high concurrency and low latency support.


Cloud/Distributed Systems:


Cloud storage systems use scalable file-systems that work close to the hardware. That’s why C++ becomes a preferred choice for Cloud systems.


Embedded Systems:


Various embedded systems like medical machines, smartwatches, etc., use C++ as the primary programming language.


Compilers:


Compilers of various programming languages use C++ as the backend programming language.

Published: By: Code Tutorial - January 24, 2023

Five Basic Concepts of C++

 

Five Basic Concepts of C++











Here are five basic C++ concepts:


C++ Variables



  • Variables are the backbone of any programming language.
  • A variable is merely a way to store some information for later use. We can retrieve this value or data by referring to a “word” that will describe this information.
  • Once declared and defined they may be used many times within the scope in which they were declared.

C++ Control Structures


  • When a program runs, the code is read by the compiler line by line (from top to bottom, and for the most part left to right). This is known as “code flow.
  • When the code is being read from top to bottom, it may encounter a point where it needs to make a decision. Based on the decision, the program may jump to a different part of the code. It may even make the compiler re-run a specific piece again, or just skip a bunch of code.
  • You could think of this process like if you were to choose from different courses from Guru99. You decide, click a link and skip a few pages. In the same way, a computer program has a set of strict rules to decide the flow of program execution.

C++ Data Structures


Let’s use a list of courses on “guru99” as the example! You probably have a list of courses in front of you. But how do you think they stored that. There can be a lot of courses, and different users may register for different courses. Do they generate a different variable for each user? For example, let’s say we need to keep track of 10 courses.

First, the WRONG WAY:

If we need to store 10 courses, we would probably define 10 variables, right?

Wrong.

In the world of programming, this is just a horrible way of trying to store 10 different variables. This is because of two main reasons:

  • The huge amount of text that you’ll need to write in your program. Sure, right now we only have 10 courses, so it’s not too bad, but what if we had 1,000 courses! Imagine typing that out a thousand times! Forget about it!
  • The flexibility. Adding another course would need manual edits to the code. We would have created variable course11. This is just crazy!

So, what is the RIGHT WAY?

Storing them in data structures.

data structure is a great way to get around having to create thousands of variables. C++ contains many types of inbuilt data structures. Most often used is arrays which will be taught later.


C++ Syntax


The syntax is a layout of words, expression, and symbols.

Well, it’s because an email address has its well-defined syntax. You need some combination of letters, numbers, potentially with underscores (_) or periods (.) in between, followed by an at the rate (@) symbol, followed by some website domain (company.com).

So, syntax in a programming language is much the same. They are some well-defined set of rules that allow you to create some piece of well-functioning software.

But, if you don’t abide by the rules of a programming language or syntax, you’ll get errors.


C++ Tools


In the real world, a tool is something (usually a physical object) that helps you to get a certain job done promptly.

Well, this holds true with the programming world too. A tool in programming is some piece of software which when used with the code allows you to program faster.

There are probably tens of thousands, if not millions of different tools across all the programming languages.

Most crucial tool, considered by many, is an IDE, an Integrated Development Environment. An IDE is a software which will make your coding life so much easier. IDEs ensure that your files and folders are organized and give you a nice and clean way to view them.

Published: By: Code Tutorial - January 24, 2023

Who uses C++?

 

Who uses C++?



Some of today’s most visible used systems have their critical parts written in C++.

Examples are Amadeus (airline ticketing)

  • Bloomberg (financial formation),
  • Amazon (Web commerce), Google (Web search)
  • Facebook (social media)

Many programming languages depend on C++’s performance and reliability in their implementation. Examples include:

  • Java Virtual Machines
  • JavaScript interpreters (e.g., Google’s V8)
  • Browsers (e.g., Internet Explorer, Mozilla’s Firefox, Apple’s Safari, and Google’s Chrome)
  • Application and Web frameworks (e.g., Microsoft’s .NET Web services framework).

Applications that involve local and wide area networks, user interaction, numeric, graphics, and database access highly depend on C++ language.

Published: By: Code Tutorial - January 24, 2023

Is C++ best programming language?

 

Is C++ best programming language?







The answer depends on perspective and requirements. Some tasks can be done in C++, though not very quickly. For example, designing GUI screens for applications.

Other languages like Visual Basic, Python have GUI design elements built into them. Therefore, they are better suited for GUI type of task.

Some of the scripting languages that provide extra programmability to applications. Such as MS Word and even photoshop tend to be variants of Basic, not C++.

C++ is still used widely, and the most famous software have their backbone in C++.

This tutorial will help you learn C++ basic and the advanced concepts.

Published: By: Code Tutorial - January 24, 2023

Popular programming languages in use?

 

Popular programming languages in use?

Popular languages that are mainly in use are Java, C++, Python, and C.

Lower level languages like

  • Assembly Language
  • C
  • C++

These languages force the programmer to think more about the problem in computer programming terms and its implementations, instead of the business logic.

As you can see despite being old, C++ is relatively popular still today which is a feat in and its own. The graph is from stackoverflow.com
Published: By: Code Tutorial - January 24, 2023

What is C++? Basic Concepts of C++ Programming Language

 

What is C++?




C++ is a general-purpose, object-oriented programming language. It was created by Bjarne Stroustrup at Bell Labs circa 1980. C++ is very similar to C (invented by Dennis Ritchie in the early 1970s). C++ is so compatible with C that it will probably compile over 99% of C programs without changing a line of source code. Though C++ is a lot of well-structured and safer language than C as it OOPs based.

Some computer languages are written for a specific purpose. Like, Java was initially devised to control toasters and some other electronics. C was developed for programming OS. Pascal was conceptualized to teach proper programming techniques. But C++ is a general-purpose language. It well deserves the widely acknowledged nickname “Swiss Pocket Knife of Languages.”

In this introduction to C++ tutorial, you will learn C++ basic concepts-



















Published: By: Code Tutorial - January 24, 2023