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

Lines changed: 40 additions & 0 deletions
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.*/
Lines changed: 16 additions & 0 deletions
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.
Lines changed: 32 additions & 0 deletions
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.
49.9 KB
Binary file not shown.

Class/Array-of-object-code.cpp

Lines changed: 32 additions & 0 deletions
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

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+
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.

0 commit comments

Comments
 (0)