Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
65 views

Week2 Programming Assignment

A programming language is a language used to control machines like computers, with types including low-level languages that are close to machine instructions and high-level languages that are easier for programmers to use but require compilers; object-oriented programming models real-world entities as objects that can represent attributes and behaviors through concepts like abstraction, encapsulation, inheritance, and polymorphism.

Uploaded by

Pankaj Khadka
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Week2 Programming Assignment

A programming language is a language used to control machines like computers, with types including low-level languages that are close to machine instructions and high-level languages that are easier for programmers to use but require compilers; object-oriented programming models real-world entities as objects that can represent attributes and behaviors through concepts like abstraction, encapsulation, inheritance, and polymorphism.

Uploaded by

Pankaj Khadka
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

What is programming and what are the types of programming


languages?
A programming language is an artificial language that can be used to
control the behavior of a machine, particularly a computer.
The types of programming languages are:
1) Low-Level Programming Language: provides little or no abstraction
of programming concepts, and is very close to writing actual
machine instructions. Eg: assembly language and machine code.
2) High-Level Programming Language:  Enables development of a
program in a much simple programming context and is generally
independent of the computer’s hardware architecture.  Eg: C/C++,
JAVA.

Q2) Differentiate between high-level programming languages and low-level


programming languages.

High-level language Low-level language

It is a programmer-friendly language. It is machine-friendly language.

It is easy to understand. It is tough to understand,

Debugging is easy. Debugging is complex


comparatively.
It is simple to maintain. It is complex to maintain
comparatively.
It is portable. It is nonportable.

It can run on any platform. It is machine dependent.

It needs a compiler or interpreter for It needs an assembler for


translation. translation.
It is used widely for programming. It is not commonly used nowadays in
programming.
3.What is OOP? Discuss its concepts without coding examples.
OOP stands for Object-Oriented Programming, which is a
programming paradigm that is based on the concept of objects. OOP
focuses on modeling real-world entities as objects and providing a
way to represent these objects in code.

The following are the key concepts of OOP:

Abstraction: Abstraction is the process of identifying and representing


the essential features of an object while ignoring the non-essential
details. In OOP, we use abstraction to create classes that represent
real-world entities by identifying their key attributes and behaviors.
For example, a Car class may have attributes such as color, model,
and year, and behaviors such as starting, accelerating, and braking.

Encapsulation: Encapsulation is the process of hiding the internal


details of an object from the outside world and providing a well-
defined interface for interacting with the object. In OOP, we use
encapsulation to protect the internal state of an object from
unauthorized access and modification. This helps to ensure that the
object remains in a valid state and prevents errors from occurring. For
example, a Car class may have a valid state and prevents errors from
occurring. For example, a Car class may have a private attribute
called "mileage" that can only be accessed and modified through
public methods such as "getMileage()" and "setMileage()".

Inheritance: Inheritance is the process of creating new classes that


inherit the attributes and behaviors of existing classes. In OOP, we
use inheritance to create a hierarchy of classes that share common
attributes and behaviors. This helps to reduce code duplication and
promote code reuse. For example, a Sedan class may inherit from a
Car class and add additional attributes such as "numDoors" and
"trunkSize".

Polymorphism: Polymorphism is the ability of objects to take on


different forms and behave differently depending on the context in
which they are used. In OOP, we use polymorphism to create classes
that can be used interchangeably with other classes that share a
common interface. This helps to promote code flexibility and
extensibility. For example, a Car class may have a "drive()" method
that can be overridden by a subclass such as a SportsCar to provide
different behavior.

4. Write a program to add, sub, divide and multiply any two numbers and display
the result
Here is the coding of a program to add, sub, divide and multiply any two
numbers and display the result

Here is the display:

5. Write a program to find the perimeter of a circle.


Code:
Display:

6 Write a program to find the area of a rectangle.

Display:

7. Write a program to display the name, age, address, and email


address of your friend.
Code:
Display:

8. Difference between compiler, interpreter and assembler.


Compilers, interpreters, and assemblers are all software tools used in the
process of converting human-readable source code into machine-
executable code. Here are the key differences between them:

Compiler:
A compiler is a software tool that translates source code into machine code
in a separate step.
The compiler takes the entire source code as input, analyzes it, and
generates an object file or an executable file as output.
The generated object file or executable file can be executed multiple times
without the need for recompilation.
Compilers are typically used for languages such as C, C++, Java, and
Python.
Interpreter:
An interpreter is a software tool that translates source code into machine
code line by line as it is being executed. The interpreter reads a single line
of source code, translates it into machine code, executes it, and then
moves on to the next line of source code.
Interpreters do not generate an executable file, and the code needs to be
interpreted each time it is executed.
Interpreters are typically used for languages such as Python, Ruby, and
JavaScript.
Assembler:
An assembler is a software tool that translates assembly language into
machine code in a separate step.
Assembly language is a low-level programming language that is closer to
machine code than high-level programming languages.
The assembler takes the assembly code as input, analyzes it, and
generates an object file as output.
The generated object file needs to be linked with other object files to
produce an executable file.
Assemblers are typically used for programming languages such as
Assembly language.

9.Describe the class and object with code examples:


Here is a coding example of having a class Animal and having objects and
then you can create objects of the ClassAnimals that represent a different
breed, color, and age.

You might also like