Skip to content

Commit 1d75cdd

Browse files
committed
added lab 8 programs
1 parent bb24295 commit 1d75cdd

12 files changed

+171
-0
lines changed

Lab_8/Q1/output.png

8.39 KB
Loading

Lab_8/Q1/power_of_number

16.9 KB
Binary file not shown.

Lab_8/Q1/power_of_number.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
class Power{
6+
private:
7+
int number;
8+
int power;
9+
int answer;
10+
void calculate(){
11+
if (power == 0)
12+
answer = 1;
13+
else
14+
for(int i = 0; i < power;i++)
15+
answer *= number;
16+
cout<<"\n"<<number<<"^"<<power<<" is: "<<answer<<"\n";
17+
}
18+
public:
19+
Power(int num, int p){
20+
answer = 1;
21+
number = num;
22+
power = p;
23+
calculate();
24+
}
25+
};
26+
27+
int main(){
28+
Power obj(3,4);
29+
return 0;
30+
}

Lab_8/Q2/Empoyee_data

17.9 KB
Binary file not shown.

Lab_8/Q2/Empoyee_data.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
using namespace std;
5+
6+
class Employee
7+
{
8+
string name;
9+
int id;
10+
public:
11+
void getdetails()
12+
{
13+
cout << "\nEnter name: ";
14+
cin >> name;
15+
cout << "Enter id: ";
16+
cin >> id;
17+
}
18+
void displayInfo()
19+
{
20+
cout << "\nid: " << id << " ";
21+
cout << "name: " << name<<"\n";
22+
}
23+
};
24+
25+
const int no_of_employee = 5;
26+
27+
int main()
28+
{
29+
Employee st[no_of_employee];
30+
for( int i=0; i < no_of_employee; i++ )
31+
{
32+
cout << "Employee " << i + 1;
33+
st[i].getdetails();
34+
}
35+
36+
for( int i=0; i < no_of_employee; i++ )
37+
{
38+
cout << "\nEmployee " << i + 1;
39+
st[i].displayInfo();
40+
}
41+
return 0;
42+
}

Lab_8/Q2/output.png

44.8 KB
Loading

Lab_8/Q3/fun_overloading_using_this

17.1 KB
Binary file not shown.
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class Area{
5+
private:
6+
int s,l,b;
7+
float bs,ht;
8+
public:
9+
int area(int s){
10+
this->s = s;
11+
return(this->s*this->s);
12+
}
13+
int area(int l,int b){
14+
this->l = l;
15+
this->b = b;
16+
return(this->l*this->b);
17+
}
18+
float area(float bs,float ht){
19+
this->bs = bs;
20+
this->ht = ht;
21+
return((this->bs*this->ht)/2);
22+
}
23+
};
24+
25+
int main()
26+
{
27+
int s,l,b;
28+
float bs,ht;
29+
Area obj;
30+
cout<<"Enter side of a square: ";
31+
cin>>s;
32+
cout<<"Enter length and breadth of rectangle: ";
33+
cin>>l>>b;
34+
cout<<"Enter base and height of triangle: ";
35+
cin>>bs>>ht;
36+
cout<<"Area of square is "<<obj.area(s);
37+
cout<<"\nArea of rectangle is "<<obj.area(l,b);
38+
cout<<"\nArea of triangle is "<<obj.area(bs,ht)<<"\n";
39+
}

Lab_8/Q3/output.png

28.3 KB
Loading
17.4 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <iostream>
2+
#include <cmath>
3+
4+
using namespace std;
5+
6+
class Equations{
7+
private:
8+
double a, b, c, eq[3];
9+
void addvalue(){
10+
eq[0] = pow(this->b,3) - pow(this->c,2);
11+
eq[1] = pow(this->b,2) + pow(this->c,2) - 4*this->a*this->c;
12+
eq[2] = pow(this->b,2) + pow(this->c, 2) + 2*this->a*this->c;
13+
}
14+
void show_result(){
15+
cout<<"\nb^3 - c^2 = "<< eq[0]<<"\n";
16+
cout<<"b^2 + c^2 - 4ac = "<< eq[1]<<"\n";
17+
cout<<"b^2 + c^2 + 2ac = "<< eq[2]<<"\n";
18+
}
19+
public:
20+
Equations(){
21+
a, b, c, eq[0], eq[1], eq[2] = 0;
22+
}
23+
void result(int a, int b, int c){
24+
this->a = a;
25+
this->b = b;
26+
this->c = c;
27+
addvalue();
28+
show_result();
29+
}
30+
void result(double a, double b, double c){
31+
this->a = a;
32+
this->b = b;
33+
this->c = c;
34+
addvalue();
35+
show_result();
36+
}
37+
void result(int a, double b, int c){
38+
this->a = a;
39+
this->b = b;
40+
this->c = c;
41+
addvalue();
42+
show_result();
43+
}
44+
void result(int a, int b, double c){
45+
this->a = a;
46+
this->b = b;
47+
this->c = c;
48+
addvalue();
49+
show_result();
50+
}
51+
};
52+
53+
int main(){
54+
Equations obj;
55+
obj.result(5,3,2);
56+
obj.result(2.2,4.7,1.9);
57+
obj.result(7,2,4.77);
58+
obj.result(3,6.143,5);
59+
return 0;
60+
}

Lab_8/Q4/output.png

37 KB
Loading

0 commit comments

Comments
 (0)