0% found this document useful (0 votes)
32 views11 pages

CSC 204 Lecture 2

Computer programming language ||

Uploaded by

taibatlawal0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views11 pages

CSC 204 Lecture 2

Computer programming language ||

Uploaded by

taibatlawal0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Structured programming Concept

In structured programming design, programs are broken into different functions these functions
are also known as modules, subprogram, subroutines or procedures. Each function is design to
do a specific task with its own data and logic. Information can be passed from one function to
another function through parameters. A function can have local data that cannot be accessed
outside the function’s scope. The result of this process is that all the other different functions are
synthesized in another function. This function is known as main function. Many of the high-level
languages support structured programming.
Structured programming minimizes the chances of the function affecting another. It allows for
clearer programs code. It made global variables to disappear and replaced by the local variables.
Due to this change one can save the memory allocation space occupied by the global variable. Its
organization helps in the easy understanding of programming logic. So that one can easily
understand the logic behind the programs. It also helps the newcomers of any industrial
technology company to understand the programs created by their senior workers of the industry.
The languages that support Structured programming approach are:
•C
• C++
• Java
• C#
• Pascal

Advantages of Structured programming


 It is user friendly and easy to understand.
 Similar to English vocabulary of words and symbols.
 It is easier to learn.
 They require less time to write.
 They are easier to maintain.
 These are mainly problem oriented rather than machine based.
 Program written in a higher-level language can be translated into many machine languages
and therefore can run on any computer for which there exists an appropriate translator.
 It is independent of machine on which it is used, i.e., programs developed in high level
languages can be run on any computer.
Disadvantages of Structured Programming
 Structured programming codes implemented in high-level language has to be translated into
the machine language by translator and thus a price in computer time is paid.
 The object code generated by a translator might be inefficient compared to an equivalent
assembly language program.
 Data type are proceeds in many functions in a structured program. When changes occur in
those data types, the corresponding change must be made to every location that acts on those
data types within the program. This is really a very time consuming task if the program is very
large.
 In a structured program, each programmer is assigned to build a specific set of functions and
data types. Since different programmers handle separate functions that have mutually shared data
type, other programmers in the team must reflect the changes in data types done by the
programmer in data type handled. Otherwise, it requires rewriting several functions.

Introduction to C++ development


Characteristics of C++
C++ is not a purely object-oriented language but a hybrid that contains the functionality
of the C programming language. This means that you have all the features that are available in C:
■ universally usable modular programs
■ efficient, close to the machine programming
■ portable programs for various platforms.
The large quantities of existing C source code can also be used in C++ programs.
C++ supports the concepts of object-oriented programming (or OOP for short),
which are:
■ data abstraction, that is, the creation of classes to describe objects
■ data encapsulation for controlled access to object data
■ inheritance by creating derived classes (including multiple derived classes)
■ polymorphism (Greek for multiform), that is, the implementation of instructions
that can have varying effects during program execution.

Traditional Procedural Programming


In traditional, procedural programming, data and functions (subroutines, procedures) are kept
separate from the data they process. This has a significant effect on the way a program handles
data:
■ the programmer must ensure that data are initialized with suitable values before use and that
suitable data are passed to a function when it is called
■ if the data representation is changed, e.g. if a record is extended, the corresponding functions
must also be modified.
Both of these points can lead to errors and neither support low program maintenance
requirements.

Objects
Object-oriented programming shifts the focus of attention to the objects, that is, to the aspects on
which the problem is centered. A program designed to maintain bank accounts would work with
data such as balances, credit limits, transfers, interest calculations, and so on. An object
representing an account in a program will have properties and capacities that are important for
account management.
OOP objects combine data (properties) and functions (capacities). A class defines a certain
object type by defining both the properties and the capacities of the objects of that type. Objects
communicate by sending each other “messages,” which in turn activate another object’s
capacities.

Advantages of OOP
Object-oriented programming offers several major advantages to software development:
■ reduced susceptibility to errors: an object controls access to its own data. More specifically, an
object can reject erroneous access attempts
■ easy re-use: objects maintain themselves and can therefore be used as building blocks for other
programs
■ low maintenance requirement: an object type can modify its own internal data representation
without requiring changes to the application.
The following three steps are required to create and translate a C++ program:
1. First, a text editor is used to save the C++ program in a text file. In other words, the source
code is saved to a source file. In larger projects the programmer will normally use modular
programming. This means that the source code will be stored in several source files that are
edited and translated separately.
2. The source file is put through a compiler for translation. If everything works as planned, an
object file made up of machine code is created. The object file is also referred to as a module.
3. Finally, the linker combines the object file with other modules to form an executable file.
These further modules contain functions from standard libraries or parts of the program that have
been compiled previously.
It is important to use the correct file extension for the source file’s name. Although the file
extension depends on the compiler you use, the most commonly found file extensions are .cpp
and .cc.
Prior to compilation, header files, which are also referred to as include files, can be copied to the
source file. Header files are text files containing information needed by various source files, for
example, type definitions or declarations of variables and functions. Header files can have the
file extension .h, but they may not have any file extension.
The C++ standard library contains predefined and standardized functions that are available for
any compiler.
Modern compilers normally offer an integrated software development environment, which
combines the steps mentioned previously into a single task. A graphical user interface is
available for editing, compiling, linking, and running the application. Moreover, additional tools,
such as a debugger, can be launched.
A C++ program is made up of objects with their accompanying member functions and global
functions, which do not belong to any single particular class. Each function fulfills its own
particular task and can also call other functions. You can create functions yourself or use ready-
made functions from the standard library. You will always need to write the global function main
() yourself since it has a special role to play; in fact it is the main program.
The short programming example on the opposite page demonstrates two of the most important
elements of a C++ program. The program contains only the function main () and displays a
message.
The first line begins with the number symbol, #, which indicates that the line is intended for the
preprocessor. The preprocessor is just one step in the first translation phase and no object code is
created at this time. You can type
#include <filename>
to have the preprocessor copy the quoted file to this position in the source code. This allows the
program access to all the information contained in the header file. The header file iostream
comprises conventions for input and output streams. The word stream indicates that the
information involved will be treated as a flow of data.
Predefined names in C++ are to be found in the std (standard) namespace. The using directive
allows direct access to the names of the std namespace.
Program execution begins with the first instruction in function main(), and this is why each C++
program must have a main function. The structure of the function is shown on the opposite page.
Apart from the fact that the name cannot be changed, this function’s structure is not different
from that of any other C++ function.
In our example the function main () contains two statements. The first statement
cout << "Enjoy yourself with C++!" << endl;
outputs the text string Enjoy yourself with C++! on the screen. The name cout (console output)
designates an object responsible for output.
The two less-than symbols, <<, indicate that characters are being “pushed” to the output stream.
Finally endl (end of line) causes a line feed. The statement
return 0;
terminates the function main() and also the program, returning a value of 0 as an exit code to the
calling program. It is standard practice to use the exit code 0 to indicate that a program has
terminated correctly.
Note that statements are followed by a semicolon. By the way, the shortest statement comprises
only a semicolon and does nothing.

You might also like