Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ea47471

Browse files
Add files via upload
1 parent b7c60fc commit ea47471

17 files changed

+926
-0
lines changed

‎Practise Programs/100hybridinhrit.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class student
5+
{
6+
private:
7+
int rollno;
8+
char name[20];
9+
public:
10+
void read()
11+
{
12+
cout<<"\nEnter Rollno and Name:\n";
13+
cin>>rollno>>name;
14+
}
15+
void show()
16+
{
17+
cout<<"\nRollno = "<<rollno;
18+
cout<<"\nName = "<<name;
19+
}
20+
};
21+
22+
class exam_internal : public student
23+
{
24+
protected:
25+
int sub1_marks;
26+
int sub2_marks;
27+
public:
28+
void read_marks()
29+
{
30+
cout<<"\nEnter Internal Marks of Subject 1 (MAX:40) :\n";
31+
cin>>sub1_marks;
32+
cout<<"\nEnter Internal Marks of Subject 2 (MAX:40) :\n";
33+
cin>>sub2_marks;
34+
}
35+
void display_marks()
36+
{
37+
cout<<"\nInternal Marks of Sub 1 = "<<sub1_marks;
38+
cout<<"\nInternal Marks of Sub 2 = "<<sub2_marks;
39+
}
40+
};
41+
42+
class exam_external : public student
43+
{
44+
protected:
45+
int sub1_ext_marks;
46+
int sub2_ext_marks;
47+
public:
48+
void read_marks()
49+
{
50+
cout<<"\nEnter Internal Marks of Subject 1 (MAX:40) :\n";
51+
cin>>sub1_ext_marks;
52+
cout<<"\nEnter Internal Marks of Subject 2 (MAX:40) :\n";
53+
cin>>sub2_ext_marks;
54+
}
55+
void display_marks()
56+
{
57+
cout<<"\nExternal Marks of Sub 1 = "<<sub1_ext_marks;
58+
cout<<"\nExternal Marks of Sub 2 = "<<sub2_ext_marks;
59+
}
60+
};
61+
62+
class result:public exam_internal, public exam_external
63+
{
64+
private:
65+
int total_marks;
66+
public:
67+
void cal_result()
68+
{
69+
total_marks = sub1_ext_marks+sub2_ext_marks+sub1_marks+sub2_marks;
70+
cout<<"Total Marks Obtained = "<<total_marks;
71+
}
72+
};
73+
74+
int main()
75+
{
76+
result r1;
77+
cout<<"Enter student information :\n";
78+
r1.exam_internal::read();//call read() of student class
79+
cout<<"Enter marks of Internal Examination:\n";
80+
r1.exam_internal::read_marks(); //To resolve ambiguty
81+
cout<<"Enter marks of External Examination:\n";
82+
r1.exam_external::read_marks(); //To resolve ambiguty
83+
cout<<"\nDisplaying Student Details\n";
84+
r1.exam_internal::show(); //Calls show of student class
85+
r1.exam_internal::display_marks(); //To resolve ambiguty
86+
r1.exam_external::display_marks(); //To resolve ambiguty
87+
cout<<"\nCalculating and displaying result\n";
88+
r1.cal_result();
89+
90+
return 0;
91+
}

‎Practise Programs/84unaryoperover.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+
4+
class score
5+
{
6+
private:
7+
int val;
8+
public:
9+
score()
10+
{ val = 0; }
11+
void operator ++() //operator function defination
12+
{
13+
val=val+1;
14+
}
15+
int show(){
16+
return (val);
17+
}
18+
};
19+
20+
int main()
21+
{
22+
score s1,s2;
23+
cout<<"\nInitial value of s1 object = "<<s1.show();
24+
cout<<"\nInitial value of s2 object = "<<s2.show();
25+
++s1; //operator function call
26+
++s1; //same as s1.operator++();
27+
++s2;
28+
cout<<"\nFinal value of s1 object = "<<s1.show();
29+
cout<<"\nFinal value of s2 object = "<<s2.show();
30+
31+
return 0;
32+
}

‎Practise Programs/85oprretval.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+
class score
5+
{
6+
private:
7+
int val;
8+
public:
9+
score()
10+
{ val = 0; }
11+
score operator ++() //prefix overloaded operator function Eg. ++i
12+
{
13+
score temp;
14+
val=val+1;
15+
temp.val = val;
16+
return(temp);
17+
}
18+
score operator ++(int) //postfix overloaded operator function Eg. i++
19+
{
20+
score temp;
21+
temp.val = val;
22+
val=val+1;
23+
return(temp);
24+
}
25+
int show(){
26+
return (val);
27+
}
28+
};
29+
30+
int main()
31+
{
32+
score s1,s2;
33+
cout<<"\nInitial value of s1 object = "<<s1.show();
34+
cout<<"\nInitial value of s2 object = "<<s2.show();
35+
s2 = ++s1;
36+
cout<<"\ns1 = "<<s1.show();
37+
cout<<"\nValue of s2 after prefix operation = "<<s2.show();
38+
s2 = s1++;
39+
cout<<"\ns1 = "<<s1.show();
40+
cout<<"\nValue of s2 after prefix operation = "<<s2.show();
41+
42+
return 0;
43+
}

‎Practise Programs/86oproverbinary.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class complex
5+
{
6+
private:
7+
double real,img;
8+
public:
9+
complex()
10+
{ real=img=0; }
11+
void read()
12+
{
13+
cout<<"\nEnter real and imaginary parts: "<<endl;
14+
cin>>real>>img;
15+
}
16+
complex operator +(complex cc2) // Overload operator function t
17+
{
18+
complex temp;
19+
temp.real = real + cc2.real;
20+
temp.img = img + cc2.img;
21+
return temp;
22+
}
23+
complex operator -(complex cc2) // Overload operator function t
24+
{
25+
complex temp;
26+
temp.real = real - cc2.real;
27+
temp.img = img - cc2.img;
28+
return temp;
29+
}
30+
void show()
31+
{
32+
if(img>0)
33+
cout<<real<<"+"<<img<<"i"<<endl;
34+
else
35+
cout<<real<<img<<"i"<<endl;
36+
}
37+
};
38+
39+
int main()
40+
{
41+
complex c1,c2,c3,c4;
42+
cout<<"Enter complex number c1 :";
43+
c1.read();
44+
cout<<"Enter complex number c2 :";
45+
c2.read();
46+
c3 = c1 + c2; //call to operator function +
47+
c4 = c1 - c2; //call to operator function -
48+
cout<<"\nAfter adding :\n";
49+
c3.show();
50+
cout<<"After subtracting :\n";
51+
c4.show();
52+
53+
return 0;
54+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class dob
5+
{
6+
private:
7+
int dd,mm,yyyy;
8+
public:
9+
dob(int d, int m, int y)
10+
{
11+
dd=d; mm=m; yyyy=y;
12+
}
13+
void show()
14+
{
15+
cout<<"DOB = "<<dd<<"-"<<mm<<"-"<<yyyy<<"\n";
16+
}
17+
int operator ==(dob);
18+
};
19+
int dob::operator==(dob dd2) //overloading operator function defination
20+
{
21+
if((yyyy==dd2.yyyy) && (mm==dd2.mm) && (dd==dd2.dd))
22+
{
23+
return 1;
24+
}else
25+
{
26+
return 0;
27+
}
28+
29+
}
30+
int main()
31+
{
32+
int dd1,mm1,yy1,dd2,mm2,yy2;
33+
cout<<"Enter date of birth 1 (Format : dd mm yyyy) :";
34+
cin>>dd1>>mm1>>yy1;
35+
dob d1(dd1,mm1,yy1);
36+
cout<<"Enter date of birth 2 (Format : dd mm yyyy) :";
37+
cin>>dd2>>mm2>>yy2;
38+
dob d2(dd2,mm2,yy2);
39+
d1.show();
40+
d2.show();
41+
if(d1==d2) // overloaded operator function call
42+
{
43+
cout<<"d1 and d2 are same DOB's";
44+
}else{
45+
cout<<"d1 and d2 have different DOB's";
46+
}
47+
48+
return 0;
49+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include<iostream>
2+
#include<string.h>
3+
using namespace std;
4+
5+
class strng
6+
{
7+
char st[20];
8+
public:
9+
strng() // Construtor with no paramenter
10+
{
11+
strcpy(st," ");
12+
}
13+
strng(char s[]) // Construtor with one paramenter
14+
{
15+
strcpy(st,s);
16+
}
17+
void show()
18+
{
19+
cout<<st;
20+
}strng operator +(strng); //declaration of overloaded operator function
21+
};
22+
strng strng::operator +(strng ss2)
23+
{
24+
strng temp; // create temporary object
25+
strcpy(temp.st,st); // copy string left object
26+
strcat(temp.st,ss2.st); // add string of right object
27+
return(temp);
28+
}
29+
int main()
30+
{
31+
char h[6] = "Happy";
32+
char d[8] = " Diwali";
33+
strng s1(h); // Uses one parameter construtor
34+
strng s2(d);
35+
strng s3; // Uses construtor with no parameter
36+
cout<<"Before concatenation \n";
37+
cout<<"s1 = ";
38+
s1.show();
39+
cout<<"\ts2 = ";
40+
s2.show();
41+
cout<<"\ts3 = ";
42+
s3.show();
43+
s3 = s1 +s2; // equivalent to s1.operator+(s2);
44+
cout<<"\nAfter Concatenation \n";
45+
s3.show();
46+
47+
return 0;
48+
}
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 score
5+
{
6+
private:
7+
int val;
8+
public:
9+
score()
10+
{ val = 0; }
11+
12+
int show(){
13+
return (val);
14+
}
15+
friend score operator++(score &); // prefix
16+
friend score operator++(score & ,int); // postfix
17+
};
18+
19+
score operator ++(score &temp) //prefix overloaded operator function Eg. ++i
20+
{
21+
temp.val=temp.val+1;
22+
return(temp);
23+
}
24+
score operator ++(score &temp,int) //postfix overloaded operator function Eg. i++
25+
{
26+
temp.val = temp.val;
27+
temp.val=temp.val+1;
28+
return(temp);
29+
}
30+
31+
int main()
32+
{
33+
score s1,s2;
34+
cout<<"\nInitial value of s1 object = "<<s1.show();
35+
cout<<"\nInitial value of s2 object = "<<s2.show();
36+
s2 = ++s1;
37+
cout<<"\ns1 = "<<s1.show();
38+
cout<<"\nValue of s2 after prefix operation = "<<s2.show();
39+
s2 = s1++;
40+
cout<<"\ns1 = "<<s1.show();
41+
cout<<"\nValue of s2 after prefix operation = "<<s2.show();
42+
43+
return 0;
44+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /