Search This Blog

Monday, 12 September 2022

UNIT 02: BASICS OF PROGRAMMING IN C++ - Lab Activity - Computer Science For Class X

GO TO INDEX

Computer Science For Class X
Unit 02: Basics Of Programming In C++
Lab Activity


1. In groups, students learn to download, install and configure Dev C++.

INTRODUCTION TO DEV-C++:

Dev-C++ is a fully featured graphical IDE (Integrated Development Environment) for programming in C / C++. DEV-C++ is developed by Bloodshed software. It was originally developed by Colin Laplace and first released in 1998. It is written in Delphi. With Dev C++ programmer can write Windows or console-based C/C++ programs easily.

INSTALLING AND CONFIGURING DEV-C++ IDE:
Dev-C++ is free available for download on Internet. After downloading the package begin the installation process. Following are the steps for installing Dec-C++ IDE.

STEP 1:
  • Select "English" as the language to be used for installation process.


STEP 2:
  • Press " I Agree" button to agree the license agreement.


STEP 3:
  • Select "Full" from the drop-down menu "for type of Install". This will select all the necessary components required to run Dev-C++ and compile C++ source code.
  • Click on "Next" to proceed.


STEP 4:
  • Select the installation folder (directory) where all the necessary Dev-C++ files and libraries will be installed. Usually, the default specified path is used for installation but we can change it if desired.
  • Click on "Install" to start installation.




STEP 5:
  • After completing process, it will show a "Finish" dialog box.
  • Make sure the "Run Dev-C++ 5..." is checked.
  • Click 'Finish' button. This will automatically start Dev-C++ after installation completes.


CONFIGURING DEV-C++:
  • Dev-C++ will require some configuration when it runs first time.
  • Set "English (Original)". as default interface language in the Dev-C++ first time configuration dialogue.
  • Click "Next" to continue.
  • On the "Theme" selection dialog box leave the default setting and click on "Next" to continue.
  • Click "OK' to close first time configuration dialogue.



LINKER SETTING FOR DEBUGGING:
Linker setting for bugging is required first time to obtain information about problems in source code. The following steps are used to enable this configuration.
  • Click on ToolsCompiler Options.
  • Open the Setting tab from the Compiler Options dialogue box.
  • Under Setting tab, open Linker tab.
  • In Linker tab change the Generate Debugging Information (-g3) options to Yes.
  • Click on OK to save setting.



DEVELOPING PROGRAM IN DEV-C++:
Development of C++ program requires writing source and saving those files for compilation. The steps to create a new project in Dev-C++ are:
  • Click on File ⇨ click NewProject.
  • In New Project dialog, Select Empty Project.
  • From language option, select C++ Project. Also enter Name for project.
  • Click on OK.
  • Dev C++ will ask path to save the new project, enter path and save project.



ADD NEW FILES TO PROJECT IN DEV-C++:
The step to create a new file are:
  • Click on Project ⇨ New File. Alternatively we can also right-click on the Project Name in the Project Explorer and click on the New File.
  • Click on Yes on the confirm dialog box to add a file.
  • To save newly added file, click on File ⇨ Save
  • Enter the path and provide its name.
  • Click on Save to Store the file.


COMPILE AND EXECUTE PROJECT IN DEV-C++:
The steps to compile and execute project are:
  • Project needs to compile before execution. To compile, click on Execute ⇨ Compile or press F9 key. Compiler Log tab shows the compilation status. Compiler tab will show if there are any syntax errors.
  • After successfully compiling the project, run it by clicking on Execute ⇨ Run or by pressing F10 key.
  • A console window will open and show the output of the program.

2. Teacher demonstrate the use of IDE and its feature as given in this unit. Also explain the use of variables and constants.

INTEGRATED DEVELOPMENT ENVIRONMENT (IDE):

  • An integrated development environment (IDE) is software for building applications or programs that combines common developer tools into a single graphical user interface (GUI).
  • IDE facilitates the development of applications designed to encompass all programming tasks in one application, one of the main benefits of an IDE is that they offer a central interface with all the tools, a developer needs.
  • For instance, Dev-C++, is used for making programs in C++ language.
  • However, there are many multiple language IDEs. Such as Eclipse (C, C++, Python, Perl, PHP, Java, Ruby and more) and Visual Studio Code (Java, JavaScript, PHP, Python, Ruby, C, C++ and more).

Explanation:
  • Integrated Development Environment (IDE):
  • IDEs provide interfaces for users to write code, organize text groups, and automate programming tools.
  • Instead of a simple plain-text editor, IDEs combine the functionality of multiple programming processes into one.
  • Most IDES come with built-in translators.
  • If any bugs or errors are found, users are shown which parts of code have problems.
  • Some IDEs are dedicated to a specific programming language or set of languages, having a set of tools and features which are helpful in writing codes for that language.

Key Benefits of Integrated Development Environments:
Serves as a single environment for most of a developer's needs such as compilation, linking, loading, and debugging tools.
Code completion capabilities improve programming workflow.
Automatically checks for errors to ensure top quality code.
Refactoring capabilities allow developers to make comprehensive and mistake-free renaming changes.

COMPONENTS OF INTEGRATED DEVELOPMENT ENVIRONMENT (IDE):
IDEs increase programmer productivity by combining common activities of writing software into a single application: editing source code, building executable, and debugging.

EDITING SOURCE CODE:
Writing and editing source codes is a major part of programming. A text editor is used for writing and editing source codes with feature providing language specific autocompletion, and checking for bugs as code is being written.

SYNTAX HIGHLIGHTING:
Syntax highlighting is a feature of IDEs that provides visual cues, keywords, and other words that have special meaning in languages (like class in C++) are highlighted with different colors. This feature makes code easier to read by visually clarifying different elements of language syntax or understand.

CODE COMPLETION:
It is a feature of IDE that completely knows the language syntax that speeds up process of coding by reducing typos and other mistakes. Autocompletion popups while typing, querying parameters of functions, query hints related to syntax errors.

COMPILER:
Compiler is a component of IDEs that translate source code (programming language) into machine code, such as binary codes. IDEs provide automated build process for languages, so the act of compiling and executing code is done automatically. Thus this feature can help automate developer tasks that are more common to save time.

LINKER:
Linker opens the compiled program file and connects or links referenced library files with compiled code as needed. Unless all linker items are resolved, the process stops and returns the user to the source code file within the text editor with an error message. If no problem encountered, it saved the linked objects into an executable file.

LOADER:
The IDE directs the operating system's program called the loader to loads executable files into the computer's memory and directs the Central Processing System (CPU) to start running the program as directed by the IDE.

DEBUGGING:
The process of removing errors from a program is known as debugging. When a program does not run correctly, IDEs provide debugging tools that allow programmer to examine different variables and inspect their codes step by step. IDE also provide hints while coding to prevent errors before compilation.
Thus, debugging is a multi-step process that involves identifying a problem, isolating the source of the problem. The final step of debugging is to test the correction or work around and make sure it works. Programmers and engineers can usually test the various segment of codes and identify errors before the application is released.

CONSTANT:

A constant is an identifier whose value remains unchanged through out the program.
OR
Constants and Variables A constant is a data item whose value cannot change during the program's execution. Thus, as its name implies - the value is constant.
OR
A constant is a value that cannot be altered by the program during execution, i.e., the value is constant. When associated with an identifier, a constant is said to be "named," although the terms "constant" and "named constant" are often used interchangeably.


TYPES OF CONSTANT:
Constants are used in two ways. They are:
  1. Literal Constants
  2. Defined Constants

LITERAL CONSTANT:
Literal constants are data used for representing fixed values. 'They can be used directly in the codes.
Example:
  • 1, 2, 5, "c", "good", "Hello World", false, null etc.

DEFINED OR SYMBOLIC CONSTANT:
In C++, we can create symbolic constant or named which are constant and represented by names. Symbolic constant value remains unchanged but used as a variable. A symbolic constant can be created using the #define preprocessor directive or const keyword.
Many programming languages use ALL CAPS to define name constant.
Example:
  • const int LIGHT_SPEED = 299792458;
  • #define LIGHT SPEED 29972458

VARIABLE:

A variable is nothing but a name given to a storage area that our programs can manipulate. In simple words, A variable is the memory location that can hold a value. Its value can change during program execution. Each variable C++ has a specified data type, which determine the size and layout of the variable's memory.
Example:
A class room with capacity of 20 students is a fixed placed or constant but the subject taught, the teacher and students may vary with each class and subject and are variables.

Variables do not require to be assigned initial value. Variables once defined may be assigned a value within the instructions of the program. Variables can be assigned different values at different time during execution.
Example:
x = 5:
x = 37;

RULES FOR NAMING VARIABLE:
The general rules for constructing names for variables (unique identifiers) are:
  • A variable name contains alphabets (letters), number, and underscores.
  • A variable name must start with a letter or an underscore (_).
  • Variable names are case sensitive. (myVar and myvar or Sum end sum are different variables)
  • Variable names cannot contain whitespaces or special characters like !, #, % etc.
  • Reserved words (Like C++ keyword, such as int cannot be used as names.
  • A variable name cannot be longer than 32 characters in C++ by default.

DECLARATION (CREATING) VARIABLE:
A variable declaration tells the compiler where and how much storage to create a variable. in other words, variable declaration is a process in which we create storage space for variable in memory.
A variable declaration consists of data type and name of the variable written as follow:
Syntax:
  • data_type variable_name,
  • int sum
Where type is one of C++ data type (such as int), and variable_ name is the name of the variable (such as x or myName)

INITIALIZATION:
Assign initial value to a variable is known as variable initialization. It can be initialized during declaration or separately. The initialization consists of an equal sign followed by a constant expression. The equal sign is used to assign value written as follows:
Syntax:
  • data_type variable_name value;
  • int sum = 3;

STRINGS IN C ++:
  • Variables that can store non numerical (alphanumeric) value that consist of multiple characters (longer than one single characters) are called strings.
  • The C++ language library provides supports for strings through the standard string class.  In C++, strings are used by one-dimensional array of characters, which is terminated by a null character \0.
  • This is not a fundamental type, but it behaves in a similar way as a fundamental types do in its most basic usage.
  • String can be declared without an initial value and can be assigned values during executions.


No comments:

Post a Comment