0% found this document useful (0 votes)
24 views36 pages

OOPS File

The document contains an index listing 9 experiments completed by a student between April and June 2021 related to OOP concepts like matrices multiplication, complex number addition, function templates, and file handling. It also includes source code for two additional problems - determining water amounts in jugs of different capacities and implementing a Tic Tac Toe game.

Uploaded by

karanmandrai8643
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views36 pages

OOPS File

The document contains an index listing 9 experiments completed by a student between April and June 2021 related to OOP concepts like matrices multiplication, complex number addition, function templates, and file handling. It also includes source code for two additional problems - determining water amounts in jugs of different capacities and implementing a Tic Tac Toe game.

Uploaded by

karanmandrai8643
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

OOPS

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;

char square[10] = {'o','1','2','3','4','5','6','7','8','9'};


int checkwin();
void board();
int main()
{
int player = 1,i,choice;
char mark;
do
{
board();
player=(player%2)?1:2;
cout << "Player " << player << ", enter a number: ";
cin >> choice;
mark=(player == 1) ? 'X' : 'O';
if (choice == 1 && square[1] == '1')
square[1] = mark;
else if (choice == 2 && square[2] == '2')
square[2] = mark;
else if (choice == 3 && square[3] == '3')
square[3] = mark;
else if (choice == 4 && square[4] == '4')
square[4] = mark;
else if (choice == 5 && square[5] == '5')
square[5] = mark;
else if (choice == 6 && square[6] == '6')
square[6] = mark;
else if (choice == 7 && square[7] == '7')
square[7] = mark;
else if (choice == 8 && square[8] == '8')
square[8] = mark;
else if (choice == 9 && square[9] == '9')
square[9] = mark;
else
{
cout<<"Invalid move ";
player--;
cin.ignore();
cin.get();
}
i=checkwin();
player++;
}while(i==-1);
board();
if(i==1)
cout<<"==>\aPlayer "<<--player<<" win ";
else
cout<<"==>\aGame draw";
cin.ignore();
cin.get();
return 0;
}
/*********************************************
FUNCTION TO RETURN GAME STATUS
1 FOR GAME IS OVER WITH RESULT
-1 FOR GAME IS IN PROGRESS
O GAME IS OVER AND NO RESULT
**********************************************/
int checkwin()
{
if (square[1] == square[2] && square[2] == square[3])
return 1;
else if (square[4] == square[5] && square[5] == square[6])
return 1;
else if (square[7] == square[8] && square[8] == square[9])
return 1;
else if (square[1] == square[4] && square[4] == square[7])
return 1;
else if (square[2] == square[5] && square[5] == square[8])
return 1;
else if (square[3] == square[6] && square[6] == square[9])
return 1;
else if (square[1] == square[5] && square[5] == square[9])
return 1;
else if (square[3] == square[5] && square[5] == square[7])
return 1;
else if (square[1] != '1' && square[2] != '2' && square[3] != '3'
&& square[4] != '4' && square[5] != '5' && square[6] != '6'
&& square[7] != '7' && square[8] != '8' && square[9] != '9')
return 0;
else
return -1;
}
/******************************************************************
*
FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS
MARK
******************************************************************
**/
void board()
{
system("cls");
cout << "\n\n\tTic Tac Toe\n\n";
cout << "Player 1 (X) - Player 2 (O)" << endl << endl;
cout << endl;
cout << " | | " << endl;
cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl;
cout << " | | " << endl << endl;
}
Output:-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy