You are on page 1of 12

Mini project

Object oriented programming


Compilation of programs-
Code-
#include <iostream>

using namespace std;

template<class Test> Test FindLarge(Test num1,Test num2, Test num3)

if(num1>=num2)

if(num1>=num3)

return num1;

else

return num3;

else

if(num2 >= num3)

return num2;

else

return num3;

class Matrix2;

class Matrix1

public:

int m1[20][20];
void setvalues(int r, int c)

int i,j;

for(i=0;i<r;i++)

for(j=0;j<c;j++)

cin>>m1[i][j];

void display(int r, int c)

int i,j;

cout<<"\n First Matrix\n";

for(i=0;i<r;i++)

for(j=0;j<c;j++)

cout<<" "<<m1[i][j]<<" ";

cout<<"\n";

friend void sum(Matrix1,Matrix2,int,int);

};

class Matrix2

public:

int m2[20][20];
void setvalues(int r, int c)

int i,j;

for(i=0;i<r;i++)

for(j=0;j<c;j++)

cin>>m2[i][j];

void display(int r,int c)

int i,j ;

cout<<"\n Second Matrix\n";

for(i=0;i<r;i++)

for(j=0;j<c;j++)

cout<<" "<<m2[i][j]<<" ";

cout<<"\n";

friend void sum(Matrix1,Matrix2,int,int);

};

void sum(Matrix1 x, Matrix2 y,int r,int c)

int matsum[20][20],i,j;

for(i=0;i<r;i++)
{

for(j=0;j<c;j++)

matsum[i][j]=x.m1[i][j]+y.m2[i][j];

cout<<"\n\nThe Sum of two matrices...."<<"\n";

for(i=0;i<r;i++)

for(j=0;j<c;j++)

cout<<" "<<matsum[i][j]<<" ";

cout<<"\n";

class Employee

int id;

char name[30];

int age;

char gender ;

int salary;

char address [50];

public:

// Declaration of function

void getdata();

// Declaration of function
void putdata();

};

// Defining the function outside

// the class

void Employee::getdata()

cout << "Enter Id : ";

cin >> id;

cout << "Enter Name : ";

cin >> name;

cout<<"enter age :";

cin>> age;

cout<<"enter gender :";

cin>> gender;

cout<<"enter salary :" ;

cin>>salary;

cout<<"enter address :";

cin>>address;

// Defining the function outside

// the class

void Employee::putdata()

cout << id << " ";

cout << name << " ";

cout<<age<<" ";

cout<<gender<<" ";

cout<<salary <<" ";


cout<<address <<" ";

cout << endl;

class Student

string name,sapid,cls;

int roll;

void getData()

cout<<"Enter the name of the student: ";

cin>>name;

cout<<"Enter the SAPID of the student: ";

cin>>sapid;

cout<<"Enter the roll number of the student: ";

cin>>roll;

cout<<"Enter the class of the student: ";

cin>>cls;

public:

void displayData()

getData();

cout<<"\n\t\t\t\t\tDisplaying the information\n"<<endl;

cout<<"\nName of the student is: "<<name<<endl;

cout<<"\nSAPID of the student is: "<<sapid<<endl;

cout<<"\nRoll number of the student is: "<<roll<<endl;

cout<<"\nClass of the student is: "<<cls<<endl;

};
int main()

int number;

cout<<"1. Program to implement class template to find the greatest of 3 numbers."<<endl;

cout<<"2. Program to copy the contents of one file into another file. ."<<endl;

cout<<"3. Program to create a friend function for adding the two matrices from two different classes
and display its sum ."<<endl;

cout<<"4. Program to to demonstrate the concept of array of an object "<<endl;

cout<<"5. Program to demonstrate concept of classes object ."<<endl;

cout<<"Enter program number(1-5): ";

cin>>number;

switch(number)

case 1:

int num1, num2, num3, large;

cout << "\n Enter Three Numbers";

cout<<"\n --------------------------";

cout<<"\n First Number : ";

cin>>num1;

cout<<"\n Second Number : ";

cin>>num2;

cout<<"\n Third Number : ";

cin>>num3;

large=FindLarge(num1,num2,num3);
cout<<"\n Largest Number is : "<<large;

break;

case 2:

char ch, sourceFile[20], targetFile[20];

FILE *fs, *ft;

cout<<"Enter the Name of Source File: ";

cin>>sourceFile;

fs = fopen(sourceFile, "r");

if(fs == NULL)

cout<<"\nError Occurred!";

return 0;

cout<<"\nEnter the Name of Target File: ";

cin>>targetFile;

ft = fopen(targetFile, "w");

if(ft == NULL)

cout<<"\nError Occurred!";

return 0;

ch = fgetc(fs);

while(ch != EOF)

fputc(ch, ft);

ch = fgetc(fs);

cout<<"\nFile copied successfully.";

fclose(fs);

fclose(ft);

cout<<endl;
break;

case 3:

Matrix1 x;

Matrix2 y;

int r,c;

cout<<"Enter the rows and Columns for each matrix\n";

cin>>r>>c;

cout<<"Enter the Elements of the First Matrix,,,\n";

x.setvalues(r,c);

cout<<"Enter the Elements of the Second Matrix,,,\n";

y.setvalues(r,c);

system("cls");

x.display(r,c);

y.display(r,c);

sum(x,y,r,c);

break;

case 4:

Employee emp[10];

int n, i;

cout << "Enter Number of Employees - ";

cin >> n;

// Accessing the function

for(i = 0; i < n; i++)

emp[i].getdata();

cout << "Employee Data - " << endl;

// Accessing the function

for(i = 0; i < n; i++)


emp[i].putdata();

break;

case 5:

Student S[10];

cout<<"\t\t\t\t\tPROGRAM TO DISPLAY STUDENT INFORMATION"<<endl;

cout<<"\n\nHow namy records do you wish to enter? \n= ";cin>>n;

for(i=0;i<n;i++)

cout<<"\n\t\t\t\t\tReading the information of student "<<i+1<<endl;

S[i].displayData();

break;

return 0;

Output-
Name- vidisha sharma
Roll no- A066.
Sap id -45207210066

You might also like