Skip to content

Commit e6dc0dd

Browse files
Add files via upload
1 parent c501da6 commit e6dc0dd

File tree

54 files changed

+717
-0
lines changed

Some content is hidden

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

54 files changed

+717
-0
lines changed
45.1 KB
Binary file not shown.

Abstract class/Abstract-class.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include<iostream>
2+
using namespace std;
3+
class polygon{
4+
public:
5+
virtual void sides()=0;
6+
void print(){
7+
cout<<"Abstract base class\n";
8+
} };
9+
class triangle:public polygon{
10+
public:
11+
void sides(){
12+
cout<<"Triangle has 3 sides.\n";
13+
cout<<"Implementing in derived class.\n";} };
14+
class square:public polygon{
15+
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+
}
27+
/*polygon p;
28+
Abstract-class.cpp:20:9: error: cannot declare variable 'p' to be of abstract type 'polygon'
29+
polygon p;
30+
^
31+
Abstract-class.cpp:3:7: note: because the following virtual functions are pure within 'polygon':
32+
class polygon{
33+
^~~~~~~
34+
Abstract-class.cpp:5:14: note: virtual void polygon::sides()
35+
virtual void sides()=0;
36+
^~~~~*/
37+
/*Triangle has 3 sides.
38+
Implementing in derived class.
39+
Square has 4 sides.
40+
Implementing in derived class.*/

Array/Largest-element-array-code.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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; }
44.2 KB
Binary file not shown.

Array/Matrix-multiplication-code.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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; }
45.6 KB
Binary file not shown.

Class/Array-of-object-code-output.exe

49.9 KB
Binary file not shown.

Class/Array-of-object-code.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include<iostream>
2+
using namespace std;
3+
//program to implement array of object
4+
class emp{
5+
private:
6+
int id;
7+
public:
8+
string name;
9+
float salary;
10+
void getdata(int i,string n,float s){
11+
id=i;
12+
name=n;
13+
salary=s;}
14+
void putdata(){
15+
cout<<"Employee details are:"<<endl;
16+
cout<<"Id is:"<<id<<""<<endl;
17+
cout<<"Name is:"<<name<<""<<endl;
18+
cout<<"Salary is:"<<salary<<""<<endl;}};
19+
int main(){
20+
emp e1[23];
21+
int n;
22+
cout<<"Enter number of employees data to be stored:";
23+
cin>>n;
24+
int id,i;
25+
char name[100]; float sa;
26+
for(i=0;i<n;i++){
27+
cout<<"Enter id,name and salary:\n";
28+
cin>>id>>name>>sa;
29+
e1[i].getdata(id,name,sa);
30+
e1[i].putdata(); }
31+
return 0;
32+
}

Class/Book-class-code.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include<iostream>
2+
using namespace std;
3+
class book{
4+
private:
5+
int id;
6+
public:
7+
string name;
8+
string writer;
9+
string subject;
10+
string course;
11+
void insert(int i,string n,string w,string s,string c){
12+
id=i;
13+
name=n;
14+
writer=w;
15+
subject=s;
16+
course=c;
17+
}
18+
void display(){
19+
cout<<"Book details are:"<<endl;
20+
cout<<"Id is:"<<id<<""<<endl;
21+
cout<<"Name is:"<<name<<""<<endl;
22+
cout<<"writer is:"<<writer<<""<<endl;
23+
24+
cout<<"subject is:"<<subject<<""<<endl;
25+
cout<<"course is:"<<course<<""<<endl;
26+
27+
}
28+
};
29+
int main(){
30+
book b1;
31+
book b2;
32+
int id;
33+
char name[100],writer[100],subject[100],course[100];
34+
cout<<"Enter id,name,writer,subject,course:\n";
35+
cin>>id>>name>>writer>>subject>>course;
36+
b1.insert(id,name,writer,subject,course);
37+
b1.display();
38+
cout<<"Enter id,name,writer,subject,course:\n";
39+
cin>>id>>name>>writer>>subject>>course;
40+
b2.insert(id,name,writer,subject,course);
41+
b2.display();
42+
return 0;
43+
}

Class/Book-class-output.exe

50.8 KB
Binary file not shown.

Class/Container-class-code-output.exe

43.8 KB
Binary file not shown.

Class/Container-class-code.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include<iostream>
2+
using namespace std;
3+
class first{
4+
public:
5+
void show(){cout<<"First Class!!"<<endl;}};
6+
class contain{
7+
first f1;
8+
public:
9+
contain(){
10+
f1.show();}};
11+
int main(){
12+
contain c1;
13+
return 0;}

Class/Demo-class1-output.exe

44 KB
Binary file not shown.

Class/Demo-class1.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<iostream>
2+
using namespace std;
3+
class demo
4+
{
5+
private:
6+
int a,b;
7+
public:
8+
void input()
9+
{
10+
cout<<"Enter value: ";
11+
cin>>a>>b;
12+
}
13+
void show()
14+
{
15+
cout<<a<<"\t"<<b;
16+
}
17+
};
18+
int main()
19+
{
20+
demo ob;
21+
ob.input();
22+
ob.show();
23+
return 0;
24+
}

Class/Demo-class2-output.exe

47.7 KB
Binary file not shown.

Class/Demo-class2.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include<iostream>
2+
using namespace std;
3+
class student{
4+
public:
5+
int id;
6+
string name;
7+
void insert(int i,string n){
8+
id=i;
9+
name=n;
10+
}
11+
void display(){
12+
cout<<"Id is:"<<id<<""<<endl;
13+
cout<<"Name is:"<<name<<""<<endl;
14+
15+
}
16+
};
17+
int main(){
18+
student s1;
19+
student s2;
20+
s1.insert(201,"mansi");
21+
s2.insert(205,"shruti");
22+
s1.display();
23+
s2.display();
24+
return 0;
25+
}

Class/Employee-class-code-output.exe

49.9 KB
Binary file not shown.

Class/Employee-class-code.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include<iostream>
2+
using namespace std;
3+
class emp{
4+
private:
5+
int id;
6+
public:
7+
string name;
8+
float salary;
9+
void insert(int i,string n,float s){
10+
id=i;
11+
name=n;
12+
salary=s;}
13+
void display(){
14+
cout<<"Employee details are:"<<endl;
15+
cout<<"Id is:"<<id<<""<<endl;
16+
cout<<"Name is:"<<name<<""<<endl;
17+
cout<<"Salary is:"<<salary<<""<<endl;}};
18+
int main(){
19+
emp e1;
20+
emp e2;
21+
int id;
22+
char name[100]; float sa;
23+
cout<<"Enter id,name and salary:\n";
24+
cin>>id>>name>>sa;
25+
e1.insert(id,name,sa);
26+
e1.display();
27+
cout<<"Enter id,name and salary:\n";
28+
cin>>id>>name>>sa;
29+
e2.insert(id,name,sa);
30+
e2.display();
31+
return 0;
32+
}

Class/Private-data-member-output.exe

43.9 KB
Binary file not shown.

Class/Private-data-member.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include<iostream>
2+
using namespace std;
3+
class Circle{
4+
private:
5+
double radius;
6+
public:
7+
double compute_area(double r){radius=r;
8+
double area= 3.14*radius*radius;
9+
cout << "Radius is: " << radius << endl;
10+
cout << "Area is: " << area;}};
11+
int main(){
12+
Circle obj;
13+
// trying to access private data member
14+
//obj.radius = 1.5;
15+
obj.compute_area(1.5);
16+
return 0;
17+
}
44.1 KB
Binary file not shown.

Class/Protected-data-member.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include<iostream>
2+
using namespace std;
3+
class Circle{
4+
protected:
5+
double radius=90;
6+
public:
7+
double compute_area(double r){radius=r;
8+
double area= 3.14*radius*radius;
9+
cout << "Radius is: " << radius << endl;
10+
cout << "Area is: " << area<<endl;}};
11+
class in : public Circle{
12+
public:
13+
void p(){cout << "Radius is: "<<radius<< endl;
14+
}};
15+
int main(){
16+
Circle obj;
17+
// trying to access private data member
18+
//obj.radius = 1.5;
19+
obj.compute_area(1.5);
20+
in i;
21+
i.p();
22+
return 0;
23+
}

Class/Student-class-code-output.exe

50 KB
Binary file not shown.

Class/Student-class-code.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include<iostream>
2+
using namespace std;
3+
class student{
4+
private:
5+
int id;
6+
public:
7+
string name;
8+
float perc;
9+
void insert(int i,string n,float p){
10+
id=i;
11+
name=n;
12+
perc=p;}
13+
void display(){
14+
cout<<"Student details are:"<<endl;
15+
cout<<"Student Id is:"<<id<<""<<endl;
16+
cout<<"Name is:"<<name<<""<<endl;
17+
cout<<"Percentage is:"<<perc<<""<<endl;}};
18+
int main(){
19+
student s1;
20+
student s2;
21+
int id;
22+
char name[100]; float pe;
23+
cout<<"Enter Student id,name and Percentage:\n";
24+
cin>>id>>name>>pe;
25+
s1.insert(id,name,pe);
26+
s1.display();
27+
cout<<"Enter Student id,name and Percentage:\n";
28+
cin>>id>>name>>pe;
29+
s2.insert(id,name,pe);
30+
s2.display();
31+
return 0;
32+
}

Constructor/Copy-constructor-code.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include<iostream>
2+
#include<stdio.h>
3+
using namespace std;
4+
class student{
5+
//wap for copy constructor
6+
public:
7+
int roll;
8+
string name;
9+
private:
10+
int id;
11+
public:
12+
student(int n1,string n2,int n3){
13+
roll=n1;
14+
name=n2;
15+
id=n3;
16+
id=n3; cout<<"Parameterized Constructor is getting called:"<<endl; cout<<"Roll no is:"<<roll<<endl; cout<<"Name is:"<<name<<endl;
17+
cout<<"Id is:"<<id<<endl;}
18+
student(const student&s1){
19+
roll=s1.roll;
20+
id=s1.id;
21+
name=s1.name;
22+
cout<<"Copy Constructor is getting called:"<<endl; cout<<"Roll no is:"<<roll<<endl; cout<<"Name is:"<<name<<endl;
23+
cout<<"Id is:"<<id<<endl;}
24+
};
25+
int main(){
26+
int x,z; string y;
27+
cout<<"Enter roll number:";
28+
cin>>x;
29+
cout<<"Enter name:";
30+
cin>>y;
31+
cout<<"Enter id number:";
32+
cin>>z;
33+
student s1(x,y,z);
34+
student s2=s1;
35+
return 0;
36+
}
50 KB
Binary file not shown.
44.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)