Skip to content

Commit 790875a

Browse files
committed
Commit all working tree is now meant to be clean
1 parent 5eb790e commit 790875a

12 files changed

+474
-7
lines changed

Diff for: Expt_3_1.cpp

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#include<iostream>
2+
using namespace std;
3+
class hydrogen;
4+
class sulphur;
5+
class oxygen;
6+
class oxygen
7+
{
8+
public:
9+
int mass;
10+
oxygen()
11+
{
12+
mass=64;
13+
}
14+
void input(int m)
15+
{
16+
mass=m;
17+
}
18+
friend void empiricalmass(oxygen o,hydrogen h,sulphur s);
19+
};
20+
class hydrogen
21+
{
22+
public:
23+
int mass;
24+
hydrogen()
25+
{
26+
mass=2;
27+
}
28+
void input(int m)
29+
{
30+
mass=m;
31+
}
32+
friend void empiricalmass(oxygen o,hydrogen h,sulphur s);
33+
};
34+
class sulphur
35+
{
36+
public:
37+
int mass;
38+
sulphur()
39+
{
40+
mass=32;
41+
}
42+
void input(int m)
43+
{
44+
mass=m;
45+
}
46+
friend void empiricalmass(oxygen o,hydrogen h,sulphur s);
47+
};
48+
void empiricalmass(oxygen o,hydrogen h,sulphur s)
49+
{
50+
int x,y,z;
51+
float n1,n2,n3;
52+
cout<<"Lets see the masses you have entered"<<endl;
53+
cout<<"Mass of oxygen is "<<o.mass<<endl;
54+
cout<<"Mass of hydrogen is "<<h.mass<<endl;
55+
cout<<"Mass of sulphur is "<<s.mass<<endl;
56+
cout<<"Lets now see the number of moles of all the elements"<<endl;
57+
n1=o.mass/16;
58+
n2=h.mass/1;
59+
n3=s.mass/32;
60+
cout<<"Moles of oxygen are "<<n1<<endl;
61+
cout<<"Moles of hydrogen are "<<n2<<endl;
62+
cout<<"Moles of sulphur are "<<n3<<endl;
63+
cout<<"Now please enter the corrected rounded figures of moles"<<endl;
64+
cout<<"Enter the number of moles of oxygen "<<endl;
65+
cin>>x;
66+
cout<<"Enter the number of moles of hydrogen "<<endl;
67+
cin>>y;
68+
cout<<"Enter the number of moles of sulphur "<<endl;
69+
cin>>z;
70+
cout<<"The Emperical mass of oxygen, hydrogen and sulphur compounds is H"<<y<<"O"<<x<<"S"<<z<<endl;
71+
}
72+
int main()
73+
{
74+
float x,y,z;
75+
cout<<"Program to calculate the emperical formulae and molecular formulae of compound of S,H and O"<<endl;
76+
cout<<"Enter the mass of oxygen in grams"<<endl;
77+
cin>>x;
78+
cout<<"Enter the mass of Hydrogen in grams"<<endl;
79+
cin>>y;
80+
cout<<"Enter the mass of Sulphur in grams"<<endl;
81+
cin>>z;
82+
oxygen o;
83+
o.input(x);
84+
sulphur s;
85+
s.input(z);
86+
hydrogen h;
87+
h.input(y);
88+
empiricalmass(o,h,s);
89+
cout<<"Goodbye"<<endl;
90+
return 0;
91+
}
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+
110+
111+
112+
113+
114+

Diff for: Expt_3_2.cpp

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#include<math.h>
2+
#include<iostream>
3+
using namespace std;
4+
class shape
5+
{
6+
float l,b;
7+
public:
8+
shape()
9+
{
10+
l=10;
11+
b=20;
12+
}
13+
virtual void calculate_area()
14+
{
15+
cout<<"Area of Shape"<<endl;
16+
float area;
17+
area=l*b;
18+
}
19+
void input()
20+
{
21+
cout<<"Who cares"<<endl;
22+
}
23+
};
24+
class rectangle: public shape
25+
{
26+
float l,b;
27+
public:
28+
rectangle()
29+
{
30+
l=15;
31+
b=20;
32+
}
33+
void input(float x,float y)
34+
{
35+
l=x;
36+
b=y;
37+
}
38+
void calculate_area()
39+
{
40+
cout<<"Area of rectangle"<<endl;
41+
float area=l*b;
42+
cout<<"Area of rectangle is "<<area;
43+
}
44+
};
45+
class triangle: public shape
46+
{
47+
float s1,s2,s3;
48+
public:
49+
triangle()
50+
{
51+
s1=3;
52+
s2=4;
53+
s3=5;
54+
}
55+
void input(float x,float y,float z)
56+
{
57+
s1=x;
58+
s2=y;
59+
s3=z;
60+
}
61+
void calculate_area()
62+
{
63+
cout<<"Area of triangle by Heron's Formulae"<<endl;
64+
float area,s,a;
65+
s=(s1+s2+s3)/2;
66+
a=s*(s-s1)*(s-s2)*(s-s3);
67+
area=pow(a,0.5);
68+
cout<<"Area of triangle is "<<area;
69+
}
70+
};
71+
int main()
72+
{
73+
int ch;
74+
shape *p;
75+
rectangle r;
76+
triangle t;
77+
cout<<"Program to enter area of a given shape"<<endl;
78+
cout<<"Option Menu"<<endl;
79+
cout<<"1: Area of Rectangle"<<endl;
80+
cout<<"2: Area of Triangle"<<endl;
81+
cout<<"3: Exit"<<endl;
82+
cout<<"Enter your choice"<<endl;
83+
cin>>ch;
84+
switch(ch)
85+
{
86+
case 1:
87+
p=&r;
88+
cout<<"Rectangle"<<endl<<"Enter the length and breadth of rectangle"<<endl;
89+
float l,b;
90+
cin>>l>>b;
91+
r.input(l,b);
92+
p->calculate_area();
93+
break;
94+
case 2:
95+
p=&t;
96+
cout<<"Triangle"<<endl<<"Enter three sides of the triangle"<<endl;
97+
float s1,s2,s3;
98+
cin>>s1>>s2>>s3;
99+
t.input(s1,s2,s3);
100+
p->calculate_area();
101+
break;
102+
case 3: cout<<"Exit please"<<endl;
103+
break;
104+
default: cout<<"Wrong Choice"<<endl;
105+
}
106+
cout<<endl;
107+
return 0;
108+
}
109+
///////////////////////////////////Break the walls maen! Note only those functions that are initialized at base as virtual functions can be binded at runtime! Use the pointer with derived only for these functions and not for all.
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
122+

Diff for: Expt_3_3.cpp

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#include<iostream>
2+
using namespace std;
3+
class student
4+
{
5+
protected:
6+
string name,rollno,gender;
7+
public:
8+
student()
9+
{
10+
name="Nishkarsh Raj";
11+
rollno="R171217041";
12+
gender="Male";
13+
}
14+
void student_details(string s1,string s2, string s3)
15+
{
16+
name=s1;
17+
rollno=s2;
18+
gender=s3;
19+
}
20+
void display_student_details()
21+
{
22+
cout<<"Details of the student are"<<endl;
23+
cout<<"Name: "<<name<<endl;
24+
cout<<"Roll No: "<<rollno<<endl;
25+
cout<<"Gender: "<<gender<<endl;
26+
}
27+
};
28+
/////////////////////////////////////////
29+
class internal_marks: virtual public student
30+
{
31+
protected:
32+
float marks1[6];
33+
int i;
34+
public:
35+
void get_marks(float m[6])
36+
{
37+
for(i=0;i<6;i++)
38+
{
39+
marks1[i]=m[i];
40+
}
41+
}
42+
void display_marks()
43+
{
44+
cout<<"Lets see the Internal Marks of the student"<<endl;
45+
for(i=0;i<6;i++)
46+
{
47+
cout<<"Marks in subject number "<<i+1<<" are "<<marks1[i]<<endl;
48+
}
49+
}
50+
};
51+
/////////////////////////////////////////
52+
class external_marks: public virtual student
53+
{
54+
protected:
55+
float marks2[6];
56+
public:
57+
int i;
58+
void get_marks(float m[6])
59+
{
60+
for(i=0;i<6;i++)
61+
{
62+
marks2[i]=m[i];
63+
}
64+
}
65+
void display_marks()
66+
{
67+
cout<<"Lets see the External Marks of the student"<<endl;
68+
for(i=0;i<6;i++)
69+
{
70+
cout<<"Marks in subject number "<<i+1<<" are "<<marks2[i]<<endl;
71+
}
72+
}
73+
};
74+
////////////////////////////////////////
75+
class result: public internal_marks,public external_marks
76+
{
77+
public:
78+
float marks[6];
79+
int i;
80+
void display_result()
81+
{
82+
for(i=0;i<6;i++)
83+
{
84+
marks[i]=marks1[i]+marks2[i];
85+
cout<<"Marks in subject "<<i+1<<" out of 100 are "<<marks[i]<<endl;
86+
}
87+
}
88+
};
89+
////////////////////////////////////////
90+
int main()
91+
{
92+
int i;
93+
string name,roll,gender;
94+
cout<<"Program for Student marks calculation"<<endl;
95+
cout<<"Enter the name of the student"<<endl;
96+
getline(cin,name);
97+
cout<<"Enter the roll number of the student"<<endl;
98+
getline(cin,roll);
99+
cout<<"Enter the gender of the student"<<endl;
100+
cin>>gender;
101+
student s;
102+
s.student_details(name,roll,gender);
103+
cout<<"Enter the marks of student in internals 6 subject out of 30"<<endl;
104+
float marks[6],marks1[6];
105+
for(i=0;i<6;i++)
106+
{
107+
cout<<"Enter marks in subject "<<i+1<<endl;
108+
cin>>marks[i];
109+
}
110+
cout<<"Enter the marks of student in Externals 6 subject out of 70"<<endl;
111+
for(i=0;i<6;i++)
112+
{
113+
cout<<"Enter marks in subject "<<i+1<<endl;
114+
cin>>marks1[i];
115+
}
116+
internal_marks i1;
117+
i1.get_marks(marks);
118+
external_marks e;
119+
e.get_marks(marks1);
120+
result r;
121+
////////////////////////////////////
122+
cout<<"Lets see the result of the student"<<endl;
123+
s.display_student_details();
124+
i1.display_marks();
125+
e.display_marks();
126+
r.display_result();
127+
return 0;
128+
}

0 commit comments

Comments
 (0)