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 620e4fe

Browse files
Get commited please
1 parent 823a3fd commit 620e4fe

15 files changed

+486
-16
lines changed

‎Commandline.cpp

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(int argc,char *argv[])
4+
{
5+
int i=1;
6+
cout<<"The name of the file is"<<argv[0]<<endl;
7+
while(i<argc)
8+
{
9+
cout<<"The "<<i<<" string is "<<argv[i]<<endl;
10+
i++;
11+
}
12+
return 0;
13+
}

‎Inheritance.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include<iostream>
2+
using namespace std;
3+
class WWE
4+
{
5+
int serial;
6+
public:
7+
string name;
8+
float salary;
9+
WWE()
10+
{
11+
serial=1;
12+
name="Finn Balor";
13+
salary=40000;
14+
}
15+
void insert()
16+
{
17+
cout<<"Make the entries of the superstar"<<endl;
18+
cout<<"Enter the serial number of the superstar ";
19+
cin>>serial;
20+
cout<<endl;
21+
cout<<"Enter the name of the superstar ";
22+
cin>>name;
23+
cout<<endl;
24+
cout<<"Enter the salary of the superstar ";
25+
cin>>salary;
26+
cout<<endl;
27+
}
28+
void show()
29+
{
30+
cout<<"Name of the superstar is "<<name<<endl<<"Serial of the superstar "<<serial<<endl<<"Salary of the superstar "<<salary<<endl;
31+
}
32+
};
33+
/////////////////////////////////////////////////////////////////////////////////////////////////////
34+
class record:public WWE
35+
{
36+
string sex;
37+
public:
38+
record()
39+
{
40+
sex="male";
41+
}
42+
void show1()
43+
{
44+
cout<<"Name of the superstar is "<<name<<endl;
45+
cout<<"Win/Loss Record of the Superstar is 80 wins to 6 losses "<<endl;
46+
cout<<"Salary of the superstar is "<<salary<<endl;
47+
cout<<"Sex of the superstar is "<<sex<<endl;
48+
}
49+
};
50+
///////////////////////////////////////////////////////////////////////////////////////////////////
51+
int main()
52+
{
53+
cout<<"Hello! This is a program depicting Inheritance"<<endl;
54+
WWE nish;
55+
nish.show();
56+
nish.insert();
57+
nish.show();
58+
record nish1;
59+
nish1.show1();
60+
return 0;
61+
}
62+

‎Inheritance/a.out

13.4 KB
Binary file not shown.

‎Inheritance/single_private.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include<iostream>
2+
using namespace std;
3+
class base
4+
{
5+
int a;
6+
protected:
7+
int b;
8+
public:
9+
int c;
10+
void set_data(int a1,int b1, int c1)
11+
{
12+
a=a1; b=b1; c=c1;
13+
}
14+
base()
15+
{
16+
a=10; b=15; c=20;
17+
}
18+
};
19+
class derived: private base
20+
{
21+
int a2;
22+
protected:
23+
int b2;
24+
public:
25+
int c2;
26+
derived()
27+
{
28+
a2=5;
29+
b2=6;
30+
c2=10;
31+
}
32+
void show()
33+
{
34+
//cout<<"Protected Member of base "<<b<<endl;
35+
//cout<<"Public Member of base "<<c<<endl;
36+
cout<<"Private Member of Derived "<<a2<<endl;
37+
cout<<"Protected Member of Derived "<<b2<<endl;
38+
cout<<"Public Member of Derived "<<c2<<endl;
39+
cout<<endl;
40+
}
41+
};
42+
int main()
43+
{
44+
cout<<"Single Level Inheritance with private derivation"<<endl;
45+
derived obj;
46+
obj.show();
47+
//obj.set_data(5,14,16);
48+
//obj.show();
49+
return 0;
50+
}
51+
52+
53+
/* Note that in private derivation all the data members and member functions are inheritable yet all are inaccessible as well. The linux CLI also states that the base is an inaccessible in the child class */
54+
55+
56+
57+

‎Inheritance/single_protected.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include<iostream>
2+
using namespace std;
3+
class base
4+
{
5+
int a;
6+
protected:
7+
int b;
8+
public:
9+
int c;
10+
void set_data(int a1,int b1, int c1)
11+
{
12+
a=a1; b=b1; c=c1;
13+
}
14+
base()
15+
{
16+
a=10; b=15; c=20;
17+
}
18+
};
19+
class derived: protected base
20+
{
21+
int a2;
22+
protected:
23+
int b2;
24+
public:
25+
int c2;
26+
derived()
27+
{
28+
a2=5;
29+
b2=6;
30+
c2=10;
31+
}
32+
void show()
33+
{
34+
cout<<"Protected Member of base "<<b<<endl;
35+
cout<<"Public Member of base "<<c<<endl;
36+
cout<<"Private Member of Derived "<<a2<<endl;
37+
cout<<"Protected Member of Derived "<<b2<<endl;
38+
cout<<"Public Member of Derived "<<c2<<endl;
39+
cout<<endl;
40+
}
41+
void show1()
42+
{
43+
set_data(5,6,10);
44+
cout<<"Protected Member of base "<<b<<endl;
45+
cout<<"Public Member of base "<<c<<endl;
46+
cout<<"Private Member of Derived "<<a2<<endl;
47+
cout<<"Protected Member of Derived "<<b2<<endl;
48+
cout<<"Public Member of Derived "<<c2<<endl;
49+
}
50+
};
51+
int main()
52+
{
53+
cout<<"Single Level Inheritance with protected derivation"<<endl;
54+
derived obj;
55+
obj.show();
56+
obj.show1();
57+
return 0;
58+
}
59+
/* Note that in protected derivations public and private members are accessible only as protected. That is they can be accessed within child class but not in main with the object. Thats why here we have called set_data function within the derived class and not in main.
60+
"Protected members are like private for a given class" */
61+
62+
63+
64+

‎Inheritance/single_public.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include<iostream>
2+
using namespace std;
3+
class base
4+
{
5+
int a;
6+
protected:
7+
int b;
8+
public:
9+
int c;
10+
void set_data(int a1,int b1, int c1)
11+
{
12+
a=a1; b=b1; c=c1;
13+
}
14+
base()
15+
{
16+
a=10; b=15; c=20;
17+
}
18+
};
19+
class derived: public base
20+
{
21+
int a2;
22+
protected:
23+
int b2;
24+
public:
25+
int c2;
26+
derived()
27+
{
28+
a2=5;
29+
b2=6;
30+
c2=10;
31+
}
32+
void show()
33+
{
34+
cout<<"Protected Member of base "<<b<<endl;
35+
cout<<"Public Member of base "<<c<<endl;
36+
cout<<"Private Member of Derived "<<a2<<endl;
37+
cout<<"Protected Member of Derived "<<b2<<endl;
38+
cout<<"Public Member of Derived "<<c2<<endl;
39+
cout<<endl;
40+
}
41+
};
42+
int main()
43+
{
44+
cout<<"Single Level Inheritance with public derivation"<<endl;
45+
derived obj;
46+
obj.show();
47+
obj.set_data(5,14,16);
48+
obj.show();
49+
return 0;
50+
}
51+
/* Note that in public derivations the constructor of the parent class is invoked without even making the object of parent class if the object of the derived class is made because derived class inherits the constructor publically with its values */
52+
53+
54+
55+

‎a.out

6.09 KB
Binary file not shown.

‎class.cpp renamed to ‎class1.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
using namespace std;
44
class student
55
{
6-
string student_name[20];
6+
string student_name;
77
int roll_no;
88
int SAP_ID;
9-
string Specialisation[5];
9+
string Specialisation;
1010
public:
1111
void Read_data()
1212
{
1313
cout<<"Enter Student's Name"<<endl;
14-
cin.getline(student_name);
14+
cin>>student_name;
1515
cout<<"Enter Roll number of student"<<endl;
1616
cin>>roll_no;
1717
cout<<"Enter SAP_ID of the student"<<endl;
1818
cin>>SAP_ID;
1919
cout<<"Enter the Specialisation of the student"<<endl;
20-
cin.getline(Specialisation);
20+
cin>>Specialisation;
2121
}
2222
void show()
2323
{

‎friendone.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ class ABC
44
{
55
int a,b;
66
public:
7-
void setdata()
7+
void setdata(int m,int n)
88
{
9-
a=10,b=25;
9+
a=m,b=n;
1010
}
1111
friend float mean(class ABC x);
1212
};
@@ -16,7 +16,11 @@ cout<<(x.a+x.b)/2;
1616
}
1717
int main()
1818
{
19+
int m,n;
1920
ABC y;
20-
y.setdata();
21+
cout<<"Enter two values whose mean you want"<<endl;
22+
cin>>m>>n;
23+
y.setdata(m,n);
2124
mean(y);
25+
cout<<endl;
2226
}

‎hybridex.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include<iostream>
2+
using namespace std;
3+
class grandmother
4+
{
5+
protected:
6+
string name="Maya Rani Khare";
7+
public:
8+
void show12()
9+
{
10+
cout<<"Name of the grandmother is "<<name<<endl;
11+
}
12+
};
13+
class father: virtual public grandmother
14+
{
15+
protected:
16+
string name="Raj Khare";
17+
public:
18+
void show1()
19+
{
20+
cout<<"Name of the father is "<<name<<endl;
21+
}
22+
};
23+
class mother: public virtual grandmother
24+
{
25+
protected:
26+
string name="Shivanee Kanchan";
27+
public:
28+
void show2()
29+
{
30+
cout<<"Name of the mother is "<<name<<endl;
31+
}
32+
};
33+
class child: public mother,public father
34+
{
35+
protected:
36+
string name;
37+
public:
38+
child(string c)
39+
{
40+
name=c;
41+
}
42+
void show()
43+
{
44+
show12();
45+
show1();
46+
show2();
47+
cout<<"Name of the child is "<<name<<endl;
48+
}
49+
};
50+
int main()
51+
{
52+
cout<<"Code for hybrid level"<<endl;
53+
child nish("Nishkarsh Raj");
54+
nish.show();
55+
cout<<"\n\n\n\n";
56+
cout<<sizeof(grandmother)<<endl;
57+
cout<<sizeof(father)<<endl;
58+
cout<<sizeof(mother)<<endl;
59+
cout<<sizeof(child)<<endl;
60+
return 0;
61+
}

0 commit comments

Comments
(0)

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