Basic Program Structure and The Integrated Development Environment
Basic Program Structure and The Integrated Development Environment
Basic Program Structure and The Integrated Development Environment
○ headers,
○ class definition,
○ and main function.
Essential program structure…
● Note that C++ provides the flexibility of writing a program with or without a
class and its member functions definitions.
● A simple C++ program (without a class) includes comments, headers,
namespace, main() and input/output statements.
● Comments are a vital element of a program that is used to increase the
readability of a program and to describe its functioning.
● Comments are not executable statements and hence, do not increase the
size of a file.
Namespace
● Namespace: Since its creation, C++ has gone through many changes by the C++
Standards Committee.
● One of the new features added to this language is namespace.
● A namespace permits grouping of various entities like classes, objects, functions and
various C++ tokens, etc., under a single name.
● Different users can create separate namespaces and thus can use similar names of
the entities.
● This avoids compile-time error that may exist due to identical-name conflicts.
● The C++ Standards Committee has rearranged the entities of the standard library
under a namespace called std.
Namespace examples
● By specifying the using directive
using namespace std;
cout<<"Hello World";
#include<iostream>
■ Inline comments explaining the functioning of the subroutine or key aspects of the
algorithm shall be frequently used. See section 4.0 for guidance on the usage of inline
comments.
○ Structured Programming
■ Keep subroutines, functions, and methods reasonably sized. This depends upon the
language being used. For guidance on how large to make software modules and
methods. A good rule of thumb for module length is to constrain each module to one
function or action (i.e. each module should only do one “thing”). If a module grows too
large, it is usually because the programmer is trying to accomplish too many actions at
one time.
■ The names of the classes, subroutines, functions, and methods shall have verbs in
them. That is the names shall specify an action, e.g. “get_name”,
“compute_temperature”.
Coding/programming Standards …
○ Source Files
■ The name of the source file or script shall represent its function. All of the routines in a
file shall have a common purpose.
○ Variable Names
■ Variable shall have mnemonic or meaningful names that convey to a casual observer,
the intent of its use. Variables shall be initialized prior to its first use.
○ Use of Braces
■ In some languages, braces are used to delimit the bodies of conditional statements,
control constructs, and blocks of scope.
Coding/programming Standards …
○ Compiler Warnings
■ Compilers often issue two types of messages: warnings and errors. Compiler warnings
normally do not stop the compilation process. However, compiler errors do stop the
compilation process, forcing the developer to fix the problem and recompile.
■ Compiler and linker warnings shall be treated as errors and fixed. Even though the
program will continue to compile in the presence of warnings, they often indicate
problems which may affect the behavior, reliability and portability of the code. Some
compilers have options to suppress or enhance compile-time warning messages.
■ Developers shall study the documentation associated with a compiler and choose the
options which fully enable the compiler’s code-checking features.
Coding/programming guidelines
● General coding guidelines provide the programmer with a set of best
practices which can be used to make programs easier to read and
maintain.
● Unlike the coding standards, the use of these guidelines is not
mandatory.
● However, the programmer is encouraged to review them and attempt to
incorporate them into his/her programming style where appropriate.
● Most of the examples use the C language syntax but the guidelines can
be applied to all languages.
Coding/programming guidelines
● Line Length
○ It is considered good practice to keep the lengths of source code lines at or
below 80 characters.
○ Lines longer than this may not be displayed properly on some terminals and
tools.
■ All binary operators except “.” should be separated from their operands by
spaces. Blank spaces should never separate unary operators such as unary
minus, increment (“++”), and decrement(“—“) from their operands.
○ They allow a person not familiar with the code to more quickly understand it.
○ It also helps the programmer who wrote the code to remember details forgotten over time.
○ This reduces the amount of time required to perform software maintenance tasks.
○ As the name suggests, inline comments appear in the body of the source code itself. They explain the logic
or parts of the algorithm which are not readily apparent from the code itself. Inline comments can also be
used to describe the task being performed by a block of code.
Coding/programming documentation
● Code documentation is a guide that helps in understanding and correctly
utilizing the software code.
● The coding standards and naming conventions written in a commonly
spoken language in code documentation provide enhanced clarity for the
designer.
● Moreover, they act as a guide for the software maintenance team (this team
focuses on maintaining software by improving and enhancing the software
after it has been delivered to the end user) while the software maintenance
process is carried out. In this way, code documentation facilitates code
reusability.
Coding/programming documentation
● Some of the documentation techniques
○ Inline comments
○ Programming tools
Coding/programming documentation
○ compiler,
○ linker
○ and a debugger.
Integrated Development environment (IDE)…
● Example of C++ IDE’s
○ Dev C++
○ Borland C++
○ Celliot
○ Code::Blocks
○ Eclipse CDT(C/C++)
● Dev C++
● Celliot
● Borland C++
● Borland Turbo C++
● Code::block
Questions?
END