0% found this document useful (0 votes)
96 views21 pages

Programming Fundamental Lab No: 01 BEET, 2 Semester

This document provides an overview of programming fundamentals including: 1. The basic process of writing a program involves writing code, compiling it, running it, and debugging it until it works properly. 2. Programming languages use words and symbols that are converted into machine code during compilation so the computer can execute it. 3. Data types define sets of values and operations that can be performed on those values in C++ programs. Common data types include integers, floating-point numbers, characters, and enums.

Uploaded by

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

Programming Fundamental Lab No: 01 BEET, 2 Semester

This document provides an overview of programming fundamentals including: 1. The basic process of writing a program involves writing code, compiling it, running it, and debugging it until it works properly. 2. Programming languages use words and symbols that are converted into machine code during compilation so the computer can execute it. 3. Data types define sets of values and operations that can be performed on those values in C++ programs. Common data types include integers, floating-point numbers, characters, and enums.

Uploaded by

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

Programming Fundamental

Lab No: 01
BEET,2nd Semester

Instructor : Engr. Shabab Zahra


Department of Electrical Engineering & Technology
Objectives
 Idea behind Programming
 Complete process of Program execution
 Basics of data types
 Writing a sample C++ code
What's actually involved in programming?
 So, what's actually involved in programming - the actual process of writing
programs? Here's a quick overview of the process:
 Write a program.
 Compile the program.
 Run the program.
 Debug the program.
 Repeat the whole process until the program is finished.
Let's discuss those steps one by one
object code/program/source code.

 A computer program written in a high level language is called the source


program/source code.
 A computer program written in a machine language is called the object code.
Write a program.
 Programming languages commonly use words like "if", "repeat", "end" and
such. Also, they use the familiar mathematical operators like "+" and "=". It's
just a matter of learning the "grammar" of the language; how to say things
properly.
 So, we said "Write a program". This means: write the steps needed to perform
the task, using the programming language you know. You'll do the typing in a
programming environment.
 Incidentally, the stuff you type to create a program is usually called source
code, or just code.
Compile the program.

 When you write a program, it's not yet in a form that the computer can use.
Computers actually only understand lots of 1s and 0s in long streams. so you
write it in a more easily-understood form (a programming language), then you
convert it to a form that the computer can actually use. This conversion
process is called compiling.
Run the program.

 Now that you've compiled the program into a form that the computer can use,
you want to see if it works.you want to make the computer perform the steps
that you specified. This is called running the program, or sometimes
executing it. Just the same as how a car isn't much use if you don't drive it, a
program isn't much use if you don't run it.
Debug the program.

 You've probably heard the term "debug" before. It refers to fixing errors and
problems with your program.
 Once again, your programming environment will help you to debug your
programs. You usually debug your program by stepping through it. This means
just what it sounds like: you go through your program one step at a time,
watching how things are going and what's happening, Sooner or later (usually
later).
Difference between A library and Header file?

 In simple terms, library contains function body whereas header file contains
function prototype. Example: math.h is a header file which includes
function prototype for function calls like sqrt(),pow() etc.{ libm.so is the
library file used for these type of functions.} libc.so is a library file which
includes function body for function calls like cout,cin etc. {#include
<iostream> is the header file for these functions.}
Preprocessor Directives

 The instructions that are given to the complier before the beginning of the
actual program are called Preprocessor Directives. They starts with a
number sign (#) and the keyword “include” or “define”.
 #include <conio.h> is a C++ header file used mostly by MS-DOS compilers to
provide console input/output.
 Using namespace std; The std namespace is special; it is short for the
word "standard." The built in C++ library routines are kept in the standard
namespace. That includes stuff like cout, cin, string, vector, map, etc.
Because these tools are commonly used, it's popular to add "using namespace
std" at the top of your source code so that you won't have to type the std::
prefix constantly. Namespaces give you more freedom to use short, accurate
names.
Continue….

 Void main() / int main(): Void means "emptiness". It represents that the
functions main() does not return a value. On the other hand int main() makes
sure your program can return a value of type int to the OS on close.
 The empty parenthesis indicates that the function takes an unspecified
number of arguments (in C++, an empty parameter list is the same as using
void)
 Getch (): reads a single character directly from the keyboard, without
echoing to the screen.
Data type:

 A set of values together with a set of operations. C++ data types fall into the
following three categories:
 1. Simple data type
 2. Structured data type
 3. Pointers

Continue…..

 Simple Data Types: The simple data type is the fundamental data type in C++
because it becomes a building block for the structured data type. There are
three categories of simple data:
 1. Integral: It is a data type that deals with integers, or numbers without a
decimal part
 2. Floating-point: It is a data type that deals with decimal numbers
 3. Enumeration: It is a user-defined data type
Continue…..

 The int data type is used to represent integers between –2147483648 and
2147483647,
 and the data type short is used to represent integers between –32768 and
32767.
 Newer programming languages have only five categories of simple data types:
integer,
 real, char, bool, and the enumeration type. The integral data types that are
used in this
 manual are int, bool, and char.
Floating-Point Data Types:

 To deal with decimal numbers, C++ provides the floating point


 data type.
 You may be familiar with scientific notation. For example:43872918 =
4.3872918 * 107 {10 to the power of seven}.0000265 = 2.65 * 10-5 {10 to the
power of minus five},47.9832 = 4.79832 * 101 {10 to the power of one}
 To represent real numbers, C++ uses a form of scientific notation called
floating-point notation.
 C++ provides three data types to manipulate decimal numbers: float, double,
and long double.
Turbo C++

 Turbo C++ is an Integrated Development Environment (IDE) for creating


programs in C++,Since C++ is based on the C language.
 Turbo C is very easy to use. It provides facilities for typing, editing, saving and
compiling C and C++ programs. You can download Turbo C++ using below
mentioned Link
 https://www.filehorse.com/download-turbo-c/
 Download Turbo_C.zip and unzip it in a folder in C:\ drive. Double Click on
INSTALL.EXE
Steps
Step 2: File > New (as shown in above picture) and then write your C
program
Continue….

Step 3: Save the program using F2 (OR file > Save), remember the extension
should be “.c”. In the below screenshot I have given the name as helloworld.
Continue….
 Step 4: Compile the program using Alt+F9 OR Compile > Compile as shown in
figure.
Continue….
 Step 5: Press Ctrl + F9 to Run OR (select Run > Run un menu bar) the C
program.
Output

 Step 6: Alt+F5 to view the output of the program at the output screen
Note:
 You have to submit your assignment in soft form form before the start of the
next lab i.e. Lab#2. Similar lab reports will not be entertained.

You might also like