-
Notifications
You must be signed in to change notification settings - Fork 0
/
linerSearch
68 lines (65 loc) · 1.23 KB
/
linerSearch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
using namespace std;
int search(int A[], n, int key)
{
for ( int i = 0; i < n; i++) {
if ( A[i] == key )
return i;
}
return -1;
}
classs Shape
{
protected:
float length;
float breadth;
public:
Shape(float x, float y) {
length = x;
breadth = y;
}
~Shape();
virtual float area() = 0;
virtual float perimeter() = 0;
virtual float diagonal() = 0;
}
class Rectangle : public Shape
{
public:
Rectangle(float x, float y) : Shape(x, y)
{
}
~Rectangle();
float area() { return length * breadth;}
float perimeter(){ return 2 * (length + breadth); }
float diagonal() { return sqrt(length * length + breadth * breadth);}
};
class Triangle : public Shape
{
public:
Triangle(float x, float y) : Shape(x, y)
{}
~Triangle();
float area() { return length * breadth / 2; }
};
int main()
{
int A[] = {2, 4, 6, 8, 10};
int x;
cout <<"Enter a key ";
cin >> x ;
int index = search(A, 5, x);
if ( index > 0 ) {
cout << "Element is found at the index " << index << endl;
}
Rectange r1, r2;
r1.length = 10;
r1.breadth = 5;
cout << r1.area() << endl;
Rectangle *p;
p = &r2;
p->length = 5;
p->breadth = 10;
cout << r2.perimeter << endl;
return 0;
}