Skip to content

Commit 2e66c25

Browse files
Formatted the code
Formatted the code for better readability
1 parent b797df1 commit 2e66c25

File tree

77 files changed

+2871
-1949
lines changed

Some content is hidden

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

77 files changed

+2871
-1949
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
using namespace std;
3+
int tarea(int b, int h)
4+
{
5+
return 0.5 * b *h;
6+
}
7+
int rarea(int l, int b)
8+
{
9+
return l *b;
10+
}
11+
int main()
12+
{
13+
int ba, h;
14+
cout << "Enter Base of triangle:\n";
15+
cin >> ba;
16+
cout << "Enter Height of triangle:\n";
17+
cin >> h;
18+
cout << "Area of triangle is:" << tarea(ba, h) << endl;
19+
int a, b;
20+
cout << "Enter Length of rectangle:\n";
21+
cin >> a;
22+
cout << "Enter Breadth of rectangle:\n";
23+
cin >> b;
24+
cout << "Area of rectangle is:" << rarea(a, b) << endl;
25+
return 0;
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
int u, p;
6+
cout << "Enter numbers of units:\n";
7+
cin >> u;
8+
if ((u > 0) && (u <= 100))
9+
{
10+
p = u * 4;
11+
}
12+
else if ((u > 100) && (u <= 300))
13+
{
14+
p = u * 5;
15+
}
16+
else
17+
{
18+
p = u * 7;
19+
}
20+
cout << "Price is :" << p << "";
21+
return 0;
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
int a, b;
6+
cout << "Enter two numbers:\n";
7+
cin >> a >> b;
8+
cout << "Entered numbers are:" << a << "\n" << "" << b;
9+
return 0;
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <iostream>
2+
int main()
3+
{
4+
int a, b;
5+
std::cout << "Enter two numbers:\n";
6+
std::cin >> a >> b;
7+
std::cout << "Entered numbers are:" << a << " \n" << b;
8+
return 0;
9+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <iostream>
2+
using namespace std;
3+
void large(int a, int b, int c)
4+
{
5+
if (a > b)
6+
{
7+
if (a > c)
8+
{
9+
cout << "The largest number is:" << a;
10+
}
11+
else
12+
{
13+
cout << "The largest number is:" << c;
14+
}
15+
}
16+
else if (b > c)
17+
{
18+
cout << "The largest number is:" << b;
19+
}
20+
else
21+
{
22+
cout << "The largest number is:" << c;
23+
}
24+
}
25+
int main()
26+
{
27+
int n1, n2, n3;
28+
cout << "Enter number 1:" << endl;
29+
cin >> n1;
30+
cout << "Enter number 2:" << endl;
31+
cin >> n2;
32+
cout << "Enter number 3:" << endl;
33+
cin >> n3;
34+
large(n1, n2, n3);
35+
return 0;
36+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
//WAP in C++ to find print prime numbers upto 20
6+
int i;
7+
cout << "Prime numbers are:\n2" << endl;
8+
for (int i = 2; i <= 20; i++)
9+
{
10+
for (int j = 2; j < i; j++)
11+
{
12+
if (i % j == 0)
13+
{
14+
break;
15+
}
16+
else
17+
{
18+
if (i == j + 1)
19+
cout << i << endl;
20+
}
21+
}
22+
}
23+
24+
return 0;
25+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
int a, b, sum, mul;
6+
cout << "Enter two numbers:\n";
7+
cin >> a >> b;
8+
sum = a + b;
9+
mul = a *b;
10+
cout << "Sum of number " << a << " and " << b << " is " << sum << endl;
11+
cout << "Multiplication of number " << a << " and " << b << " is " << mul << endl;
12+
return 0;
13+
}

Abstract class/Abstract-class.cpp

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
1-
#include<iostream>
1+
#include <iostream>
22
using namespace std;
3-
class polygon{
3+
class polygon
4+
{
45
public:
5-
virtual void sides()=0;
6-
void print(){
7-
cout<<"Abstract base class\n";
8-
} };
9-
class triangle:public polygon{
6+
virtual void sides() = 0;
7+
void print()
8+
{
9+
cout << "Abstract base class\n";
10+
}
11+
};
12+
class triangle: public polygon
13+
{
1014
public:
11-
void sides(){
12-
cout<<"Triangle has 3 sides.\n";
13-
cout<<"Implementing in derived class.\n";} };
14-
class square:public polygon{
15+
void sides()
16+
{
17+
cout << "Triangle has 3 sides.\n";
18+
cout << "Implementing in derived class.\n";
19+
}
20+
};
21+
class square: public polygon
22+
{
1523
public:
16-
void sides(){
17-
cout<<"Square has 4 sides.\n";
18-
cout<<"Implementing in derived class.\n";} };
19-
int main(){
20-
triangle t;
21-
t.sides();
22-
t.print();
23-
square s;
24-
s.sides();
25-
return 0;
26-
}
24+
void sides()
25+
{
26+
cout << "Square has 4 sides.\n";
27+
cout << "Implementing in derived class.\n";
28+
}
29+
};
30+
int main()
31+
{
32+
triangle t;
33+
t.sides();
34+
t.print();
35+
square s;
36+
s.sides();
37+
return 0;
38+
}
2739
/*polygon p;
2840
Abstract-class.cpp:20:9: error: cannot declare variable 'p' to be of abstract type 'polygon'
2941
polygon p;
Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
#include<iostream>
2-
using namespace std;
3-
int main(){
4-
//WAP in C++ to find largest number of array
5-
int n,a[15],l=0;
6-
cout<<"Enter the number of element:";
7-
cin>>n;
8-
for(int i=0;i<n;i++){
9-
cout<<"Enter element "<<i+1<<":"; cin>>a[i]; }
10-
for(int i=0;i<n;i++){
11-
if(a[0]<a[i]){
12-
a[0]=a[i];
13-
} }
14-
l=a[0];
15-
cout<<"Largest number of the array is:"<<l<<endl;
16-
return 0; }
1+
#include <iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
//WAP in C++ to find largest number of array
6+
int n, a[15], l = 0;
7+
cout << "Enter the number of element:";
8+
cin >> n;
9+
for (int i = 0; i < n; i++)
10+
{
11+
cout << "Enter element " << i + 1 << ":";
12+
cin >> a[i];
13+
}
14+
for (int i = 0; i < n; i++)
15+
{
16+
if (a[0] < a[i])
17+
{
18+
a[0] = a[i];
19+
}
20+
}
21+
l = a[0];
22+
cout << "Largest number of the array is:" << l << endl;
23+
return 0;
24+
}
Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,52 @@
1-
#include<iostream>
2-
using namespace std;
3-
int main(){
4-
//WAP in C++ to multiply matrix
5-
int a[10][10],b[10][10],mul[10][10],r,c,i,j,k,p=1,q=1;
6-
cout<<"Enter the number of row:"<<endl;
7-
cin>>r;
8-
cout<<"Enter the number of column:"<<endl;
9-
cin>>c;
10-
cout<<"Enter the first matrix element"<<endl;
11-
for(i=0;i<r;i++){
12-
for(j=0;j<c;j++){
13-
cout<<"Element"<<p<<":"<<endl;
14-
cin>>a[i][j]; p++; } }
15-
cout<<"Enter the second matrix element"<<endl;
16-
for(i=0;i<r;i++) {
17-
for(j=0;j<c;j++){
18-
cout<<"Element"<<q<<":"<<endl;
19-
cin>>b[i][j]; q++; }
20-
}
21-
cout<<"Multiplication of the matrix:"<<endl;
22-
for(i=0;i<r;i++){
23-
for(j=0;j<c;j++) {
24-
mul[i][j]=0;
25-
for(k=0;k<c;k++) {
26-
mul[i][j]+=a[i][k]*b[k][j];
27-
} } }
28-
for(i=0;i<r;i++){
29-
for(j=0;j<c;j++){
30-
cout<<mul[i][j]<<"\t"; }
31-
cout<<"\n"; }
32-
return 0; }
1+
#include <iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
//WAP in C++ to multiply matrix
6+
int a[10][10], b[10][10], mul[10][10], r, c, i, j, k, p = 1, q = 1;
7+
cout << "Enter the number of row:" << endl;
8+
cin >> r;
9+
cout << "Enter the number of column:" << endl;
10+
cin >> c;
11+
cout << "Enter the first matrix element" << endl;
12+
for (i = 0; i < r; i++)
13+
{
14+
for (j = 0; j < c; j++)
15+
{
16+
cout << "Element" << p << ":" << endl;
17+
cin >> a[i][j];
18+
p++;
19+
}
20+
}
21+
cout << "Enter the second matrix element" << endl;
22+
for (i = 0; i < r; i++)
23+
{
24+
for (j = 0; j < c; j++)
25+
{
26+
cout << "Element" << q << ":" << endl;
27+
cin >> b[i][j];
28+
q++;
29+
}
30+
}
31+
cout << "Multiplication of the matrix:" << endl;
32+
for (i = 0; i < r; i++)
33+
{
34+
for (j = 0; j < c; j++)
35+
{
36+
mul[i][j] = 0;
37+
for (k = 0; k < c; k++)
38+
{
39+
mul[i][j] += a[i][k] * b[k][j];
40+
}
41+
}
42+
}
43+
for (i = 0; i < r; i++)
44+
{
45+
for (j = 0; j < c; j++)
46+
{
47+
cout << mul[i][j] << "\t";
48+
}
49+
cout << "\n";
50+
}
51+
return 0;
52+
}

0 commit comments

Comments
 (0)