The Vasant Valley School Science Magazine

An Intro to Coding

By Aditya Chopra

Coding is analogically(and structurally) like a language. The way societies are built from the ground up on the basis of language and communication, computers are built from the ground up on lines of code. These lines of code, execute a task which they are specifically asked to carry out. The hardware of a system provides the power needed to push a command while the software is a series of instructions and task details. That is the essence of coding. Its initiation seems abstract and its application vague. But bit by bit (or may I say byte by byte) you’re contributing your part to the digital era.

What is unique about C++

As an introduction to C++ coding, I would like to provide an overview into its basics. C++ is a language which differentiates itself from other languages because of its additional features of Object Oriented Programming. By definition, we could code, lets say, a car. To add features to this car, we would create a class for it called Car. In this car we could define the name of the car, its features, registration no. etc. Now we have for ourselves a well described car with all its characteristics stored in our data. Lets say we are a company which records the sale of a thousand such cars daily. Instead of repeating our code over and over, object oriented programming allows us to creates objects, derived from this class which have all the characteristics of the class, but specific to the object. The ability to create such objects and classes and inheriting data members from one class to another is what sets C++ aside from most other languages.

The absolute basics

C++ has a few essential elements: each C++ code has a mandated main function, which is the primary code in which tasks place. The main function is the only mandatory part of every code. To use predefined functions, the compiler (the software which executes a code) includes header files, which act as files which contain code for the more usual commands like inputting data, outputting data, mathematical operations etc. Header files act as preprocessor directives (just fancy terminology) and allow you to circumvent the need to code some basic commands. The last essential element of the language are keywords, these preexisting words are what helps you access the codes in the header files.

#include <name of header file> //syntax to invoke a header file

int main() //syntax for main function

{

cout<<“Hello world! ”;//cout is a keyword present in the header file <iostream> used for outputting data

}

That was the most basic of all C++ codes.

To carry out algebraic tasks one must first define data members.

C++ has a large amount of data types. For the more conventional coding we use the following data types:

int – integer data type

char – character data type

float – decimal data type

long int – integer data type with double the digits

long float – decimal data type with double the digits.

To define a variable, we need a variable name. The name of a variable can be anything except a keyword.