OOPS File
OOPS File
Practical File
Submitted by:-
Kaustubh Sharma
02451203119
IT 2nd Shift
INDEX
S.No. Date Experiment Remarks
1 5/4/21 Write a program for multiplication of two
matrices using OOP.
2 12/4/21 Write a program to perform addition of two
complex numbers using constructor
overloading.
3 19/4/21 Write a program to find the greater of two given
numbers in two different classes using friend
function.
4 17/5/21 Write a program to implement a class string
which uses operator overloading to perform
operations on strings
5 24/5/21 Write a program to define the function template
for calculating the square of given numbers with
different data types.
6 31/5/21 Write a program to demonstrate the use of
special functions, constructor and destructor in
the class template. The program is used to find
the bigger of two entered numbers.
7 7/6/21 Write a program to perform the deletion of
white spaces such as horizontal tab, vertical tab,
space, line feed, new line and carriage return
from a text file and store the contents of the file
without the white spaces on another file.
8 14/6/21 Write a program to read the class object of
student info such as name , age ,sex ,height and
weight from the keyboard and to store them on a
specified file using read() and write() functions.
Again the same file is opened for reading and
displaying the contents of the file on the screen.
9 CBS1:- You are given two unmarked jugs with
capacities x and y liters. Determine the moves to
obtain exactly n liters of water in any of the two
jugs or both by the end
10 CBS2:- WAP to make Tic Tac Toe game.
Content Beyond Syllabus 1
Aim:- You are given two unmarked jugs with capacities x and y liters. Determine
the moves to obtain exactly n liters of water in any of the two jugs or both by the
end.
Given that:
1. There is infinite supply of water.
2. Both the jugs are empty at the beginning.
Operations allowed:
1. Empty /fill a jug completely with water.
2. Pour water from one jug to another until one of the jugs is either empty or full.
Source Code:-
#include<bits/stdc++.h>
using namespace std;
int x;
int y;
void show(int a, int b);
int min(int w, int z)
{
if (w < z)
return w;
else
return z;
}
void show(int a, int b)
{
cout << setw(12) << a << setw(12) << b<<endl;
}
void s(int n)
{
int xq = 0, yq = 0;
int t;
cout << setw(15) <<"FIRST JUG"<< setw(15) <<"SECOND JUG"<<endl;
while (xq != n && yq!=n )
{
if (xq == 0)
{
xq = x;
show(xq, yq);
}
else if (yq == y)
{
yq = 0;
show(xq, yq);
}
else
{
t = min(y - yq, xq);
yq= yq + t;
xq = xq - t;
show(xq, yq);
}
}
}
int main()
{
int n;
cout << "Enter the liters of water required out of the two jugs: ";
cin >> n;
cout << "Enter the capacity of the first jug: ";
cin >> x;
cout << "Enter the capacity of the second jug: ";
cin >> y;
if(n<x || n<y)
{ if(n%(__gcd(x,y))==0)
s(n);
else
cout<<"This is not possible....\n";
}
else
cout<<"This is not possible....\n";
}
Output:-
Content Beyond Syllabus 2
Aim:- WAP to make Tic Tac Toe game.
Source Code:-
#include <iostream>
using namespace std;