[go: up one dir, main page]

0% found this document useful (0 votes)
24 views19 pages

C M M Theory

Uploaded by

fadzimushayi
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)
24 views19 pages

C M M Theory

Uploaded by

fadzimushayi
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/ 19

Programmers write instructions in various programming languages to perform their computation

tasks such as:

(i) Machine level Language

(ii) Assembly level Language

(iii) High level Language

Machine level Language :

Machine code or machine language is a set of instructions executed directly by a computer's central

processing unit (CPU). Each instruction performs a very specific task, such as a load, a jump, or an

ALU operation on a unit of data in a CPU register or memory. Every program directly executed by a

CPU is made up of a series of such instructions.

Assembly level Language :

An assembly language (or assembler language) is a low-level programming language for a computer,

or other programmable device, in which there is a very strong (generally one-to-one) correspondence

between the language and the architecture's machine code instructions. Assembly language is

converted into executable machine code by a utility program referred to as an assembler; the

conversion process is referred to as assembly, or assembling the code.

High level Language :

High-level language is any programming language that enables development of a program in much

simpler programming context and is generally independent of the computer's hardware architecture.

High-level language has a higher level of abstraction from the computer, and focuses more on the

programming logic rather than the underlying hardware components such as memory addressing and

register utilization.

The first high-level programming languages were designed in the 1950s. Now there are dozens of

different languages, including Ada , Algol, BASIC, COBOL, C, C++, JAVA, FORTRAN, LISP,

Pascal, and Prolog. Such languages are considered high-level because they are closer to human
languages and farther from machine languages. In contrast, assembly languages are considered low

level because they are very close to machine languages.

The high-level programming languages are broadly categorized in to two categories:

(iv) Procedure oriented programming(POP) language.

(v) Object oriented programming(OOP) language.

Procedure Oriented Programming Language

In the procedure oriented approach, the problem is viewed as sequence of things to be done such as

reading , calculation and printing.

Procedure oriented programming basically consist of writing a list of instruction or actions for the

computer to follow and organizing these instruction into groups known as functions.

The disadvantage of the procedure oriented programming languages is:

1. Global data access

2. It does not model real word problem very well

3. No data hiding

Characteristics of procedure oriented programming:

1. Emphasis is on doing things(algorithm)

2. Large programs are divided into smaller programs known as functions.

3. Most of the functions share global data

4. Data move openly around the system from function to function

5. Function transforms data from one form to another.

6. Employs top-down approach in program design

Object Oriented Programing

“Object oriented programming as an approach that provides a way of modularizing programs by

creating partitioned memory area for both data and functions that can be used as templates for

creating copies of such modules on demand”.


Features of the Object Oriented programming

1. Emphasis is on doing rather than procedure.

2. programs are divided into what are known as objects.

3. Data structures are designed such that they characterize the objects.

4. Functions that operate on the data of an object are tied together in the data

structure.

5. Data is hidden and can’t be accessed by external functions.

6. Objects may communicate with each other through functions.

7. New data and functions can be easily added.

8. Follows bottom-up approach in program design.

BASIC CONCEPTS OF OBJECTS ORIENTED PROGRAMMING

1. Objects

2. Classes

3. Data abstraction and encapsulation

4. Inheritance

5. Polymorphism

6. Dynamic binding

7. Message passing

BENEFITS OF OOP:
Oop offers several benefits to both the program designer and the user. Object-oriented contributes to

the solution of many problems associated with the development and quality of software products.

The principal advantages are :

1. Through inheritance we can eliminate redundant code and extend the use of existing

classes.

2. We can build programs from the standard working modules that communicate with one

another, rather than having to start writing the code from scratch. This leads to saving of

development time and higher productivity.


3. This principle of data hiding helps the programmer to build secure programs that can’t be

invaded by code in other parts of the program.

4. It is possible to have multiple instances of an object to co-exist with out any interference.

5. It is easy to partition the work in a project based on objects.

6. Object-oriented systems can be easily upgraded from small to large systems.

7. Message passing techniques for communication between objects makes the interface

description with external systems much simpler.

8. Software complexity can be easily managed.

APPLICATION OF OOP:

The most popular application of oops up to now, has been in the area of user interface

design such as windows. There are hundreds of windowing systems developed using oop

techniques.

Real business systems are often much more complex and contain many more objects

with complicated attributes and methods. Oop is useful in this type of applications because it

can simplify a complex problem. The promising areas for application of oop includes.

1. Real – Time systems.

2. Simulation and modeling

3. Object oriented databases.

4. Hypertext,hypermedia and expertext.

5. Al and expert systems.

6. Neural networks and parallel programming.

7. Dicision support and office automation systems.

OBJECTS

An Object is an instance of a class. Objects are the basic run-time entities in an object-oriented system.
They may represent a person, a place, a bank account, a table of data or any item that the program must
handle. The fundamental idea behind object oriented approach is to combine both data and function
into a single unit and these units are called objects.
The term objects means a combination of data and program that represent some real word

entity. For example: consider an example named Amit; Amit is 25 years old and his salary is 2500.

The Amit may be represented in a computer program as an object. The data part of the object would

be (name: Amit, age: 25, salary: 2500)

The program part of the object may be collection of programs (retrive of data, change age,

change of salary). In general even any user –defined type-such as employee may be used. In the

Amit object the name, age and salary are called attributes of the object.

CLASS:
A group of objects that share common properties for data part and some program part are

collectively called as class.

In C ++ a class is a new data type that contains member variables and member functions that

operate on the variables.

# include<iostream.h>

class person

char name[30];

int age;
public:

void getdata(void);

void display(void);

};

void person :: getdata ( void )

cout<<”enter name”;

cin>>name;

cout<<”enter age”;

cin>>age;

void display()

cout<<”\n name:”<<name;

cout<<”\n age:”<<age;

int main( )

person p;

p.getdata();

p.display();

return(0);

DATA ABSTRACTION :
Abstraction refers to the act of representing essential features without including the back

ground details or explanations. Classes use the concept of abstraction and are defined as size, width

and cost and functions to operate on the attributes.


DATA ENCAPSALATION :
The wrapping up of data and function into a single unit (called class) is known as

encapsulation. The data is not accessible to the outside world and only those functions which are

wrapped in the class can access it. These functions provide the interface between the objects data and

the program.

INHERITENCE :
Inheritance is the process by which objects of one class acquire the properties of another

class. In the concept of inheritance provides the idea of reusablity. This mean that we can add

additional features to an existing class with out modifying it. This is possible by desining a new class

will have the combined features of both the classes.

POLYMORPHISIM:

Polymorphism means the ability to take more than one form. An operation may exhibit different

instance. The behaviour depends upon the type of data used in the operation.

A language feature that allows a function or operator to be given more than one definition. The types

of the arguments with which the function or operator is called determines which definition will be

used.

Overloading may be operator overloading or function overloading.

It is able to express the operation of addition by a single operater say ‘+’. When this is possible you

use the expression x + y to denote the sum of x and y, for many different types of x and y; integers ,

float and complex no. You can even define the + operation for two strings to mean the concatenation

of the strings.

DYNAMIC BINDING :
Binding refers to the linking of a procedure call to the code to the executed in

response to the call. Dynamic binding means the code associated with a given procedure call is not
known untill the time of the call at run-time. It is associated with a polymorphic reference depends

upon the dynamic type of that reference.

C++ Comments:
C++ introduces a new comment symbol //(double slash). Comments start with a

double slash symbol and terminate at the end of line. A comment may start any where in the line and

what ever follows till the end of line is ignored. Note that there is no closing symbol.

The double slash comment is basically a single line comment. Multi line comments can be

written as follows:

// this is an example of

// c++ program

// thank you

The c comment symbols /* ….*/ are still valid and more suitable for multi line comments.

/* this is an example of c++ program */

Output Operator:

The statement cout <<”Hello, world” displayed the string with in quotes on the screen. The identifier

cout can be used to display individual characters, strings and even numbers. It is a predefined object

that corresponds to the standard output stream. Stream just refers to a flow of data and the standard

Output stream normally flows to the screen display. The cout object, whose properties are defined in

iostream.h represents that stream. The insertion operator << also called the ‘put to’ operator directs

the information on its right to the object on its left.

Return Statement:

In C++ main ( ) returns an integer type value to the operating system. Therefore every main (

) in C++ should end with a return (0) statement, otherwise a warning or an error might occur.

Input Operator:

The statement
cin>> number 1;

is an input statement and causes. The program to wait for the user to type in a number. The number

keyed in is placed in the variable number1. The identifier cin is a predefined object in C++ that

corresponds to the standard input stream. Here this stream represents the key board.

The operator >> is known as get from operator. It extracts value from the keyboard

and assigns it to the variable on its right.

Cascading Of I/O Operator:


cout<<”sum=”<<sum<<”\n”;

cout<<”sum=”<<sum<<”\n”<<”average=”<<average<<”\n”;

cin>>number1>>number2;

IDENTIFIERS:
Identifiers refers to the name of variable , functions, array, class etc. created by programmer. Each

language has its own rule for naming the identifiers.

The following rules are common for both C and C++.

1. Only alphabetic chars, digits and under score are permitted.

2. The name can’t start with a digit.

3. Upper case and lower case letters are distinct.

4. A declared keyword can’t be used as a variable name.

5) first characters should be alphabet or underscore

6) name should not be a keyword

7) since C is a case sensitive, the upper case and lower case considered

differently, for example code, Code, CODE etc. are different identifiers.

8) identifiers are generally given in some meaningful name such as value,

net_salary, age, data etc. An identifier name may be long, some implementation

recognizes only first eight characters, most recognize 31 characters. ANSI

standard compiler recognize 31 characters

In ANSI C the maximum length of a variable is 32 chars but in c++ there is no bar.
The type void normally used for:

1) To specify the return type of function when it is not returning any value.

2) To indicate an empty argument list to a function.

Example:

Void function(void);
CONSTANTS
Constant is a any value that cannot be changed during program execution. In C,

any number, single character, or character string is known as a constant. A constant


is an entity that doesn’t change whereas a variable is an entity that may change.

For example, the number 50 represents a constant integer value

 Numeric constant: Numeric constant consists of digits. It required minimum size

of 2 bytes and max 4 bytes. It may be positive or negative but by default sign is

always positive. No comma or space is allowed within the numeric constant and it

must have at least 1 digit. The allowable range for integer constants is -32768 to

32767. Truly speaking the range of an Integer constant depends upon the compiler.

For a 16-bit compiler like Turbo C or Turbo C++ the range is –32768 to 32767.

For a 32-bit compiler the range would be even greater. Mean by a 16-bit or a 32-

bit compiler, what range of an Integer constant has to do with the type of compiler.

It is categorized a integer constant and real constant. An integer constants are

whole number which have no decimal point. Types of integer constants are:

Decimal constant: 0-------9(base 10)

Octal constant: 0-------7(base 8)

Hexa decimal constant: 0----9, A------F(base 16)

In decimal constant first digit should not be zero unlike octal constant first digit

must be zero(as 076, 0127) and in hexadecimal constant first two digit should be

0x/ 0X (such as 0x24, 0x87A). By default type of integer constant is integer but if

the value of integer constant is exceeds range then value represented by integer

type is taken to be unsigned integer or long integer. It can also be explicitly

mention integer and unsigned integer type by suffix l/L and u/U.

 Real constant is also called floating point constant. To construct real constant we

must follow the rule of ,

-real constant must have at least one digit.

-It must have a decimal point.

-It could be either positive or negative.

-Default sign is positive.

-No commas or blanks are allowed within a real constant. Ex.: +325.34

426.0
-32.76

To express small/large real constant exponent(scientific) form is used where

number is written in mantissa and exponent form separated by e/E. Exponent can

be positive or negative integer but mantissa can be real/integer type, for example

3.6*105=3.6e+5. By default type of floating point constant is double, it can also be

explicitly defined it by suffix of f/F.

 Character constant

22 *Under revision

Character constant represented as a single character enclosed within a single

quote. These can be single digit, single special symbol or white spaces such as

‘9’,’c’,’$’, ‘ ’ etc. Every character constant has a unique integer like value in

machine’s character code as if machine using ASCII (American standard code for

information interchange). Some numeric value associated with each upper and

lower case alphabets and decimal integers are as:

A------------ Z ASCII value (65-90)

a-------------z ASCII value (97-122)

0-------------9 ASCII value (48-59)

; ASCII value (59)

 String constant

Set of characters are called string and when sequence of characters are

enclosed within a double quote (it may be combination of all kind of symbols) is a

string constant. String constant has zero, one or more than one character and at the

end of the string null character(\0) is automatically placed by compiler. Some

examples are “,sarathina” , “908”, “3”,” ”, “A” etc. In C although same characters

are enclosed within single and double quotes it represents different meaning such

as “A” and ‘A’ are different because first one is string attached with null character

at the end but second one is character constant with its corresponding ASCII value

is 65.

 Symbolic constant
Symbolic constant is a name that substitute for a sequence of characters and,

characters may be numeric, character or string constant. These constant are

generally defined at the beginning of the program as

#define name value , here name generally written in

upper case for example

23 *Under revision

#define MAX 10

#define CH ‘b’

#define NAME “sony”

OPERATORS

An operator is a symbol that tells the compiler to perform specific mathematical or logical

manipulations. C language is rich in built-in operators and provides the following types of

operators:

• Arithmetic Operators

• Relational Operators

• Logical Operators

• Bitwise Operators

• Assignment Operators

• Increment and decrement operators

• Conditional operators

• Misc Operators

Arithmetic operator:
These are used to perform mathematical calculations like addition, subtraction, multiplication,
division and modulus.
Relational Operators:

These operators are used to compare the value of two variables.


Logical Operators:

These operators are used to perform logical operations on the given two variables.

Bitwise Operators

Bitwise operator works on bits and performs bit-by-bit operation. Bitwise operators are used in bit

level programming. These operators can operate upon int and char but not on float and double.

Showbits( ) function can be used to display the binary representation of any integer or character

value.

Bit wise operators in C language are; & (bitwise AND), | (bitwise OR), ~ (bitwise OR), ^ (XOR),

<< (left shift) and >> (right shift)


Assignment Operators:

In C programs, values for the variables are assigned using assignment operators.
int a = 5, b = 3;

int sum = a + b; // sum is 8

int diff = a - b; // diff is 2

int prod = a * b; // prod is 15

int quot = a / b; // quot is 1

int rem = a % b; // rem is 2

bool x = true, y = false;

bool result = x && y; // result is false

bool either = x || y; // either is true

bool notX = !x; // notX is false

INCREMENT AND DECREMENT OPERATOR

In C, ++ and – are called increment and decrement operators respectively. Both of these operators

are unary operators, i.e, used on single operand. ++ adds 1 to operand and – subtracts 1 to

operand respectively. For example:

Let a=5 and b=10

a++; //a becomes 6

a--; //a becomes 5

++a; //a becomes 6

--a; //a becomes 5

When i++ is used as prefix(like: ++var), ++var will increment the value of var and then return it

but, if ++ is used as postfix(like: var++), operator will return the value of operand first and then

only increment it. This can be demonstrated by an example:

#include <stdio.h>

int main()
{

int c=2,d=2;

printf(“%d\n”,c++); //this statement displays 2 then, only c incremented by 1 to 3.

Printf(“%d”,++c); //this statement increments 1 to c then, only c is displayed.

Return 0;

Output

- Linker Errors:

- Linker errors occur during the linking phase when combining object files into an executable program.
These errors include unresolved symbols or missing libraries.

- Runtime Errors:

- Runtime errors are found during program execution. They can be further classified:

- Logic Errors: Errors found by the programmer while investigating erroneous results.

- Run-time Errors: Errors detected during program execution, such as division by zero or accessing
out-of-bounds memory.

Remember that understanding and fixing these errors is essential for successful programming!

You might also like