Unit 1
Unit 1
Unit 1
Programming
UNIT - 1
The data of an object can be accessed only by the function associated with that object. However,
function of one object can access the function of other objects.
Brunda G, Dept. of CSE, RIT 10
Some of the features of object oriented programming are:
a) Emphasis is on data rather than procedure.
b) Programs are divided into what are known as objects.
c) Data structures are designed such that they characterize
the objects.
d) Functions that operate on the data of an object are ties
together in the data
structure.
e) Data is hidden and cannot be accessed by external function.
f) Objects may communicate with each other through function.
g) New data and functions can be easily added whenever
necessary.
h) Follows bottom up approach in program design.
Brunda G, Dept. of CSE, RIT 11
Brunda G, Dept. of CSE, RIT 12
Brunda G, Dept. of CSE, RIT 13
1. Write a C++ program to find the area and circumference of a
circle
#include <iostream>
using namespace std;
int main() {
int n;
long factorial = 1.0;
cout << "Enter a positive integer: ";
cin >> n;
if (n < 0)
cout << "Error! Factorial of a negative number doesn't
exist.";
else {
for(int i = 1; i <= n; ++i) {
factorial *= i;
}
cout << "Factorial of " << n << " = " << factorial;
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int n;
int sum = 0;
int main() {
int num, reversedNum = 0, originalNum, remainder;
originalNum = num;
while (num != 0) {
remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num /= 10;
}
if (originalNum == reversedNum) {
cout << originalNum << " is a palindrome." << endl;
} else {
cout << originalNum << " is not a palindrome." << endl;
}
return 0;
Brunda G, Dept. of CSE, RIT 37
}