Posts

Showing posts from August, 2018

Factorial Program using classes C++

Image
Classes are basically created to compress a big program into a small program that is meaningful too. Here , we gonna work on a factorial program using classes. #include<iostream.h> #include<conio.h> class factorial { int i,f,num; public: void read(); void fact(); void display(); }; void factorial::read() { cout<<"Enter an Integer to get Factorial:- "; cin>>num; } void factorial::fact() { f=1; for(i=1;i<=num;i++) { f=f*i; } } void factorial::display() { cout<<"Factorial of "<<num<<" :-"<<f; } void main() { factorial vk; clrscr(); vk.read(); vk.fact(); vk.display(); getch(); }

Addition of 2 Integers using classes

Image
Today i am going to introduce the uses classes and their implementation respectively. first of all classes are almost like structure of C but classes not as exactly same here a few difference that it is a set object that shares similar property. #include<iostream.h> #include<conio.h> class add { int a,b,c; public: void read() { cout<<"Enter 2 Integers:-"<<endl; cin>>a>>b; } void sum() { c=a+b; } void display() { cout<<"Sum of 2 Integer:- "<<c; } }; void main() { add x; clrscr(); x.read(); x.sum(); x.display(); getch(); }