Skip to content

Commit 07d2ed4

Browse files
committed
Initial Commit
1 parent 1c11894 commit 07d2ed4

File tree

7 files changed

+348
-0
lines changed

7 files changed

+348
-0
lines changed

OOPS-Lab-6/OOPS Lab-6.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1. WAP to swap private data member of two classes.[The classes have no relation with each other]
2+
2. Create two classes which stores distance in feet, inches and meter, centimeter format respectively. Write a function which compares distance in object of these classes and displays the larger one.
3+
3. Create a class with an integer data member. Include fumctions for input and output in class. Count the number of times each function is called and display it.
4+
4. Create a class which stores name, roll number and total marks for a student. Input data for n students. Find the average marks scored by n students, store it as a data member of the class and display it using a function which may be called without object.
5+
5. Create a class which stores name, author and price of a book. Store mformation for n number of books. Display information of all the books in a given price range using friend function.
6+
6. Write a Program to declare three classes S1,S2 and S3.The classes have private data member variable of character data type. Read strings for the classes S1 and S2. Concatenate the strings read and assign it to the data member of class S3.Use New and delete operator.

OOPS-Lab-6/Q1.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+
class B;
4+
class A
5+
{
6+
private:
7+
int a;
8+
9+
public:
10+
A()
11+
{
12+
cout << "\nEnter the value of a: ";
13+
cin >> a;
14+
}
15+
void show()
16+
{
17+
cout << "\nAfter swapping, a is: " << a;
18+
}
19+
friend void swap(A *num1, B *num2);
20+
};
21+
class B
22+
{
23+
private:
24+
int b;
25+
26+
public:
27+
B()
28+
{
29+
cout << "Enter the value of b: ";
30+
cin >> b;
31+
}
32+
void show()
33+
{
34+
cout << "\nAfter swapping, b is: " << b;
35+
}
36+
friend void swap(A *a, B *b);
37+
};
38+
void swap(A *no1, B *no2)
39+
{
40+
int no3;
41+
no3 = no1->a;
42+
no1->a = no2->b;
43+
no2->b = no3;
44+
}
45+
int main()
46+
{
47+
cout << "\nProgrammed by 2005601_Rishabh Kumar";
48+
A ob1;
49+
B ob2;
50+
swap(&ob1, &ob2);
51+
ob1.show();
52+
ob2.show();
53+
return 0;
54+
}

OOPS-Lab-6/Q2.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <iostream>
2+
using namespace std;
3+
class B;
4+
class A
5+
{
6+
private:
7+
float x, y, temp1, temp2;
8+
9+
public:
10+
friend void large(A &, B &);
11+
void input()
12+
{
13+
cout << "\nEnter the distance in feet and inches resp: ";
14+
cin >> x >> y;
15+
temp1 = x;
16+
temp2 = y;
17+
x *= 30.48;
18+
y *= 2.54;
19+
x = x + y;
20+
}
21+
};
22+
class B
23+
{
24+
private:
25+
float a, b, temp1, temp2;
26+
27+
public:
28+
friend void large(A &, B &);
29+
void input()
30+
{
31+
cout << "\nEnter the distance in meter and centimeter resp: ";
32+
cin >> a >> b;
33+
temp1 = a;
34+
temp2 = b;
35+
a *= 100;
36+
a = a + b;
37+
}
38+
};
39+
void large(A &p, B &q)
40+
{
41+
if (p.x > q.a)
42+
{
43+
cout << "\n" << p.temp1 << " feet and " << p.temp2 << " inch is greater";
44+
}
45+
else
46+
{
47+
cout << "\n" << q.temp1 << " meter and " << q.temp2 << " centimeter is greater";
48+
}
49+
}
50+
int main()
51+
{
52+
cout << "\nProgrammed by 2005601_Rishabh Kumar";
53+
A p;
54+
p.input();
55+
B q;
56+
q.input();
57+
large(p, q);
58+
}

OOPS-Lab-6/Q3.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+
class A
4+
{
5+
private:
6+
int x;
7+
static int Input;
8+
static int Output;
9+
10+
public:
11+
void input();
12+
void output();
13+
void display();
14+
};
15+
int A::Input = 0;
16+
int A::Output = 0;
17+
void A::input()
18+
{
19+
cout << "Enter the value of x: ";
20+
cin >> x;
21+
Input++;
22+
}
23+
void A::output()
24+
{
25+
26+
cout << "The value of x is: " << x << endl;
27+
Output++;
28+
}
29+
void A::display()
30+
{
31+
cout << "The input function has been called " << Input << " times\n";
32+
cout << "The output function has been called " << Output << " times\n";
33+
}
34+
int main()
35+
{
36+
cout << "\nProgrammed by 2005601_Rishabh Kumar\n";
37+
A d;
38+
d.input();
39+
d.output();
40+
d.input();
41+
d.output();
42+
d.display();
43+
}

OOPS-Lab-6/Q4.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <iostream>
2+
#include <cstring>
3+
using namespace std;
4+
class A
5+
{
6+
char name[30];
7+
int roll;
8+
static float avg;
9+
10+
public:
11+
void input(char *p, int r, float a)
12+
{
13+
strcpy(name, p);
14+
roll = r;
15+
avg += a;
16+
}
17+
friend void show(A *arr, int n);
18+
};
19+
float A::avg;
20+
void show(A *arr, int n)
21+
{
22+
A::avg = (A::avg) / n;
23+
cout << "Average of the marks: " << A::avg << endl;
24+
}
25+
int main()
26+
{
27+
cout << "\nProgrammed by 2005601_Rishabh Kumar";
28+
int n;
29+
cout << "\nEnter the number of student: ";
30+
cin >> n;
31+
char a[30];
32+
int roll;
33+
float av;
34+
A s[n];
35+
for (int i = 0; i < n; i++)
36+
{
37+
cout << "\nEnter details of student " << i + 1 << endl;
38+
cout << " Enter Name: ";
39+
cin.ignore();
40+
cin.getline(a, 30);
41+
cout << " Enter Roll No.: ";
42+
cin >> roll;
43+
cout << " Enter Marks: ";
44+
cin >> av;
45+
cout << endl;
46+
s[i].input(a, roll, av);
47+
}
48+
show(s, n);
49+
return 0;
50+
}

OOPS-Lab-6/Q5.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <iostream>
2+
#include <string.h>
3+
using namespace std;
4+
class bookstore
5+
{
6+
string name;
7+
string author;
8+
float price;
9+
10+
public:
11+
void getbooks()
12+
{
13+
cout << "\nEnter name of the book: ";
14+
cin >> name;
15+
cout << "Enter name of the author: ";
16+
cin >> author;
17+
cout << "Enter the price of book: ";
18+
cin >> price;
19+
}
20+
friend void check(bookstore b[], int n);
21+
};
22+
void check(bookstore b[], int n)
23+
{
24+
int i, temp = 0;
25+
int low, up;
26+
cout << "\nEnter the price range(first low then high): ";
27+
cin >> low >> up;
28+
cout << "\nThe books in the range " << low << " to " << up << " are: " << endl;
29+
for (i = 0; i < n; i++)
30+
{
31+
if (b[i].price >= low && b[i].price <= up)
32+
{
33+
cout << "\nName of the book" << " : " << b[i].name << endl;
34+
cout << "Author of the book" << " : " << b[i].author << endl;
35+
cout << "Price of the book" << " : " << b[i].price << endl;
36+
temp++;
37+
}
38+
}
39+
if (temp == 0)
40+
{
41+
cout << "No books are in this price range." << endl;
42+
}
43+
}
44+
int main()
45+
{
46+
cout << "\nProgrammed by 2005601_Rishabh Kumar";
47+
int n, i;
48+
cout << "\nEnter the number of books: ";
49+
cin >> n;
50+
bookstore b[n];
51+
for (i = 0; i < n; i++)
52+
{
53+
b[i].getbooks();
54+
}
55+
check(b, n);
56+
return 0;
57+
}

OOPS-Lab-6/Q6.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include <iostream>
2+
#include <cstring>
3+
using namespace std;
4+
class B;
5+
class C;
6+
class A
7+
{
8+
string *a = new string;
9+
friend class C;
10+
11+
public:
12+
void input(void)
13+
{
14+
cout << "\nEnter string no. 1: ";
15+
getline(cin, *a);
16+
}
17+
void show()
18+
{
19+
cout << "\nFirst string is: " << *a << endl;
20+
}
21+
void del()
22+
{
23+
delete a;
24+
}
25+
};
26+
class B
27+
{
28+
string *b = new string;
29+
friend class C;
30+
31+
public:
32+
void input()
33+
{
34+
cout << "Enter string no. 2: ";
35+
getline(cin, *b);
36+
}
37+
void show()
38+
{
39+
cout << "Second string is: " << *b << endl;
40+
}
41+
void del()
42+
{
43+
delete b;
44+
}
45+
};
46+
class C
47+
{
48+
string *c = new string;
49+
50+
public:
51+
void join(A ob, B ob1)
52+
{
53+
*c = *ob.a + *ob1.b;
54+
}
55+
void show()
56+
{
57+
cout << "After concatenation, the new string is: " << *c << endl;
58+
}
59+
void del()
60+
{
61+
delete c;
62+
}
63+
};
64+
int main()
65+
{
66+
cout << "\nProgrammed by 2005601_Rishabh Kumar";
67+
A ob;
68+
B ob1;
69+
C ob2;
70+
ob.input();
71+
ob1.input();
72+
ob.show();
73+
ob1.show();
74+
ob2.join(ob, ob1);
75+
ob2.show();
76+
ob.del();
77+
ob1.del();
78+
ob2.del();
79+
return 0;
80+
}

0 commit comments

Comments
 (0)