Anna University Regulation 2013 Information Technology (IT) IT6311 PDS2 LAB Manual for all experiments is provided below. Download link for IT 3rd SEM IT6311 Programming and Data Structures II Laboratory Manual is listed down for students to make perfect utilization and score maximum marks with our study materials.

Anna University Regulation 2013 Information Technology (IT) 3rd SEM IT6311 PDS2 LAB-Programming and Data Structures II Laboratory Manual

CONSTRUCTOR

AIM:
To implement a C++ program to calculate prime number using Constructor.
ALGORITHM:
Step 1: Include the header files
Step 2: Declare the class as Prime with data members and Member functions.
Step 3: Consider the argument constructor Prime () with integer Argument.
Step 4: To cal the function calculate () and do the following steps.
Step 5: For i=2 to a/2 do
Step 6: Check if a%i==0 then set k=0 and break.
Step 7: Else set k value as 1.
Step 8: Increment the value i as 1.
Step 9: Check whether the k value is 1 or 0.
Step 10: If it is 1 then display the value is a prime number.
Step 11: Else display the value is not prime.
PROGRAM:
#include<iostream.h>
#include<conio.h>
using namespace std;
class prime {
int a,k,i;
public:
prime(int x)
{
a=x;
}
void calculate()
{
k=1;
{
for(i=2;i<=a/2;i++)
if(a%i==0)
{
k=0;
break;
}
else
{
k=1;
}
}
}
void show()
{
if(k==1)
cout<<“\n”<<a<<” is Prime Number.”;
else
cout<<“\n”<<a<<” is Not Prime Numbers.”;
}
};
int main()
{
int a;
cout<<“Enter the Number:”;
cin>>a; prime obj(a);
obj.calculate();
obj.show();
getch();
return 0;
}

SAMPLE OUTPUT:
Enter the Number: 10
10 is not a Prime Number.
Enter the Number:7
7 is a Prime Number.
RESULT:
Thus a C++ program to check the prime number using constructor is implemented successfully.