1. FCPIT ASSIGNMENT NO. – 1
Overview of C++ Language
SUBMITTED By: Name: Priyanka
Class: CSE -2
SUBMITTED To:-
Department Of Computer Science
Guru Nanak Dev Engineering College, Gill Park, Ludhiana
3. INTRODUCTION
The C++ programming language is a very powerful general – purpose
programming language that supports procedural programming as well as
object – oriented programming. It incorporates all the ingredients required
for building software for large and complex problems.
The C++ language is treated as super set of C language because
the developer of C++ language have retained all features of C,
enhanced some of the existing features, and incorporated new features to
support for object – oriented programming.
The importance of C++ can well be judged from the following statement:
“Object – Oriented Technology is regarded as the ultimate
paradigm for the modeling of information, be that information data or
logic. The C++ has by now shown to fulfill this goal.”
4. EVOLUTION OF C++ LANGUAGE
The C++ programming language was developed by Bjarne Stroustrup at AT&T
BELL LABORATORIES, NEW JERSEY, USA, in the early 1980’s. He found
that as the problem size and complexity grows, it becomes extremely difficult to
manage it using most of procedural languages, even with C language.
He was strong admirer of Simula67 and C languages, and wanted to have a
language that combines the best of both of the languages, i.e., a language that
support object – oriented programming and have power and elegance of C
language. The outcome of this effort ultimately leads to the development of C++.
Since the classes were a major addition to the original C language, he initially
called the new language ‘C with classes’. However, later in 1983, the name was
changed to C++. The idea of suffixing C with ++ came from the increment
operator, since new features that existed and being used since long.
5. GENERAL STRUCTURE OF A C++ PROGRAM
SECTION 1: COMMENTS
SECTION 2: PREPROCESSOR DIRECTIVES
SECTION 3: GLOBAL DECLARATIONS
SECTION 4:
Void main
{
local declarations
statements
}
SECTION 5: OTHER FUNCTIONS AS REQUIRED
6. SECTION 1 is optional . It contains the description about the program.
SECTION 2 contains the preprocessor directives. The frequently used preprocessor
directives are include and define. These directives tell the preprocessor how to prepare
the program for compilation. The include directive tells which header files are to be
included in the program and the define directive is usually used to associate an
identifier with a literal that is to be used at many places in the program.
SECTION 3 is optional. It contains the global declarations. These declarations usually
include the declaration of the data items which are to be shared between many
functions in the program. It also include the decorations of functions.
SECTION 4 contains the main function. The execution of the program always begins
with the execution of the main function. The main function can call any number of
other functions, and those called function can further call other functions.
SECTION 5 is also optional. If present, it contains the other functions.
8. PROGRAM DEVELOPMENT LIFE CYCLE
Program development life cycle (PDLC) is a systematic way of
developing quality programs. It provides an organized plan for
breaking down the task of program development into manageable
chunks, each of which must be successfully completed before moving
on to the next phase. The program development process is divided
into following phases:
DEFINING THE PROBLEM The first step in developing a
program is to define the problem. The program specification precisely
defines the input data, the processing that should take place, the
format of the output reports and the user interface.
9. DESIGNING THE PROGRAM Program design begins by focusing on the main
goal that the program is trying to achieve and then breaking the program into
manageable components, each of which contributes to this goal. The first step involves
identifying the main routine which is the program’s major activity. From there,
programmers try to break down the various components of the main routine into
smaller units called modules, until each module is highly focused.
The various familiar program design tools are :STRUCTURE CHARTS – A structure chart, also called hierarchy chart, show the
top-down design of a program. Each box in the chart indicates a task that the program
must accomplish.
ALGORITHMS – An algorithm is a step-by-step description of how to arrive at a
solution.
FLOWCHARTS – A flowchart is a diagram that shows the logic of the program.
PSEUDOCODES – A pseudo code is another tool to describe the way to arrive at a
solution.
10. // C++ simple example
#include <iostream> //for C++ Input and Output
int main ()
{
int number3;
std::cout << "Enter a number:";
std::cin >> number3;
int number2, sum;
std::cout << "Enter another number:";
std::cin >> number2;
sum = number2 + number3;
std::cout << "Sum is: " << sum <<std::endl;
}
return 0;
11. BUILDING THE PROGRAM
Once the design of the program is ready, the next step is to convert the program
design into a computer.
CREATING AND EDITING PROGRAMS
We key in computer memory using a text editor. A text editor helps us to enter the
character data into computer memory, allows editing the data in computer
memory, and save the data from memory in a disk file on secondary memory with
extension “.cpp”. This stored file is known as source file, and its contents are
known as source code.
COMPILING PROGRAM
The source code in the source file, stored on the disk, must to be translated into
machine language. This job is done by the compiler. The C++ compiler actually is a
combination of two separate programs – the preprocessor and the translator.
The preprocessor reads the source code and prepares it for translation.
The translator reads the translation unit instruction-by-instruction and checks them for
their grammatical accuracy. If there is a syntax error in it, it flags an error message –
called diagnostic message on the screen.
12. LINKING PROGRAM
Once the source code is translated into object code, though it is in machine
language, still it is not in executable form.
A linker is a development tool that extracts the referred library functions from the
system libraries, reads the object codes of the user-defined functions from the
object files and integrates them with the current object code to produce the final
executable code, which is stored in disk file with extension “*.exe”. This
executable code is the final form of the program that is ready for execution.
EXECUTING PROGRAMS
Once the program is linked, it is ready for execution. To execute a program we
give an operating system command, such as run, to load the program into
computer memory and execute it. The loader locates the executable program in
the secondary storage, reads it and brings into the computer memory.
13. TESTING THE PROGRAM
A logical error is a mistake that the programmer made while designing the
solution to the problem. The programmer must find and correct logical errors by
carefully examining the program output for a set of data for which results are
already known.
DOCUMENTING THE PROGRAM
After testing the program development is almost complete . The structure charts,
algorithm, pseudo code, flow charts developed during the design phase become
documentation for others who are associated with the program . All of this
documentations needs to be saved and placed together for future reference.
14. DEPLOYING AND MAINTAINING THE PROGRAM
In the final phase, the program is deployed at the users site. Here also, the program
is kept under watch till the user gives green signals to it. Even after the
development project is complete, it needs to be maintained and evaluated regularly.
15. Programming Style
C++ is a free-format language, which
means that:
Extra blanks (spaces) or tabs before or after
identifiers/operators are ignored.
Blank lines are ignored by the compiler just
like comments.
Code can be indented in any way.
There can be more than one statement on a
single line.
A single statement can continue over several
lines.