Skip to content

Commit 94f2f03

Browse files
Cpp Programming
1 parent f8ab086 commit 94f2f03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1404
-0
lines changed

FloydTriangle.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int rows;
7+
cout<<"Enter the number of Rows="<<endl;
8+
cin>>rows;
9+
cout<<"Floyd Triangle of"<<rows<<endl;
10+
11+
int count=1;
12+
for(int i =0;i<=rows;i++)
13+
{
14+
for(int j=0;j<=i;j++)
15+
{
16+
cout<<(count++)<<" ";
17+
}
18+
cout << endl;
19+
}
20+
return 0;
21+
}

FriendFunction.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class A{
5+
int x;
6+
public:
7+
A(int y)
8+
{
9+
x=y;
10+
}
11+
12+
friend void print(A &obj);
13+
14+
15+
16+
17+
};
18+
void print(A &obj)
19+
{
20+
cout<<obj.x<<endl;
21+
22+
}
23+
int main()
24+
{
25+
A obj(5);
26+
print(obj);
27+
28+
return 0;
29+
}
30+

FriendFunction3.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include<iostream>
2+
using namespace std;
3+
class Amir;
4+
class Ahmed
5+
{
6+
private:
7+
int value =5;
8+
void homework()
9+
{
10+
cout<<"Ahmed completed the homework"<<endl;
11+
}
12+
friend void adnan(Ahmed,Amir);
13+
};
14+
class Amir
15+
16+
{
17+
private:
18+
int value=5;
19+
void study()
20+
{
21+
cout<<"Amir is doing study "<<endl;
22+
}
23+
friend void adnan(Ahmed,Amir);
24+
};
25+
void adnan(Ahmed a1, Amir a2)
26+
{
27+
cout<<"sum="<<a1.value+a2.value<<endl;
28+
29+
30+
31+
32+
}
33+
34+
int main()
35+
{
36+
Ahmed obj1;
37+
Amir obj2;
38+
39+
adnan(obj1,obj2);
40+
41+
42+
43+
44+
45+
return 0;
46+
}

FruitInheritance.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class Fruit
5+
{
6+
public:
7+
static int fruitCounter;
8+
Fruit()
9+
{
10+
fruitCounter++;
11+
12+
}
13+
~Fruit()
14+
{
15+
fruitCounter--;
16+
}
17+
18+
19+
20+
};
21+
class Apples:public Fruit{
22+
public:
23+
static int appleCounter;
24+
Apples()
25+
{
26+
appleCounter++;
27+
28+
}
29+
~Apples()
30+
{
31+
appleCounter--;
32+
}
33+
34+
35+
};
36+
class Mangoes:public Fruit{
37+
public:
38+
static int mangoCounter;
39+
Mangoes()
40+
{
41+
mangoCounter++;
42+
}
43+
~Mangoes()
44+
{
45+
mangoCounter--;
46+
}
47+
48+
};
49+
int Fruit::fruitCounter=0;
50+
int Apples::appleCounter=0;
51+
int Mangoes::mangoCounter=0;
52+
53+
int main()
54+
{
55+
Apples first,second;
56+
Mangoes fi,se;
57+
cout<<"Total Number of Fruits="<<Fruit::fruitCounter<<endl;
58+
cout<<"total number of apples="<<Apples::appleCounter<<endl;
59+
cout<<"Total number of Mangoes="<<Mangoes::mangoCounter<<endl;
60+
61+
62+
63+
}

FunctionOverload.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class Addition{
5+
public:
6+
void add(int x,int y)
7+
{
8+
int sum =x+y;
9+
cout<<sum<<endl;
10+
11+
}
12+
13+
void add(int x, int y , int z)
14+
{
15+
int sum =x+y+z;
16+
cout<<sum;
17+
}
18+
19+
void add(float x ,float y)
20+
{
21+
float sum = x+y;
22+
cout<<sum;
23+
24+
}
25+
};
26+
27+
int main()
28+
{
29+
Addition a;
30+
a.add(5,6);
31+
a.add(6,7);
32+
a.add(float (5.5),float (6.5));
33+
34+
return 0;
35+
}

HierarchicalInheritance.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class A
5+
{
6+
public:
7+
A()
8+
{
9+
cout<<"A"<<endl;
10+
11+
12+
}
13+
};
14+
class B : public A{
15+
public:
16+
B()
17+
{
18+
cout<<"BB"<<endl;
19+
20+
}
21+
};
22+
23+
class C : public A
24+
{
25+
public:
26+
C()
27+
{
28+
cout<<"CCC"<<endl;
29+
30+
}
31+
};
32+
33+
int main()
34+
{
35+
B j;
36+
C obj;
37+
return 0;
38+
39+
}

HollowRectanglePyramid.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int rows,cols;
7+
cout<<"Enter the number Rows="<<endl;
8+
cin>>rows;
9+
10+
cout<<"Enter the number Columns = "<<endl;
11+
cin>>cols;
12+
13+
cout << "The dimension of Rectangle is "<<rows <<"*"<<cols<<endl;
14+
15+
for(int i=0;i<rows;i++)
16+
{
17+
for(int j=0;j<cols;j++)
18+
{
19+
if (i == 0 || i==rows-1 || j == 0 || j==cols-1)
20+
{
21+
cout<<"*";
22+
}
23+
else {
24+
cout<< " ";
25+
}
26+
27+
}
28+
29+
cout<<endl;
30+
31+
32+
}
33+
return 0;
34+
}

HybridInheritance.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
5+
class Base
6+
{
7+
public:
8+
Base ()
9+
{
10+
cout<<"HEllo Base "<<endl;
11+
}
12+
};
13+
14+
class DerivedOne : public Base
15+
{
16+
public:
17+
DerivedOne()
18+
{
19+
cout<<"Derived class One "<<endl;
20+
}
21+
22+
} ;
23+
class DerivedTwo : public Base{
24+
public:
25+
DerivedTwo()
26+
{
27+
cout<<"Derived Class Two"<<endl;
28+
}
29+
30+
};
31+
class end : public DerivedTwo,public DerivedOne
32+
{
33+
public:
34+
end()
35+
{
36+
cout<<"End Class ";
37+
}
38+
};
39+
int main()
40+
{
41+
DerivedOne one;
42+
return 0;
43+
}

Inheritance.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class Animal {
5+
public:
6+
void sound()
7+
{
8+
cout<<"Some weird Sound !!"<< endl;
9+
}
10+
};
11+
class Dog : Animal{
12+
public :
13+
void sound()
14+
{
15+
cout<<"Woof Wooof !!"<< endl;
16+
17+
}
18+
};
19+
class cat : Animal
20+
{
21+
public :
22+
void sound()
23+
{
24+
cout<<"Meow Meow !!"<<endl;
25+
}
26+
27+
28+
};
29+
30+
31+
int main()
32+
{
33+
Animal an;
34+
Dog doo;
35+
cat Ca;
36+
37+
doo.sound();
38+
Ca.sound();
39+
40+
return 0;
41+
42+
43+
44+
}

0 commit comments

Comments
 (0)