0% found this document useful (0 votes)
36 views22 pages

C++ Programming Basics and IDE Guide

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

C++ Programming Basics and IDE Guide

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Brief history and and

basic concept of C++


Language
then start programming

Corse instructor
Mr. Shahid Mehmood
Objective

• Understand the basic compiler concept


by using C++ compiler.
• Brief historical background of C++
• Familiar the Dev C++ interface.
• Understand the importance of header
and main function.
• Understand the importance of body
and statement's
Introduction with compiler
• Dev C++ is a simple, beginner-friendly IDE
(Integrated Development Environment) that
allows you to write, compile, and run C/C++.
• C is a general purpose high level programming
language. Because of its flexibility and
efficiency.
• It is widely used for software development.
• It allows the development of well-structured
programs.
• The data types and control structures are
directly supported by most computers, resulting
in the construction of efficient programs.
Evolution of C Language

• C was developed by Dennis Ritchie at Bell


Laboratories in 1972.
• It was evolved from ALGOL, BCPL(Basic
Combined Programming Language), and B.
• C uses many concepts of these languages and
new features like data types.
• It was then approved by the International
standards Organization (ISO) in 1990. It was
Characteristics of C
Language
• C language is well suited for structured
modular programming
• C is smaller which has minimal
instruction set and programs written in
C are efficient and fast
• C is highly portable
IDE (Integrated
Development Environment)
IDE is a software that facilitate the programmer to Write the
source code.
•Debug the source code.
•Compile the source code.
• Execute the program.
In a same environment.
Various IDEs are available for C/C++ programming, some
of commonly used are Turbo C++ , Dev-C++, Microsoft
Visual Source Code and Eclipse etc.
Dev-C++ IDE
Turbo C++ IDE
C++ Program Life Cycle
Editor

• Write source code in an IDE and


save it with extension .cpp.
• Vi and emacs for linux.
• Eclipse, dev-c++, MS visual studio for
window.
Preprocessor
• In a C/C++ language, a preprocessor program
executes automatically before the compiler’s
translation phase begins.

• The C/C++ preprocessor obeys special commands


called preprocessor directives, which indicate that
certain manipulations are to be performed on the
program before compilation.

• These manipulations usually consist of including


other files in the file to be compiled and performing
various text replacements.
Linker

• The next phase is called linking.


• C++ programs typically contain references to functions,
objects and classes defined elsewhere, such as in the
standard libraries or in the private libraries of groups of
programmers working on a particular project.
• The object code produced by the C compiler typically
contains “holes” due to these missing parts. A linker links
the object code with the code for the missing functions to
produce an executable image (with no missing pieces).
Loading

Before a program can be executed, the


program must first be placed in
memory. This is done by the loader,
which takes the executable image from
disk and transfers it to memory.
Execution

Finally, the computer, under the control

of its CPU, executes the program one

instruction at a time.
Questions?
First lab
 Proper use of IDE
 Installation
• Download Dev C++ from a trusted
source, like the official website.
• Follow the installation steps. Make sure
to include the MinGW compiler, which
will compile your C/C++ code.
Creating a New Project

• Open Dev C++.


• Go to File > New > Project.
• Choose Console Application (for
standard input-output programs).
• Select C++ Project and name your
project.
• Save it in a desired location
Writing Your First
Program
 Writing Your First Program
• After creating a new project, a blank code
file will open. If not, go to File > New >
Source File.
• Write a simple program, for example:
 #include <iostream>
 using namespace std;
 int main()
 {
 cout << "Hello, World!" << endl;
 return 0;
 }
Compiling and Running

Save your file (File > Save).


To compile, click on Execute > Compile or press F9.


After compiling, you can run it by clicking


Execute > Run or pressing F10


Perform arithmetic
operations
#include <iostream>
using namespace std;
int main()
{
int num1, num2;
cout << "Enter two numbers: ";
cin >> num1 >> num2;
// Perform arithmetic operations
cout << "Addition: " << num1 << " + " << num2 << " = " << (num1 + num2) <<
endl;
cout << "Subtraction: " << num1 << " - " << num2 << " = " << (num1 - num2)
<< endl;
cout << "Multiplication: " << num1 << " * " << num2 << " = " << (num1 * num2)
<< endl;
return 0;
}
First lab assignment
Write a single C++ statement or line that
accomplishes each of the following:
a) Print the message "Enter two numbers".
ANS: _________________________
b) Assign the product of variables b and c to variable a.
ANS: _________________________
c) State that a program performs a sample payroll
calculation (i.e., use text that helps to document a program).
ANS: ___________________________
d) Input three integer values from the keyboard and into
integer variables a, b and c.
ANS:__________________________
First lab assignment
 What, if anything, prints when each of the following C++ statements is
performed? If nothing prints, then answer “nothing.”
 Assume x = 2 and y = 3.
a) cout << x; f) z = x + y;
ANS: ___________________________ ANS___________________________
b) cout << x + x; g) cin >> x >> y;
ANS: __________________________ ANS: __________________________
c) cout << "x="; h) // cout << "x + y = " << x
+ y;
ANS: __________________________ ANS: __________________________
d) cout << "x = " << x; i) cout << "\n";
ANS: __________________________ ANS:
__________________________
e) cout << x + y << " = " << y + x;
ANS: _________________________

You might also like