0% found this document useful (0 votes)
17 views17 pages

Lab 1-3 M

The document outlines a lab course on programming fundamentals using C++ at the Shaheed Zulfiqar Ali Bhutto Institute of Science and Technology. It covers the introduction to programming languages, the hierarchy of computer languages, and provides a detailed overview of C++ and its development environment, Dev C++. Additionally, it includes practical tasks for students to implement basic programming concepts and operations.

Uploaded by

mahedmemon110
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)
17 views17 pages

Lab 1-3 M

The document outlines a lab course on programming fundamentals using C++ at the Shaheed Zulfiqar Ali Bhutto Institute of Science and Technology. It covers the introduction to programming languages, the hierarchy of computer languages, and provides a detailed overview of C++ and its development environment, Dev C++. Additionally, it includes practical tasks for students to implement basic programming concepts and operations.

Uploaded by

mahedmemon110
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/ 17

SHAHEED ZULFIQAR ALI BHUTTO INSTITUTE OF

SCIENCE AND TECHNOLOGY

FUNDAMENTALS OF
PROGRAMMING(CSCL-1103)
Spring-2025

ID:2412197
Student’s Name: mahed mohammad memon
Lab Instructor: DR AWAIS AHMED

Department of Computer Science


Shaheed Zulfiqar Ali Bhutto Institute of Science And Technology
Gharo Campus

LAB 1 Introduction to Programming


Fundamentals, C++ and DEV C++
OBJECTIVES:
❖ Introduction of C++ programming Language
❖ Introduction of Dev C++ Programming Environment ❖ Basic Program writing and
error correction.
❖ Output using cout, Preprocessor Directives

INTRODUCTION TO PROGRAMMING LANGUAGES:


A computer is a computational device which is used to process the data under the control
of a computer program. Program is a sequence of instruction along with data. While
executing the program, raw data is processed into a desired output format. These computer
programs are written in a programming language which are high level languages. High
level languages are nearly human languages which are more complex than the computer
understandable language which are called machine language, or low level language.

Between high-level language and machine language there are assembly language also
called symbolic machine code. Assembly language are particularly computer architecture
specific. Utility program (Assembler) is used to convert assembly code into executable
machine code. High Level Programming Language are portable but require Interpretation
or compiling to convert it into a machine language which is computer understood.

HIERARCHY OF COMPUTER LANGUAGE:


Programmers write instructions in various programming languages, some directly understandable
by computers and others requiring intermediate translation steps. Hundreds of computer
languages are in use today. These may be divided into three general types

1. Machine languages
2. Assembly languages
3. High-level languages

Any computer can directly understand only its own machine language. Machine language is
the "natural language" of a computer and as such is defined by its hardware design.
Machine languages generally consist of strings of numbers (ultimately reduced to 1s and
0s) that instruct computers to perform their most elementary operations one at a time.
Machine languages are machine dependent (i.e., a particular machine language can be
used on only one type of computer).

Machine-language programming was simply too slow, tedious and error-prone for most
programmers. Instead of using the strings of numbers that computers could directly
understand, programmers began using English- like abbreviations to represent elementary
operations. These abbreviations formed the basis of assembly languages. Translator
programs called assemblers were developed to convert early assembly-language programs
to machine language at computer speeds.
Computer usage increased rapidly with the advent of assembly languages, but
programmers still had to use many instructions to accomplish even the simplest tasks. To
speed the programming process, high-level languages were developed in which single
statements could be written to accomplish substantial tasks. Translator programs called
compilers convert high-level language programs into machine language. High-level
languages allow programmers to write instructions that look almost like every day English
and contain commonly used mathematical notations.
From the programmer's standpoint, obviously, high-level languages are preferable to
machine and assembly language. C, C++, Microsoft's .NET languages (e.g., Visual
Basic .NET, Visual C++ .NET and C#) and Java are among the most widely used high-level
programming languages.
The process of compiling a high-level language program into machine language can take a
considerable amount of computer time. Interpreter programs were developed to execute
high-level language programs

Directly, although much more slowly. Interpreters are popular in program development
environments in which new features are being added and errors corrected. Once a program
is fully developed, a compiled version can be produced to run most efficiently.

INTRODUCTION TO C++:
C++ programming language is an enhanced version of C language that provides
objectoriented programming (OOP) capabilities. It is a superset of C, which means that you
can use a C++ compiler to compile C programs. Object oriented programming techniques
differ significantly from the sequential programming used in C programming language.

HISTORY OF C AND C++:


C++ evolved from C, which evolved from two previous programming languages, BCPL and
B. BCPL was developed in 1967 by Martin Richards as a language for writing
operatingsystems software and compilers for operating systems. Ken Thompson modeled
many features in his language B after their counterparts in BCPL and used B to create
early versions of the UNIX operating system at Bell Laboratories in 1970.
The C language was evolved from B by Dennis Ritchie at Bell Laboratories. C uses many
important concepts of BCPL and B. C initially became widely known as the development
language of the UNIX operating system. Today, most operating systems are written in C
and/or C++. C is now available for most computers and is hardware independent. With
careful design, it is possible to write C programs that are portable to most computers.
The widespread use of C with various kinds of computers (sometimes called hardware
platforms) unfortunately led to many variations. This was a serious problem for program
developers, who needed to write portable programs that would run on several platforms. A
standard version of C was needed. The American National Standards Institute (ANSI)
cooperated with the International Organization for Standardization (ISO) to standardize C
worldwide; the joint standard document was published in 1990 and is referred to as
ANSI/ISO 9899: 1990.
C++, an extension of C, was developed by Bjarne Stroustrup in the early 1980s at Bell
Laboratories. C++ provides a number of features that "spruce up" the C language, but more
importantly, it provides capabilities for object-oriented programming.
A revolution is brewing in the software community. Building software quickly, correctly and
economically remains an elusive goal, and this at a time when the demand for new and
more powerful software is soaring. Objects are essentially reusable software components
that model items in the real world. Software developers are discovering that using a
modular, object-oriented design and implementation approach can make them much more
productive than they can be with previous popular programming techniques. Objectoriented
programs are easier to understand, correct and modify.

THE INTEGRATED DEVELOPMENT ENVIRONMENT


(IDE):
Turbo C++ compiler has its own built-in text editor. The files you create with text editor
are called source files, and for C++ they typically are named with the extension .CPP, .CP,
or .C.
The C++ Developing Environment, also called as Programmer‟s Platform, is a screen
display with windows and pull-down menus. The program listing, error messages and other
information are displayed in separate windows. The menus may be used to invoke all the
operations necessary to develop the program, including editing, compiling, linking, and
debugging and program execution.

USING DEV C++ IDE:


The Dev C++ is a creative launching pad that you can use to edit, debug, and build code.

Figure 1: Dev C++ IDE

CREATING NEW SOURCE FILE:


Fig 2: Get started with DEV C++

Fig 3: C++ in DEV C++

TYPING AND COMPILING YOUR FIRST PROGRAM:


Now type your program as shown in figure 3. Save you program by pressing “ctrl + S”, give any

name to you file. Now click on “Compile and Run” icon to see the output of your program.

THE COMPILATION PROCESS:


A program goes from text files (or source files) to processor instructions as follows:
Object files are intermediate files that represent an incomplete copy of the program: each
source file only expresses a piece of the program, so when it is compiled into an object file,
the object file has some markers indicating which missing pieces it depends on. The linker
takes those object files and the compiled libraries of predefined code that they rely on, fills
in all the gaps, and spits out the final program, which can then be run by the operating
system (OS).
The compiler and linker are just regular programs. The step in the compilation process in which
the compiler reads the file is called parsing.
In C++, all these steps are performed ahead of time, before you start running a program. In
some languages, they are done during the execution process, which takes time. This is one
of the reasons C++ code runs far faster than code in many more recent languages.

Now perform the following changes. Is the program running as before? Write Yes or No and
explain why. Finally correct the program again.

1. Delete the line using namespace std from the program.

2. Write void main() instead of int main()

3. Write #include<abc> instead of #include<iostream>


4. Remove any one semi colon „; ‟.

5. Remove any one of brace „{‟ or „} ‟.

6. Write int main() ; instead of int main()

7. Write cout >> instead of cout <<


8. Remove the line return 0;

9. Write Main() instead of main()

10. Write COUT<< instead of cout<<

11. Remove inverted commas “ “ in line 7;


12. Remove # from #include<iostream>

TASK2:

Write a C++ program to print the following lines:

• Two is less than three.


• Capital of Germany is Berlin.
TASK3

Write five C++ statements to print the asterisk pattern as shown below.

**

***

****

First Program in C++, Variables and Data


Types
LAB 2
First Program in C++, Variables and Data Types
OBJECTIVES:
❖ Understanding Concept of Whitespace

❖ Output Using cout

❖ String Constants

❖ Preprocessor Directives

❖ Header File,

❖ Comments

❖ Defining Integer Variables

❖ Declarations and Definitions

❖ Variable Names

❖ Assignment Statements

❖ Integer Constants

❖ Output Variations

❖ The endl Manipulator


❖ Input with cin.

THE #INCLUDE DIRECTIVE:


Include the contents of another file, commonly called a header file, in your file. The header file
contains the declaration of different functions and objects. We have included “iostream.h” to use
“cout”, “cin” and “endl” in our program.

COMMENTS:
Comments are removed by the C pre-processor before the resulting program code is compiled
so the C Compiler does not see them but they can be read by humans looking at the contents
of your program file.

❖ Single Line Comment \\

❖ Many Line Comments Start with \* and end with *\


THE MAIN () FUNCTION:
When you run a C++ program, the first statement executed will be at the beginning of
a function called main ().

OUTPUT USING COUT:


The cout causes the phrase in quotation marks (called a string constant) to be displayed on
the screen. The identifier cout (pronounced “C out”) is actually an object. It is predefined in
C++ to correspond to the standard output stream. A stream is an abstraction that refers to a
flow of data. The operator << is called the insertion or put to operator. It directs the contents
of the variable on its right to the object on its left.

INTEGER VARIABLES
A variable has a name and can be given a value. Variables are located in particular
places in the computer‟s memory. When a variable is given a value, that value is actually
placed in the memory space assigned to the variable. Integer variables represent integer
numbers like 1, 30,000, and –27. The following statement is used to declare the integer
variable:

int var1;

ASSIGNMENT STATEMENTS:
The equal sign (=) causes the value on the right to be assigned to the variable on the left.
var1 = 10;

Variable Deceleration:
A variable declaration provides assurance to the
compiler that there is one variable existing with the given
type and name.

int a; char

b; float c; Variable Initialization in C+

+:
A variable can be initialized at the time of declaration or even after that.
int a=9; char

b=‟x‟; float

c=3.14159;

Constants :
Constants refer to fixed values that the program may not alter during its execution. These fixed
values are also called literals.

Defining Constants:
There are two simple ways in C++ to define constants:

Using #define preprocessor

#define LENGTH 10
#define WIDTH 5
Using const keyword
const int LENGTH =
10; const int WIDTH =
5; PROGRAM 2:

INPUT WITH CIN:


The cin causes the program to wait for the user to type in a value. The value is placed in a
variable. The keyword cin (pronounced “C in”) is an object, predefined in C++ to correspond
to the standard input stream. This stream represents data coming from the keyboard. The >>
is the extraction or get from operator. It takes the value from the stream object on its left and
places it in the variable on its right. For Example:

cin
>> var1;

ARITHMETIC OPERATORS:
The symbols +, -, *, / are the arithmetic operator used to perform addition, subtraction, multiplication
and division between two numbers or variables.
Task 1:

Take two integers as input from the user apply athematic operations on them (+,-,*,/) as print Them
on screen.

Task 2:
Take all input from user
❖ Calculate the Area of a Circle (area = PI * r2)

❖ Calculate the Area of a Rectangle (area = length * width) ❖ Calculate

the Area of a Triangle (area = base * height * .5) ❖ Calculate the volume of a

sphere.
Task 3:
Write down a program which takes the temperature in Fahrenheit °F from use r and
displays the output in Celsius °C

°C = 5/9(°F – 32)

Task 4:
Total Purchase a customer in a store is purchasing five items. The prices of the five items
are:
Price of item 1 = $12.95
Price of item 2 = $24.95

Price of item 3 = $6.95

Price of item 4 = $14.95

Price of item 5 = $3.95


Write a program that holds the prices of the five items in five variables. Display each items Price,
the subtotal of the sale, the amount of sales tax, and the total. Assume the sales tax 6%.

You might also like