Skip to content

Commit 22859f9

Browse files
added cpps
1 parent 993604a commit 22859f9

10 files changed

+235
-0
lines changed

E BALAGURUSAMY/Class1.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Class in C++
2+
#include<iostream>
3+
using namespace std;
4+
class people{
5+
char name[30];
6+
int age;
7+
public:
8+
void dataset(void);
9+
void datafetch(void);
10+
11+
};
12+
void people::dataset(){
13+
cout<<"Enter Name : ";
14+
cin>>name;
15+
cout<<endl<<"Enter Age : ";
16+
cin>>age;
17+
}
18+
void people::datafetch(){
19+
cout<<endl<<"Name : "<<name;
20+
cout<<endl<<"Age : "<<age;
21+
}
22+
int main(){
23+
people k;
24+
k.dataset();
25+
k.datafetch();
26+
return 0;
27+
}

E BALAGURUSAMY/Class2.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Class in C++
2+
#include<iostream>
3+
using namespace std;
4+
class item{
5+
float cost;
6+
int number;
7+
public:
8+
void dataset(int x,float y);
9+
void datafetch(void){
10+
cout<<"Number : "<<number;
11+
cout<<endl<<"Cost : "<<cost<<endl;
12+
}
13+
};
14+
void item::dataset(int x,float y){
15+
cost=y;
16+
number=x;
17+
}
18+
int main(){
19+
item p;
20+
cout<<"1st object"<<endl;
21+
p.dataset(100,299.95);
22+
p.datafetch();
23+
item q;
24+
cout<<endl<<"2nd object"<<endl;
25+
q.dataset(200,175.50);
26+
q.datafetch();
27+
return 0;
28+
}

E BALAGURUSAMY/Manipulators.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Manipulators in C++
2+
#include<iostream>
3+
#include<iomanip>
4+
using namespace std;
5+
int main(){
6+
int x=56,y=345,z=3765;
7+
cout<<setw(10)<<"X"<<setw(10)<<x<<endl
8+
<<setw(10)<<"Y"<<setw(10)<<y<<endl
9+
<<setw(10)<<"Z"<<setw(10)<<z<<endl;
10+
return 0;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Scope of a variable (scope resolution operator)
2+
#include<iostream>
3+
using namespace std;
4+
int x=40;
5+
int main(){
6+
int x=50;
7+
{
8+
int y=x;
9+
int x=30;
10+
cout<<"Inside innermost block";
11+
cout<<"\nx = "<<x;
12+
cout<<"\ny = "<<y;
13+
cout<<"\n::x = "<<::x;
14+
}
15+
cout<<"\nOutside inner block";
16+
cout<<"\nx = "<<x;
17+
cout<<"\n::x = "<<::x;
18+
return 0;
19+
}

E BALAGURUSAMY/default-args.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Default Argumentation
2+
#include<iostream>
3+
using namespace std;
4+
void line(char k='*',int n=30){
5+
for(int i=0;i<=n;i++) cout<<k;
6+
cout<<endl;
7+
}
8+
float val(float x,float y,float z=0.15){
9+
int p=1;
10+
float s=x;
11+
while (p<=y){
12+
s*=1+z;
13+
p+=1;
14+
}
15+
return(s);
16+
}
17+
int main(){
18+
float m;
19+
line();
20+
m=val(5000.00,5);
21+
cout<<endl<<"Net value = "<<m<<endl<<"\n";
22+
line('=');
23+
return 0;
24+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Function Overloading in C++
2+
#include<iostream>
3+
using namespace std;
4+
int vol(int);
5+
double vol(double,int);
6+
long vol(long,int,int);
7+
int main(){
8+
cout<<"vol.1 = "<<vol(10)<<endl;
9+
cout<<"vol.2 = "<<vol(2.5,8)<<endl;
10+
cout<<"vol.3 = "<<vol(100L,75,15)<<endl;
11+
return 0;
12+
}
13+
int vol(int k){
14+
return(k*k*k);
15+
}
16+
double vol(double x,int y){
17+
return(3.14159*x*x*y);
18+
}
19+
long vol(long p,int q, int r){
20+
return(p*q*r);
21+
}

E BALAGURUSAMY/inline-functions.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Inline function is a request to the compiler not a command
2+
#include<iostream>
3+
using namespace std;
4+
inline float into(float m,float n){
5+
return(m*n);
6+
}
7+
inline float upon(double u,double v){
8+
return(u/v);
9+
}
10+
int main(){
11+
float x=25.678,y=7.48;
12+
cout<<"x*y = "<<into(x,y)<<"\n";
13+
cout<<"x/y = "<<upon(x,y);
14+
return 0;
15+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Nesting of member functions
2+
#include<iostream>
3+
using namespace std;
4+
class collection{
5+
int p,q;
6+
public:
7+
void get(void);
8+
void show(void);
9+
int greatest(void);
10+
};
11+
int collection::greatest(void){
12+
if(p>=q)
13+
return(p);
14+
else
15+
return(q);
16+
}
17+
void collection::get(void){
18+
cout<<"Enter vals. of P & Q : ";
19+
cin>>p>>q;
20+
}
21+
void collection::show(void){
22+
cout<<"\nGreatest Val. = "<<greatest();
23+
}
24+
int main(){
25+
collection n;
26+
n.get();
27+
n.show();
28+
return 0;
29+
}

E BALAGURUSAMY/static-data-member.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Static Class Members
2+
#include<iostream>
3+
using namespace std;
4+
class item{
5+
static int c;
6+
int n;
7+
public:
8+
void input(int k){
9+
n=k;
10+
c++;
11+
}
12+
void count(void){
13+
cout<<"Count : "<<c<<endl;
14+
}
15+
};
16+
int item::c;
17+
int main(){
18+
item x,y,z;
19+
x.count();
20+
y.count();
21+
z.count();
22+
x.input(100);
23+
y.input(200);
24+
z.input(300);
25+
cout<<"Data added"<<endl;
26+
x.count();
27+
y.count();
28+
z.count();
29+
return 0;
30+
}
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//Static Member Functions in a class
2+
#include<iostream>
3+
using namespace std;
4+
class stats{
5+
int k;
6+
static int c;
7+
public:
8+
void code(void){
9+
k=++c;
10+
}
11+
void display(void){
12+
cout<<"Obj. no. = "<<k<<endl;
13+
}
14+
static void cdisp(void){
15+
cout<<"Count = "<<c<<endl;
16+
}
17+
};
18+
int stats::c;
19+
int main(){
20+
stats o1,o2;
21+
o1.code();
22+
o2.code();
23+
stats::cdisp();
24+
stats o3;
25+
o3.code();
26+
stats::cdisp();
27+
o1.display();
28+
o2.display();
29+
o3.display();
30+
return 0;
31+
}

0 commit comments

Comments
 (0)