#include<iostream> #include<conio.h> using namespace std; // Class Declaration class prime { //Member Varibale Declaration int a,k,i; public: prime(int x) { a=x; } // Object Creation For Class 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.”; } }; //Main Function int main() { int a; cout<<“Enter the Number:”; cin>>a; // Object Creation For Class prime obj(a); // Call Member Functions obj.calculate(); obj.show(); getch(); return 0; }
Simple Class Example Program In C++
#include <iostream> #include<conio.h> using namespace std; // Class Declaration class person { //Access – Specifier public: //Varibale Declaration string name; int number; }; //Main Function int main() { // Object Creation For Class person obj; //Get Input Values For Object Varibales cout<<“Enter the Name :”; cin>>obj.name; cout<<“Enter the Number :”; cin>>obj.number; //Show the Outputcout … Read more
Simple Example Program For Copy Constructor In C++
#include<iostream> #include<conio.h> using namespace std; class Example { // Variable Declaration int a,b; public: //Constructor with Argument Example(int x,int y) { // Assign Values In Constructor a=x; b=y; cout<<”\nIm Constructor”; } void Display() { cout<<”\nValues :”<<a<<”\t”<<b; } }; int main() { Example Object(10,20); //Copy ConstructorExample Object2=Object; // Constructor invoked. Object.Display(); Object2.Display(); // Wait For Output … Read more
Simple Example Program For Constructor Overloading In C++
#include<iostream> #include<conio.h> using namespace std; class Example { // Variable Declaration int a,b; public: //Constructor wuithout Argument Example() { // Assign Values In Constructor a=50; b=100; cout<<”\nIm Constructor”; } //Constructor with Argument Example(int x,int y) { // Assign Values In Constructor a=x; b=y; cout<<”\nIm Constructor”; } void Display() {cout<<”\nValues :”<<a<<”\t”<<b; } }; int main() { … Read more
Simple Example Program For Parameterized Constructor In C++
#include<iostream> #include<conio.h> using namespace std; class Example { // Variable Declaration int a,b; public: //Constructor Example(int x,int y) { // Assign Values In Constructor a=x; b=y; cout<<“Im Constructor\n”; } void Display() { cout<<“Values :”<<a<<”\t”<<b; } }; int main() { Example Object(10,20); // Constructor invoked. Object.Display();// Wait For Output Screen getch(); return 0; } Output … Read more
Simple Example Program For Constructor In C++
#include<iostream> #include<conio.h> using namespace std; class Example { // Variable Declaration int a,b; public: //Constructor Example() { // Assign Values In Constructor a=10; b=20; cout<<“Im Constructor\n”; } void Display() { cout<<“Values :”<<a<<”\t”<<b; } }; int main() { Example Object; // Constructor invoked. Object.Display();// Wait For Output Screen getch(); return 0; } Output : … Read more
Do While Loop Example Program In C++
#include<iostream> #include<conio.h> using namespace std; int main() { // Variable Declaration int a; // Get Input Value cout<<“Enter the Number :”; cin>>a; int counter = 1; //Do while Loop Block do { cout<<“Execute Do While “<<counter<<” time”<<endl; counter++; }while (counter <= a); // Wait For Output Screen getch(); return 0; } Output : … Read more
While Loop Example Program In C++
#include<iostream> #include<conio.h> using namespace std; int main() { // Variable Declaration int a; // Get Input Value cout<<“Enter the Number :”; cin>>a; int counter = 1; //while Loop Block while (counter <= a) { cout<<“Execute While “<<counter<<” time”<<endl; counter++; } // Wait For Output Screen getch(); return 0; } Output : Enter the … Read more
how to write For Loop Example Program In C++
Hello friends, Welcome to your Techgsr.co blog. And today in this article we will learn about how to write For Loop Example Program In C++ .So let’s go to our topic #include<iostream> #include<conio.h> using namespace std; int main() { // Variable Declaration int a; // Get Input Value cout<<“Enter the Number :”; cin>>a; //for Loop Block … Read more
how to write if..else Statement Example Program In C++
Hello friends, Welcome to your Techgsr.co blog. And today in this article we will learn about how to write if..else Statement Example Program In C++.So let’s go to our topic #include<iostream> #include<conio.h> using namespace std; int main() { // Variable Declaration int a; // Get Input Value cout<<“Enter the Number :”; cin>>a; //If Condition Check if(a … Read more