Lab 1-3 M
Lab 1-3 M
FUNDAMENTALS OF
PROGRAMMING(CSCL-1103)
Spring-2025
ID:2412197
Student’s Name: mahed mohammad memon
Lab Instructor: DR AWAIS AHMED
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.
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.
name to you file. Now click on “Compile and Run” icon to see the output of your program.
Now perform the following changes. Is the program running as before? Write Yes or No and
explain why. Finally correct the program again.
TASK2:
Write five C++ statements to print the asterisk pattern as shown below.
**
***
****
❖ String Constants
❖ Preprocessor Directives
❖ Header File,
❖ Comments
❖ Variable Names
❖ Assignment Statements
❖ Integer Constants
❖ Output Variations
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.
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
+:
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:
#define LENGTH 10
#define WIDTH 5
Using const keyword
const int LENGTH =
10; const int WIDTH =
5; PROGRAM 2:
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)
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