Posts

Operator overloading in C++ (Cout and Cin)

Image
#include<iostream.h> #include<conio.h> class distance { int feet,inches; public: distance() { } distance(int f,int i) { feet=f; inches=i; } friend ostream &operator<<(ostream &output,const distance &d) { output<<"F: "<<d.feet<<" I: "<<d.inches; return output; } friend istream &operator>>(istream &input, distance &d) { input>>d.feet>>d.inches; return input; } }; void main() { distance d1(11,10),d2(5,11),d3; clrscr(); cout<<"Enter the value of object: "<<endl; cin>>d3; cout<<"First Distance: "<<d1<<endl; cout<<"Second Distance: "<<d2<<endl; cout<<"Third Distance: "<<d3; getch(); }

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(); }

C++ Program to subract 2 no.s

Image
#include<iostream> using namespace std; int main() {     int s1, s2 ,s;     cout <<"Subtraction Program \n";     cout <<"Enter value:- ";     cin >>s1;      cout <<"Enter value:- ";     cin >>s2;     s=s1-s2;     cout <<s;     return 0; }

C++ Program to add 2 integers

Image
#include<iostream> using namespace std; int main() {     int f1, f2, s;     cout <<"Enter a value:- ";     cin >> f1;     cout <<"Enter a value:- ";     cin >> f2;     s=f1+f2;     cout <<s;     return 0; }

C++ Program to print hello linux

Image
#include<iostream> using namespace std; int main() {     cout<<"hello linux";     return 0; }

File input/output program to access no. of character, spaces, tabs...

Image
By using File Input/Output , we gonna count:- No. of characters No. of blanks No. of tabs No. of lines So, here the code for the above. /*Pre Processors */ #include<stdio.h> #include<conio.h> int main()     /*Main function*/ {     FILE *fp;     char ch;     clrscr();     int nol=0, not=0, nob, noc=0;     fp=fopen("EMPLOYEE.TXT","r");     while(1)     {         ch=fgetc(fp);         if(ch==EOF)         break;         noc++;         if(ch==' ')         nob++;         if(ch=='\n')         nol++;         if(ch=='\t')         not++;...