0% found this document useful (0 votes)
6 views

Lesson1 Fundamentals of C- Prog

The document provides an overview of C++ programming, detailing its history, structure, and functionalities. It outlines the objectives for students learning C++, including understanding its standard libraries and basic programming constructs. Additionally, it discusses the differences between compiled and interpreted languages, and includes resources for further learning.

Uploaded by

jervinbucu30
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Lesson1 Fundamentals of C- Prog

The document provides an overview of C++ programming, detailing its history, structure, and functionalities. It outlines the objectives for students learning C++, including understanding its standard libraries and basic programming constructs. Additionally, it discusses the differences between compiled and interpreted languages, and includes resources for further learning.

Uploaded by

jervinbucu30
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

DON HONORIO VENTURA STATE

UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

FUNDAMENTALS OF C++ PROGRAMMING


Descriptio
n
C++ is a powerful general-purpose programming language. It can be used to
develop operating systems, browsers, games, and so on. C++ supports
different ways of programming like procedural, object-oriented, functional,
and so on. This makes C++ powerful as well as flexible.

Objectives
After completing the module, the students are expected to:
 Appreciate the history of the C++ programming language
 Familiarize with the terms used in C++ programming language
 Able to construct the basic structure of C++
 Understand the C++ standard library/libraries and headers
 Understand the files and standard functions

Instructions

 Engage students with the topic by demonstrating them how to construct


functions in Dev C++ IDE.
 Elaborate each function to have a deeper understanding in constructing
the basic C++ structure.
 Discuss content and answer questions. Check for understanding by asking:

 What are the main parts of the basic structure of C++ programming
language?
 What is the standard library of C++ programming language?
 How does Bjarne Stroustroup make the C++ programming language?
 What is the difference of <iostream> and <iomanip> header libraries?
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

Resources (Educational Materials):


url: videos: https://www.youtube.com/watch?
https://goalkicker.com/CPlusPlusBook/ v=vLnPwxZdW4Y
https://www.w3schools.com/cpp/cpp_getst https://www.youtube.com/watch?
arted.asp v=_bYFu9mBnr4
http://www.cplusplus.com/info/description/ https://www.youtube.com/watch?
https://www.programiz.com/cpp- v=JBjjnqG0BP8
programming
https://www.studytonight.com/cpp/introduc
tion-to- cpp.php
https://docs.oracle.com/cd/E19957-
01/806- 3569/Standard.html
https://docs.microsoft.com/en-us/cpp/st
andard- library/iostream?view=vs-2019
https://www.softwaretestinghelp.com/i
omanip-
functions-in-cpp/

Computers are some of the most versatile tools that we have available. They are
capable of performing stunning feats of computation, they allow information to be
exchanged easily regardless of their physical location, they simplify many every-day
tasks, and they allow us to automate many processes that would be tedious or boring to
perform otherwise. However, computers are not "intelligent" as we are. They have to be
told in no uncertain terms exactly what they're supposed to do, and their native languages
are quite unlike anything we speak. Thus, there's a formidable language barrier between a
person who wishes a computer to do something, and the computer that typically requires
instructions in its native language, machine code, to do anything. So far, computers
cannot figure out what they are supposed to do on their own, and thus they rely on
programs which we create, which are sets of instructions that the computer can
understand and follow.

Overview of Programs and Programming Languages


A program is an executable software that runs on a computer. It is similar to a
script, but is often much larger in size and does not require a scripting engine to run.
Instead, a program consists of compiled code that can run directly from the computer's
operating system. Programming language is the communication between the user and the
computer itself.
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

Compiled Languages
are translated to the target machine’s native language by a program called a
compiler. This can result in very fast code, especially if the compiler is effective at
optimizing, however the resulting code may not port well across operating systems and
the compilation process may take a while.

Interpreted Languages
are read by a program called an interpreter and are executed by that program.
While they are as portable as their interpreter and have no long compile times, interpreted
languages are usually much slower than an equivalent compiled program.

JIT Compiled (just-in-time) languages


languages are languages that are quickly compiled when programs written in them
need to be run (usually with very little optimization), offering a balance between
performance and portability.

Low-level language
is generally quite similar to machine code, and thus is more suitable for programs
like device drivers or very high-performance programs that really need access to the
hardware.

High-level language
focuses more on concepts that are easy to understand by the human mind, such as
objects or mathematical functions.

Introduction to C++ Programming Language


C++, is an extension to C language and was developed by Bjarne Stroustrup at Bell
labs. C++ is an intermediate level language, as it comprises a confirmation of both high-
level and low-level language features. C++ is a statically typed, free form, multiparadigm,
compiled general-purpose language. C++ is an object-oriented programming language
but is not purely object oriented.
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

History of C++ Programming Language


The C++ programming language has a history going back to 1979, when Bjarne
Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the
opportunity to work with was a language called Simula, which as the name implies is a
language primarily designed for simulations. The Simula 67 language – which was the
variant that Stroustrup worked with – is regarded as the first language

to support the object-oriented programming paradigm. Stroustrup found that this


paradigm was very useful for software development, however the Simula language was
far too slow for practical use. Shortly thereafter, he began work on “C with Classes”, which
as the name implies was meant to be a superset of the C language. His goal was to add
object-oriented programming into the C language, which was and still is a language well-
respected for its portability without sacrificing speed or low-level functionality. His
language included classes, basic inheritance, inlining, default function arguments, and
strong type checking in addition to all the features of the C language.

The first C with Classes compiler was called Cfront, which was derived from a C compiler
called Cpre. It was a program designed to translate C with Classes code to ordinary C. A
rather interesting point worth noting is that Cfront was written mostly in C with Classes,
making it a self-hosting compiler (a compiler that can compile itself). Cfront would later be
abandoned in 1993 after it became difficult to integrate new features into it, namely C++
exceptions. Nonetheless, Cfront made a huge impact on the implementations of future
compilers and on the Unix operating system.

Timeline Event
1993 The name of the language was changed from C with
Classes to C++. The ++ operator in the C language
is an operator for incrementing a variable, which
gives some insight into how Stroustrup regarded the
language.

1985 Stroustrup’s reference to the language entitled The


C++ Programming Language was published. That
same year, C++ was implemented as a commercial
product.
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

1990 The Annotated C++ Reference Manual was released.


The same year, Borland's Turbo C++ compiler would
be released as a commercial product. Turbo C++
added a plethora of additional libraries which would
have a considerable impact on C++'s development.

1998 The C++ standards committee published the first


international standard for C++ ISO/IEC 14882:1998,
which would be informally known as C++98.

2005 The C++ standards committee released a technical


report (dubbed TR1) detailing various features they
were planning to add to the latest C++ standard.

Mid 2011 The new C++ standard (dubbed C++11) was


finished. The Boost library project made a
considerable impact on the new standard, and some
of the new modules were derived directly from the
corresponding Boost libraries.

Version Standard Release


Date
C++98 ISO/EIC 09-01-1998
14882:1998
C++03 ISO/EIC 10-16-2003
14882:2003
C++11 ISO/EIC 09-01-2011
14882:2011
C++14 ISO/EIC 12-15-2014
14882:2014
C++17 ISO/EIC 01-01-2017
14882:2017
C++20 ISO/EIC 01-01-2020
14882:2020
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

Basic Structure of C++

Example explained

Line 1: #include <iostream> is a header file library that lets us work with input and
output objects, such as cout (used in line 5). Header files add functionality to C++
programs.

Line 2: using namespace std means that we can use names for objects and variables
from the standard library.

Don't worry if you don't understand how #include <iostream> and using namespace
std works. Just think of it as something that (almost) always appears in your program.

Line 3: A blank line. C++ ignores white space. But we use it to make the code more
readable.

Line 4: Another thing that always appear in a C++ program, is int main(). This is called
a function. Any code inside its curly brackets {} will be executed.

Line 5: cout (pronounced "see-out") is an object used together with the insertion
operator (<<) to output/print text. In our example it will output "Hello World!".

Note: Every C++ statement ends with a semicolon ;.

Note: The body of int main() could also been written as:
int main () { cout << "Hello World! "; return 0; }

Remember: The compiler ignores white spaces. However, multiple lines makes the
code more readable.

Line 6: return 0 ends the main function.

Line 7: Do not forget to add the closing curly bracket } to actually end the main
function.
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

Omitting Namespace

You might see some C++ programs that runs without the standard namespace library.
The using namespace std line can be omitted and replaced with the std keyword,
followed by the :: operator for some objects:

Comments

Comments can be used to explain the C++ code, and to make it more readable. It can also
be used to prevent execution when testing alternative code.
 Single-line comments start with two forward slashes (//)
 Multi-line comments start with (/*) and ends with (*/). Any text between the
comment symbols will be ignored by the compilers.
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

C++ Standard Library Header Files


HEADER DESCRIPTION
<typeinfo> Run-time type identification
<utility> Comparison operators
<valarra Value arrays useful for numeric programming
y>
<vector> Sequences supporting random access
<new> Basic memory allocation and deallocation
<memory> Special memory allocators
<iterator Class for traversing a sequence
>
<limits> Properties of numeric types
<list> Ordered sequences
<locale> Support for internationalization
<map> Associative containers with key/value pairs
<numeri Generalized numeric operations
c>
<ostream> Output I/O streams
<queue> Sequences supporting addition at the head and removal at
the tail
<set> Associative container with unique keys
<sstream> Stream I/O using an in-memory string as source or sink
<stack> Sequences supporting addition and removal at the head
<stdexcept> Additional standard exception classes
<streambuf> Buffer classes for iostreams
<string> Sequences of characters
<algorithm> Standard algorithms that operate on containers
<bitset> Fixed-size sequences of bits
<complex> The numeric type representing complex numbers
<deque> Sequences supporting addition and removal at each end
<exception> Predefined exception classes
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

<frstream> Stream I/O on files


<functional> Function objects
<iomanip> iostream manipulators
<ios> iostream base classes
<iosfwd Forward declarations of iostream classes
>
<iostream> Basic stream I/O functionality
<istrea Input I/O streams
m>

Files and Standard Function


<iostream>
The C++ <iostream> header file declares a set of functions for standard
Input/Output.
It also defines I/O stream objects such as cin, cout, clog, etc.
This class inherits members from its two parent classes istream
and ostream, thus being able to perform both input and output
operations.

Name Descriptions
cerr The object cerr controls output to a stream buffer associated
with the object stderr, declared in <cstdio>.
cin Specifies the cin global stream.
clog Specifies the clog global stream.
cout Specifies the cout global stream.
wcerr Specifies the wcerr global stream.
wistream The object controls extractions from the standard input as a
wide
stream. Once the object is constructed, the call wcin.tie
returns &wcout.
wclog Specifies the wclog global stream.
wostream The object controls insertions to the standard output
as a wide stream.
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

<iomanip>
The header <iomanip> is part of the Input/output library of the C++
Standard Library. It defines the manipulator functions resetiosflags(), setiosflags(),
setbase(), setfill(), setprecision(), and setw(). These functions may be conveniently
used by C++ programs to affect the state of iostream objects. It contains the
functions that we can use to format the output of the C++ program. These
functions can be used one at a time or together to make the output of our program
more presentable.

Functions for the output


 Setprecision: This function sets the precision for decimal or float values.
 Setw: Setw function sets the field width or number of characters
that are to be displayed before a particular field.
 Setfill: Setfill function is used to fill the stream with char type c
specified as a parameter.
Setprecision
Function Prototype: setprecision (int n).
Parameter(s): n=>value of the decimal
precision to be set.
Return Value: unspecified
Description: This function sets the
decimal precision for floating-point
values. This format the floating-point
when displayed.
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

Setw
Function Prototype: setw (int n).
Parameter(s): n=> value of the field
width (number of characters) to be
used.
Return Value: unspecified
Description: Function setw sets the field
width or the number of characters to be
used for outputting numbers.

Setfill
Function Prototype: setfill (char_type c).
Parameter(s): n=> new fill character
for the stream; char_type: type of
characters used by stream.
Return Value: unspecified
Description: setfill sets c as the new fill
character for the stream.
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

References:
 Goodrich, Michael et.al (2011). Data Structures and Algorithms in C++. John
Wiley & Sons Inc, United States of America
 Educational Technology Journals.
http://www.educational-software-directory.net/publications/journals
 CPlusPlusNotesForProfessionals. http://www.GoalKicker.com
 C++ Tutorials. http://www.programiz.com
 C++ Tutorials. http://www.w3schools.in

You might also like