0% found this document useful (0 votes)
16 views24 pages

Opps Lab Practical in C++

C++ oops lab which include class object
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)
16 views24 pages

Opps Lab Practical in C++

C++ oops lab which include class object
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/ 24

GREATER NOIDA INSTITUTE OF

TECHNOLOGY
Greater Noida (college code - 272)
Affiliated to Guru Gobind Singh
Indraprastha University, New Delhi

Object-Oriented Programming
Using C++
Practical file
Code-- CIC-257

Submitted by -
Name – Amrit Kumar
Course – Btech (Cse)
Enrollment no.- 35127202723
Year – 2nd year (3RD semester)
1 Write a program for multiplication
of two matrices using OOP.
INPUT
OUTPUT
2 Write a program to perform addition
of two complex numbers using
constructor overloading. The first
constructor which takes no argument
is used to create objects which are not
initialized, second which takes one
argument is used to initialize real and
imag parts to equal values and third
which takes two argument is used to
initialized real and imag to two
different values.
INPUT
OUTPUT
3 Write a program to find the greatest
of two given numbers in two different
classes using friend function.
INPUT
OUTPUT
4 Implement a class string containing
the following functions:
a. Overload + operator to carry out
the concatenation of strings.
b. Overload = operator to carry out
string copy.
c. Overload <= operator to carry out
the comparison of strings.
d. Function to display the length of a
string.
e. Function tolower( ) to convert upper
case letters to lower case.
f. Function toupper( ) to convert lower
case letters to upper case.

INPUT
OUTPUT
5 Create a class called LIST with two
pure virtual function store() and
retrieve().To store a value call store
and to retrieve call retrieve function.
Derive two classes stack and queue
from it and override store and
retrieve.
INPUT
OUTPUT
6 Write a program to define the
function template for calculating the
square of given numbers with
different data types.
INPUT

OUTPUT
7 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.
INPUT

OUTPUT
8 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.
INPUT
#include <iostream>
#include <fstream>
#include <string>
void removeWhitespace(const
std::string& inputFile, const
std::string& outputFile) {
std::ifstream inFile(inputFile);
std::ofstream outFile(outputFile);
if (!inFile) {
std::cerr << "Error opening input
file: " << inputFile << std::endl;
return;
}
if (!outFile) {
std::cerr << "Error opening output
file: " << outputFile << std::endl;
return;
}
char ch;
while (inFile.get(ch)) {
if (ch != ' ' && ch != '\t' && ch != '\v'
&& ch != '\n' && ch != '\r') {
outFile << ch;
}
}
inFile.close();
outFile.close();
std::cout << "Whitespace characters
removed and written to " << outputFile
<< std::endl;
}
int main() {
std::string inputFile, outputFile;
std::cout << "Enter the name of the
input file: ";
std::getline(std::cin, inputFile);
std::cout << "Enter the name of the
output file: ";
std::getline(std::cin, outputFile);
removeWhitespace(inputFile,
outputFile);
return 0;
}
9 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.
INPUT
Output
10 Write a program to raise an
exception if any attempt is made to
refer to an element whose index is
beyond the array size.
Input
Output

You might also like