Sunday, April 2, 2023

BCA and B.Sc Programs - Programming in C++ Lab - Bharathiar University - Practical Program 9-Write a C++ program using Function Overloading to read two matrices of different data types such as integers and floating point numbers. Find out the sum of the above two matrices separately and display the sum of these arrays individually

 

Bharathiar University

Programming in C++ Lab
C++ Program 9
Write a C++ program using Function Overloading to read two matrices of different data types such as integers and floating point numbers. Find out the sum of the above two matrices separately and display the sum of these arrays individually

In this page

  • C++ Source Code for MS Dos Turbo C++
  • C++ Source Code for Visual studio code
Source code for Turbo C++
#include<iostream.h>
#include<conio.h>

class Matrix
{
   public:
int a[3][3],b[3][3];
float x[3][3],y[3][3];
void readint();
void readfloat();
void sum(int a[3][3],int b[3][3]);
void sum(float x[3][3],float y[3][3]);
};
void Matrix::readint()
{
int i,j;
cout<<"\nEnter integer Matrix 1 : ";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin>>a[i][j];
}
}
cout<<"\nEnter integer Matrix 2 : ";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin>>b[i][j];
}
}
}
void Matrix::readfloat()
{
int i,j;
cout<<"\nEnter float Matrix 1 :";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin>>x[i][j];
}
}
cout<<"\n Enter float Matrix 2 :";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin>>y[i][j];
}
}
}
void Matrix::sum(int a[3][3],int b[3][3])
{
cout<<"\n Addition of Integer Matrices : \n";
for(int i=0; i<3; i++)
{
cout<<" ";
for(int j=0; j<3; j++)
{
cout<<a[i][j]+b[i][j]<<"\t";
}
cout<<"\n";
}
}
void Matrix::sum(float x[3][3],float y[3][3])
{
cout<<"\n Addition of Float Matrices : \n";
for(int i=0; i<3; i++)
{
cout<<" ";
for(int j=0; j<3; j++)
{
cout<<x[i][j]+y[i][j]<<"\t";
}
cout<<"\n";
}
}

int main()
{
Matrix m;
clrscr();
m.readint();
m.readfloat();
m.sum(m.a,m.b);
m.sum(m.x,m.y);
getch();
return 0;
}

OUTPUT:
Enter integer Matrix 1 : 1 2 3
1 2 3
1 2 3

Enter integer Matrix 2 : 1 1 1
1 1 1
1 1 1

Enter float Matrix 1 :2.3 2.1 3.2
2.3 5.4 4.3
2.3 4.3 5.4

 Enter float Matrix 2 :1.1 2.2 3.3
2.1 1.1 4.2
1.1 1.5 1.2

 Addition of Integer Matrices :
 2      3       4
 2      3       4
 2      3       4

 Addition of Float Matrices :
 3.4    4.3     6.5
 4.4    6.5     8.5
 3.4    5.8     6.6



Source code for Visual studio code
#include<iostream>
#include<conio.h>
using namespace std;
class Matrix
{
   public:
int a[3][3],b[3][3];
float x[3][3],y[3][3];
void readint();
void readfloat();
void sum(int a[3][3],int b[3][3]);
void sum(float x[3][3],float y[3][3]);
};
void Matrix::readint()
{
int i,j;
cout<<"\nEnter integer Matrix 1 : ";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin>>a[i][j];
}
}
cout<<"\nEnter integer Matrix 2 : ";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin>>b[i][j];
}
}
}
void Matrix::readfloat()
{
int i,j;
cout<<"\nEnter float Matrix 1 :";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin>>x[i][j];
}
}
cout<<"\n Enter float Matrix 2 :";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin>>y[i][j];
}
}
}
void Matrix::sum(int a[3][3],int b[3][3])
{
cout<<"\n Addition of Integer Matrices : \n";
for(int i=0; i<3; i++)
{
cout<<" ";
for(int j=0; j<3; j++)
{
cout<<a[i][j]+b[i][j]<<"\t";
}
cout<<"\n";
}
}
void Matrix::sum(float x[3][3],float y[3][3])
{
cout<<"\n Addition of Float Matrices : \n";
for(int i=0; i<3; i++)
{
cout<<" ";
for(int j=0; j<3; j++)
{
cout<<x[i][j]+y[i][j]<<"\t";
}
cout<<"\n";
}
}

int main()
{
Matrix m;
m.readint();
m.readfloat();
m.sum(m.a,m.b);
m.sum(m.x,m.y);
return 0;
}
Output
Enter integer Matrix 1 : 1 2 3
1 2 3
1 2 3

Enter integer Matrix 2 : 1 1 1
1 1 1
1 1 1

Enter float Matrix 1 :2.3 2.1 3.2
2.3 5.4 4.3
2.3 4.3 5.4

 Enter float Matrix 2 :1.1 2.2 3.3
2.1 1.1 4.2
1.1 1.5 1.2

 Addition of Integer Matrices :
 2      3       4
 2      3       4
 2      3       4

 Addition of Float Matrices :
 3.4    4.3     6.5
 4.4    6.5     8.5
 3.4    5.8     6.6

Friday, March 31, 2023

BCA and B.Sc Programs - Programming in C++ Lab - Bharathiar University - Practical Program 11-Write a C++ Program to create a File and to display the contents of that file with line numbers.

 

Bharathiar University

Programming in C++ Lab
C++ Program 11
Write a C++ Program to create a File and to display the contents of that file with line numbers.

In this page

  • C++ Source Code for MS Dos Turbo C++
  • C++ Source Code for Visual studio code
Source code for Turbo C++
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
    char fname[30], str[100];
    fstream fp;
    int i=0;
    clrscr();
    cout<<"Enter the Name of File: ";
    gets(fname);
    fp.open(fname, fstream::out);
    if(!fp)
    {
cout<<"\nError Occurred!";
    return 0;
    }
    cout<<"Enter the Data: ";
    gets(str);
    while(strlen(str)>0)
    {
fp<<str;
fp<<'\n';
gets(str);
    }
    fp.close();
    fp.open(fname, fstream::in);
    if(!fp)
    {
cout<<"\nError Occurred!";
return 0;
    }
    cout<<"\nContent of "<<fname<<":-\n";
    fp.getline(str, 1000);
    while(strlen(str)>0)
   {
      
     cout<<++i<<".";
     cout << str << endl;
     fp.getline(str, 1000);
   
   }
    fp.close();
    getch();
    return 0;
}

Output:


Output.txt file





Source code for Visual studio code

#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
    char fname[30], str[50],ch;
    fstream fp;
    int i=0;
    cout<<"Enter the Name of File: ";
    gets(fname);
    fp.open(fname, fstream::out);
    if(!fp)
    {
        cout<<"\nError Occurred!";
        return 0;
    }
    cout<<"Enter the Data: ";
    gets(str);
    while(strlen(str)>0)
    {
        fp<<str;
        fp<<"\n";
        gets(str);
    }
    fp.close();
    fp.open(fname, fstream::in);
    if(!fp)
    {
        cout<<"\nError Occurred!";
        return 0;
    }
     cout<<"\nContent of "<<fname<<":-\n";
    fp.getline(str, 1000);
    while(strlen(str)>0)
   {
     
     cout<<++i<<".";
     cout << str << endl;
     fp.getline(str, 1000);
    
   }
   
    fp.close();
    cout<<endl;
    return 0;
}

Output:

test.txt file

Monday, March 27, 2023

BCA and B.Sc Programs - Programming in C++ Lab - Bharathiar University - Practical Program 10- Write a C++ Program to check whether the given string is a palindrome or not using pointers

 

Bharathiar University

Programming in C++ Lab
C++ Program 10
Write a C++ Program to check whether the given string is a palindrome or not using pointers

In this page

  • C++ Source Code for MS Dos Turbo C++
Source code for Turbo C++

#include <iostream.h>
#include<string.h>
#include<conio.h>

int main() {
    char str[20], rev[20];
    int *n;
    clrscr();
    cout<<"Palindrome String Using Pointers"<<endl;
    cout << "Enter a string: ";
    cin>>str;
    strcpy(rev, str);
    strrev(rev);
    *n=strcmp(str, rev);
    if (*n==0)
      cout<<"String is Palindrome";
else
cout<<"String is not Palindrome";
getch();
 return 0;
}

OUTPUT





Wednesday, March 22, 2023

BCA and B.Sc Programs - Programming in C++ Lab - Bharathiar University - Practical Program 6- Write a C++ Program to create a class, which consists of EMPLOYEE Detail like E_Number, E_Name, Department, Basic_Salary and Grade. Write a member function to get and display them. Derive a class PAY from the above class and write a member function to calculate DA, HRA and PF depending on the grade.

Bharathiar University

Programming in C++ Lab
C++ Program 6
Write a C++ Program to create a class, which consists of EMPLOYEE Detail like E_Number, E_Name, Department, Basic_Salary and Grade. Write a member function to get and display them. Derive a class PAY from the above class and write a member function to calculate DA, HRA and PF depending on the grade.

In this page

  • C++ Source Code for MS Dos Turbo C++
  • C++ Source Code for Visual Studio Code
Source code for Turbo C++

 #include<iostream.h>

#include<conio.h>


class EMPLOYEE {

    public:

    int E_Number;

    char E_Name[50],dept[50];

    char grade;

    float basic_sal;

    void get()

    {

cout<<"Enter Employee details::"<<endl;

cout<<"Enter Employee Number: ";

cin>>E_Number;

cout<<"Enter Employee Name: ";

cin>>E_Name;

cout<<"Enter Employee department: ";

cin>>dept;

cout<<"Enter Employee Basic Salary: ";

cin>>basic_sal;

cout<<"Enter Employee Grade(A/B/C): ";

cin>>grade;

    }

    void display()

    {

cout<<"Employee Details"<<endl;

cout<<"****************"<<endl;

cout<<"Employee Number: "<<E_Number<<endl;

cout<<"Employee Name: "<<E_Name<<endl;

cout<<"Employee Department: "<<dept<<endl;

cout<<"Employee Basic salary: "<<basic_sal<<endl;

cout<<"Employee Grade: "<<grade<<endl;

    }

};


class PAY:public EMPLOYEE

{

float hra,da,pf,netsal;

    public:

    void calculate()

    {

if(grade=='A')

{

    da=0.5*basic_sal;

    hra=0.4*basic_sal;

    pf=0.1*(basic_sal+da);

    netsal=basic_sal+da+hra-pf;

}

else if(grade=='B')

{

     da=0.4*basic_sal;

    hra=0.3*basic_sal;

    pf=0.08*(basic_sal+da);

    netsal=basic_sal+da+hra-pf;

}

else

{

     da=0.3*basic_sal;

    hra=0.2*basic_sal;

    pf=0.05*(basic_sal+da);

    netsal=basic_sal+da+hra-pf;

}

    }

void disp_sal()

{

    cout<<"Dearness Allowance: "<<da<<endl;

    cout<<"House Rent Allowance: "<<hra<<endl;

    cout<<"Provident Fund: "<<pf<<endl;

    cout<<"Employee Net Salary: "<<netsal<<endl;

}

};


int main()

{

    PAY p;

    clrscr();

    p.get();

    p.calculate();

    p.display();

    p.disp_sal();

    getch();

return 0;

}


OUTPUT




Source code for Visual studio Code

#include<iostream>
#include<conio.h>
using namespace std;
class EMPLOYEE {
    public:
    int E_Number;
    char E_Name[50],dept[50];
    char grade;
    float basic_sal;
    void get()
    {
cout<<"Enter Employee details::"<<endl;
cout<<"Enter Employee Number: ";
cin>>E_Number;
cout<<"Enter Employee Name: ";
cin>>E_Name;
cout<<"Enter Employee department: ";
cin>>dept;
cout<<"Enter Employee Basic Salary: ";
cin>>basic_sal;
cout<<"Enter Employee Grade(A/B/C): ";
cin>>grade;
    }
    void display()
    {
cout<<"Employee Details"<<endl;
cout<<"****************"<<endl;
cout<<"Employee Number: "<<E_Number<<endl;
cout<<"Employee Name: "<<E_Name<<endl;
cout<<"Employee Department: "<<dept<<endl;
cout<<"Employee Basic salary: "<<basic_sal<<endl;
cout<<"Employee Grade: "<<grade<<endl;
    }
};

class PAY:public EMPLOYEE
{
float hra,da,pf,netsal;
    public:
    void calculate()
    {
if(grade=='A')
{
    da=0.5*basic_sal;
    hra=0.4*basic_sal;
    pf=0.1*(basic_sal+da);
    netsal=basic_sal+da+hra-pf;
}
else if(grade=='B')
{
     da=0.4*basic_sal;
    hra=0.3*basic_sal;
    pf=0.08*(basic_sal+da);
    netsal=basic_sal+da+hra-pf;
}
else
{
     da=0.3*basic_sal;
    hra=0.2*basic_sal;
    pf=0.05*(basic_sal+da);
    netsal=basic_sal+da+hra-pf;
}
    }
void disp_sal()
{
    cout<<"Dearness Allowance: "<<da<<endl;
    cout<<"House Rent Allowance: "<<hra<<endl;
    cout<<"Provident Fund: "<<pf<<endl;
    cout<<"Employee Net Salary: "<<netsal<<endl;
}
};

int main()
{
    PAY p;
    
    p.get();
    p.calculate();
    p.display();
    p.disp_sal();
    
return 0;
}

OUTPUT 

Enter Employee details::
Enter Employee Number: 101
Enter Employee Name: Raja
Enter Employee department: HR
Enter Employee Basic Salary: 15000
Enter Employee Grade(A/B/C): A
Employee Details
****************
Employee Number: 101
Employee Name: Raja
Employee Department: HR
Employee Basic salary: 15000
Employee Grade: A
Dearness Allowance: 7500
House Rent Allowance: 6000
Provident Fund: 2250
Employee Net Salary: 26250


Sunday, March 19, 2023

BCA and B.Sc Programs - Programming in C++ Lab - Bharathiar University - Practical Program 4- Write a C++ Program to create a class FLOAT that contains one float data member. Overload all the four arithmetic operators so that they operate on the object FLOAT

  

Bharathiar University

Programming in C++ Lab
C++ Program 4
Write a C++ Program to create a class FLOAT that contains one float data member. Overload all the four arithmetic operators so that they operate on the object FLOAT





In this page

  • C++ Source Code for Visual Studio Code
  • C++ Source Code for MS Dos Turbo C++

FOR VISUAL STUDIO CODE
#include <iostream>    
#include<stdio.h>
#include<iomanip>
using namespace std;    
class FLOAT    
{    
        public: 
      float f;    
           void operator+(FLOAT ob)
       {     
              float result=f+ob.f;
              cout<<"Addition: "<<result;
              cout<<endl;
             
       } 
        void operator-(FLOAT ob)
       {     
              float result=f-ob.f;
              cout<<"Subtraction: "<<result;
             cout<<endl;
       }
        void operator*(FLOAT ob)
       {     
              float result=f*ob.f;
              cout<<"Multiplication: "<<result;
             cout<<endl;
       }
        void operator/(FLOAT ob)
       {     
              float result=f/ob.f;
              cout<<"Division: "<<setprecision(3)<<result;
             cout<<endl;
       } 
          
};    
int main()    
{    
    FLOAT ob1,ob2;
    cout << " Enter 1st float value: ";
    cin>>ob1.f;
    cout << " Enter 2nd float value: ";
    cin>>ob2.f;
    

    ob1+ob2;
    ob1-ob2;
    ob1*ob2;
    ob1/ob2;           
    return 0;    

Output
Enter 1st float value: 1.5
 Enter 2nd float value: 1.3
Addition: 2.8
Subtraction: 0.2
Multiplication: 1.95
Division: 1.15


Turbo c++


#include <iostream.h>
#include<stdio.h>
#include<iomanip.h>
#include<conio.h>

class FLOAT
{
public:
      float f;
   void operator+(FLOAT ob)
       {
      float result=f+ob.f;
      cout<<"Addition: "<<result;
      cout<<endl;

       }
void operator-(FLOAT ob)
       {
      float result=f-ob.f;
      cout<<"Subtraction: "<<result;
     cout<<endl;
       }
void operator*(FLOAT ob)
       {
      float result=f*ob.f;
      cout<<"Multiplication: "<<result;
     cout<<endl;
       }
void operator/(FLOAT ob)
       {
      float result=f/ob.f;
      cout<<"Division: "<<setprecision(2)<<result;
     cout<<endl;
       }

};
int main()
{
    FLOAT ob1,ob2;
    clrscr();
    cout << " Enter 1st float value: ";
    cin>>ob1.f;
    cout << " Enter 2nd float value: ";
    cin>>ob2.f;
    ob1+ob2;
    ob1-ob2;
    ob1*ob2;
    ob1/ob2;
    getch();
    return 0;
}

OUTPUT




Program 12 BCA Madras University BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files

  BCA Object Oriented Programming using C++ Practical Madras University  Program 12  Implement a telephone directory using files SOURCE CODE...