Showing posts with label MCA. Show all posts
Showing posts with label MCA. Show all posts

Thursday, 24 August 2017

Write a program to generate a class named Person (with data numbers: Name, Age) and compare the age of two persons and show the eldest one, using this pointer.

Figure 9
Coding:

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class Person
{
   char Name[20];
   int Age;
public:
  void getData()
  {
    cout<<"Enter Person Name:";
    gets(Name);
    cout<<"Enter Person Age:";
    cin>>Age;
  }
  void putData()
  {
   cout<<"\n\nDetails About Eldest Person as follows:";
   cout<<"\nName="<<Name<<"\nAge="<<Age;
  }
  Person &Compare(Person &p1)
  {
   if(p1.Age>this->Age)
   return p1;
   return *this;
  }
};








void main()
{
  clrscr(); Person x,y,z;
  x.getData();
  y.getData();
  z=x.Compare(y);
  z.putData();
  getch();
}


Output:

Saturday, 22 July 2017

Write a program to calculate the area of different shapes (circle, square, triangle, rectangle) using function overloading.

Coding:

#include<iostream.h>
#include<math.h>

#include<conio.h>
#define PI 3.141
class Shape
{
 float a;
 public:
    void area(int r);
    void area(float s);
    void area(float l,float b);
    void area(float a,float b,float c);
};
void Shape::area(int r)
{
  a=float(PI*r*r);
  cout<<"\nArea of Circle is:"<<a;
}
void Shape::area(float s)
{
 a=pow(s,2);
 cout<<"\nArea of Square is:"<<a;
}
void Shape::area(float l,float b)
{
  a=l*b;
  cout<<"\nArea of Rectangle is:"<<a;
}
void Shape::area(float a,float b,float c)
{
  float s;
  s=(a+b+c)/2;
  a=sqrt(s*(s-a)*(s-b)*(s-c));
  cout<<"\nArea of Tringle is:"<<a;
}
void main()
{
  clrscr();
  float k=6.5;
  Shape s;
  s.area(5);
  s.area(k);
  s.area(5,6.5);
  s.area(10,15.5,6.8);
  getch();
}


Output:


Wednesday, 7 June 2017

Create two classes DM and DB which store the value of distances. DM stores distances in metres and centimeters and DB in feet and inches.

Write  a program that can read values for the class  objects and add one object DM with another object of DB. Use a Friend Function to carry out  the addition operation. The object that stores the results may be a DM object or DB object, depending on the units in which the





Coding:

#include<iostream.h>
#include<conio.h>
class DB;
class DM
{
 float meter,centi;
 public:
 void getdata()
 {
  cout<<"\nEnter the distance in(meter-centimeter):";
  cin>>meter>>centi;
 }
 void display()
 {
  cout<<"\nThe distance is:";
  cout<<meter<<" meters and "<<centi<<" centimeter";
 }
 friend void add(DM &,DB &);
};
class DB
{
 float inch,feet;
 public:
 void getdata()
 {
  cout<<"\nEnter the distance in(feet-inch):";
  cin>>feet>>inch;
 }
 void display()
 {
  cout<<"\nThe distance is:";
  cout<<feet<<" feet and "<<inch<<" inch";
 }
 friend void add(DM &,DB &);
};
void add(DM &a,DB &b)
{
 int ch;
 cout<<"\nPress 1 for meter-centi:";
 cout<<"\nPress 2 for feet-inch:";
 cout<<"\nEnter your choice:";
 cin>>ch;
 if(ch==1)
 {
  DM d;
  int c=(a.meter*100+a.centi+b.feet*30.48+b.inch*2.54);
  if(c>=100)
  {
   d.meter=c/100;
   d.centi=c%100;
  }
  else
  {
   d.meter=0;
   d.centi=c;
  }
  d.display();
 }
 else
 {
  DB d;
  int i=(a.meter*39.37+a.centi*.3937008+b.feet*12+b.inch);
  if(i>=12)
  {
   d.feet=i/12;
   d.inch=i%12;
  }
  else
  {
   d.feet=0;
   d.inch=i;
  }
  d.display();
 }
}
void main()
{
 clrscr();
 DM a;
 DB b;
 a.getdata();
 b.getdata();
 add(a,b);
 getch();

}


Output:


Friday, 19 May 2017

Write a Program to implement first Pattern Matching Algorithm to find the location of Given Pattern (P) in A Given Text (T).

Coding:

#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
  clrscr();
  int k,max,index,t_len,p_len;
  char a[50],p[10];
  cout<<"\nEnter any text:";
  gets(a);
  cout<<"\nEnter pattern:";
  gets(p);
  t_len=strlen(a);
  p_len=strlen(p);
  k=0;
  max=t_len-p_len+1;
  while(k<max)
  {
   for(int i=0;i<p_len;i++)
   {
    if(p[i]!=a[k+i])
    {
      index=0;
      k++;
      break;
    }
    else
    {
      index=k;
      cout<<"\nPattern is exist In given text and position is:"<<index;
      getch();
      exit(0);
    }
   }
  }
  if(index==0)
  cout<<"\nPattern does not Exist:";
  getch();
 }


Output:

Thursday, 18 May 2017

Define a class Age with data members: Years, Months & Days. Write a program to add three different values of Age by using Object as arguments concept & also return final result by using object.

Coding:

#include<iostream.h>
#include<conio.h>
class Age
{
  int YY,MM,DD;
  public:
       void getdata();
       void Add(Age,Age);
       void display();
};
void Age::getdata()
{
  cout<<"\nEnter Age of Person(DD.MM.YY):";
  cin>>DD>>MM>>YY;
}
void Add(Age a1,Age a2)
{
  Age a;
  a.MM=0;
  a.DD=a1.DD+a2.DD;
  if(a.DD>=30)
  {
   a.MM=a.DD/30;
   a.DD=a.DD%30;
  }
  a.MM+=a1.MM+a2.MM;
  if(a.MM>=12)
  {
   a.YY=a.MM/12;
   a.MM=a.MM%12;
  }
  a.YY+=a1.YY+a2.YY;
   a.display();
}
void Age::display()
{
  cout<<"\nAddition of Two date is:\n";
  cout<<"\t\t"<<"\nDD:"<<DD<<"\nMM:"<<MM<<"\nYY:"<<YY;
}
void main()
{
  clrscr();
  Age a,b,c;
  a.getdata();
  b.getdata();
  c=Add(a,b);
  getch();
}


Output:

Wednesday, 17 May 2017

Write a program to test your class.

Define a class named Student, create following members in it: Data Members: student_name, rollno, class (BCA/MCA), semester, sub1_marks,sub2_marks, sub3_marks,  total marks, average, percentage.                                   
          Member Functions: 
To enter the information of a student. 
To calculate his/her total, average, percentage.
To display the result.  

Write a program to test your class.


Coding:

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class student
{
  int roll,total_marks,sub1_marks,sub2_marks,sub3_marks;
  char stu_name[20],clss[3],sem[10];
  float avg,percentage;
  public:
     void getdata();
     void calculation();
     void display();
};
void student::getdata()
{
  cout<<"\nEnter Student Name:"<<" ";
  gets(stu_name);
  cout<<"\nEnter Student Roll No.:"<<" ";
  cin>>roll;
  cout<<"\nEnter class:"<<" ";
  gets(clss);
  cout<<"\nEnter semester:"<<" ";
  gets(sem);
  cout<<"\nEnter subject marks:"<<" ";
  cin>>sub1_marks>>sub2_marks>>sub3_marks;
}


void student::calculation()
{
  total_marks=sub1_marks+sub2_marks+sub3_marks;
  avg=total_marks/3;
  percentage=total_marks*100/300;
}
void student::display()
{
  cout<<"\nThe Result is:\n";
  cout<<"\nTotal Marks="<<total_marks;
  cout<<"\nAverage Marks="<<avg;
  cout<<"\nPercentage Marks="<<percentage;
}
void main()
{
 clrscr();
 student stu;
 stu.getdata();
 stu.calculation();
 stu.display();
 getch();

}

Output: