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 b7c60fc

Browse files
Add files via upload
1 parent b22f2d2 commit b7c60fc

14 files changed

+456
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
class grandparent
5+
{
6+
protected:
7+
int base_data;
8+
public:
9+
void readgp()
10+
{
11+
cout<<"Enter data of grand parent :";
12+
cin>>base_data;
13+
}
14+
};
15+
16+
class parent1 : public virtual grandparent
17+
{
18+
protected:
19+
int parent1_data;
20+
public:
21+
void readp1()
22+
{
23+
cout<<"Enter data of parent 1 :";
24+
cin>>parent1_data;
25+
}
26+
};
27+
28+
class parent2 : virtual public grandparent
29+
{
30+
protected:
31+
int parent2_data;
32+
public:
33+
void readp2()
34+
{
35+
cout<<"Enter data of parent 2 :";
36+
cin>>parent2_data;
37+
}
38+
};
39+
40+
class child : public parent1, public parent2
41+
{
42+
private:
43+
int sum;
44+
public:
45+
void add()
46+
{
47+
sum = base_data + parent1_data + parent2_data;
48+
}
49+
void show()
50+
{
51+
cout<<"Grandparent's data member = "<<base_data;
52+
cout<<"\nParent 1 and Parent 2 data member = "<<parent1_data<<"\t"<<parent2_data;
53+
cout<<"\nSum of all data = "<<sum;
54+
}
55+
};
56+
57+
int main()
58+
{
59+
child c1;
60+
c1.readgp();
61+
c1.readp1();
62+
c1.readp2();
63+
c1.add();
64+
c1.show();
65+
return 0;
66+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class base
5+
{
6+
public:
7+
void display()
8+
{cout<<"Base class display is called\n";}
9+
};
10+
11+
class derv1: public base
12+
{
13+
public:
14+
void display()
15+
{cout<<"Derv1's class display is called\n";}
16+
};
17+
18+
class derv2: public base
19+
{
20+
public:
21+
void display()
22+
{cout<<"Derv2's class display is called\n";}
23+
};
24+
25+
int main()
26+
{
27+
base *ptr; //pointer to base class
28+
// base obj;
29+
// ptr = &obj;
30+
// ptr->display();
31+
derv1 d1;
32+
derv2 d2;
33+
ptr = &d1; //Address of d1 to base pointer
34+
ptr->display();
35+
ptr = &d2; //Address of d1 to base pointer
36+
ptr->display();
37+
38+
return 0;
39+
}

‎Practise Programs/103virtualfn.cpp‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class base
5+
{
6+
public:
7+
virtual void display()
8+
{cout<<"Base class display is called\n";}
9+
};
10+
11+
class derv1: public base
12+
{
13+
public:
14+
void display()
15+
{cout<<"Derv1's class display is called\n";}
16+
};
17+
18+
class derv2: public base
19+
{
20+
public:
21+
void display()
22+
{cout<<"Derv2's class display is called\n";}
23+
};
24+
25+
int main()
26+
{
27+
base *ptr; //pointer to base class
28+
base obj;
29+
ptr = &obj;
30+
ptr->display();
31+
derv1 d1;
32+
derv2 d2;
33+
ptr = &d1; //Address of d1 to base pointer
34+
ptr->display();
35+
ptr = &d2; //Address of d1 to base pointer
36+
ptr->display();
37+
38+
return 0;
39+
}

‎Practise Programs/104virtualfneg.cpp‎

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 shape
5+
{
6+
protected:
7+
float a,b;
8+
public:
9+
void read() { cin>>a>>b; }
10+
virtual void cal_area()
11+
{ cout<<"Virtual function"; }
12+
};
13+
14+
class rectangle : public shape
15+
{
16+
public:
17+
void cal_area()
18+
{
19+
float area = a*b;
20+
cout<<"\nArea of rectangle = "<<area;
21+
}
22+
};
23+
24+
class triangle : public shape
25+
{
26+
public:
27+
void cal_area()
28+
{
29+
float area = (a*b)/2;
30+
cout<<"\nArea of triangle = "<<area;
31+
}
32+
};
33+
34+
int main()
35+
{
36+
shape *ptr;
37+
rectangle r1;
38+
cout<<"Enter length and bredth of rectangle ";
39+
r1.read();
40+
ptr = &r1;
41+
ptr->cal_area();
42+
triangle t1;
43+
cout<<"\nEnter base and perpendicluar of triangle ";
44+
t1.read();
45+
ptr = &t1;
46+
ptr->cal_area();
47+
48+
return 0;
49+
}

‎Practise Programs/105streamgetfn.cpp‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// #include<iostream>
2+
// using namespace std;
3+
4+
// int main()
5+
// {
6+
// const int MAX = 80;
7+
// char str[MAX];
8+
// cout<<"Enter a string\n";
9+
// cin.get(str,MAX);
10+
// cout<<"String is ="<<str;
11+
12+
// return 0;
13+
// }
14+
15+
#include<iostream>
16+
using namespace std;
17+
18+
int main()
19+
{
20+
const int MAX = 80;
21+
char str[MAX];
22+
cout<<"Enter a string\n";
23+
cin.getline(str,MAX,'/');
24+
cout<<"\nString is =\n"<<str;
25+
26+
return 0;
27+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
char ch='x';
7+
cout.put(ch);
8+
cout.put('\n');
9+
cout.put('A');
10+
cout.put('\n');
11+
cout.put('b');
12+
cout.write("\n",1);
13+
cout.write("Hello Friends how are you",13);
14+
cout.write("\n",1);
15+
cout.write("Bye",3);
16+
return 0;
17+
}

‎Practise Programs/107createfile.cpp‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include<iostream>
2+
#include<fstream>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
int rollno,marks;
8+
char name[20];
9+
ofstream out_file("stud.txt");
10+
if(!out_file)
11+
{
12+
cerr<<"File cannot open correctly";
13+
exit(-1);
14+
}
15+
cout<<"Enter student details :";
16+
cout<<"\nRollno :"; cin>>rollno;
17+
cout<<"Name :"; cin>>name;
18+
cout<<"Marks :"; cin>>marks;
19+
cout<<"Writing student details into file...";
20+
out_file<<rollno<<endl;
21+
out_file<<name<<endl;
22+
out_file<<marks<<endl;
23+
24+
return 0;
25+
}

‎Practise Programs/108readfile.cpp‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include<iostream>
2+
#include<fstream>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
int rollno,marks;
8+
char name[20];
9+
ifstream inp_file("stud.txt");
10+
if(!inp_file)
11+
{
12+
cerr<<"File cannot open correctly";
13+
exit(-1);
14+
}
15+
inp_file>>rollno;
16+
inp_file>>name;
17+
inp_file>>marks;
18+
cout<<"Reading student details into file..."<<endl;
19+
cout<<"\nRollno :"<<rollno;
20+
cout<<"\nName :"<<name;
21+
cout<<"\nMarks :"<<marks;
22+
return 0;
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include<iostream>
2+
#include<fstream>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
char str[80];
8+
ifstream fin("multiplelines.txt");
9+
if(!fin)
10+
{
11+
cout<<"File cant open";
12+
exit(-1);
13+
}
14+
cout<<"Contents of file ...\n";
15+
while(fin.eof()==0)
16+
{
17+
fin.getline(str,80);
18+
cout<<str<<endl;
19+
}
20+
return 0;
21+
}

‎Practise Programs/110template.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<iostream>
2+
using namespace std;
3+
template<class T>
4+
T min(T &a, T &b) //or void min(T &a, T &b)
5+
{
6+
return(a<b)?a:b;
7+
}
8+
9+
int main()
10+
{
11+
int x,y;
12+
cout<<"Enter Integer Values"<<endl;
13+
cin>>x>>y;
14+
cout<<"Minimum numbers of Integers = "<<min(x,y);
15+
float p,q;
16+
cout<<"\nEnter Float Values"<<endl;
17+
cin>>p>>q;
18+
cout<<"Minimum numbers of Floats = "<<min(p,q);
19+
char c1,c2;
20+
cout<<"\nEnter two characters"<<endl;
21+
cin>>c1>>c2;
22+
cout<<"Minimum character value(based on ASCII value) = "<<min(c1,c2);
23+
return 0;
24+
}

0 commit comments

Comments
(0)

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