Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Pratik Bakane C++

787 views

Published on

Pratik Bakane C++ programs...............This are programs desingedby sy diploma student from Governement Polytecnic Thane.....programsare very easy alongwith coding andscreen shot of the output

Published in: Engineering, Business, Technology
  • Be the first to comment

  • Be the first to like this

Pratik Bakane C++

  1. 1. /*Program for above Hierachy where Employee id Base class and Programmer and manager are child class. Make display function virtual which is common for all the three classes*/ /**************************Experiment 16****************************/ #include<iostream.h> #include<conio.h> class Employee { private: char name[20]; float sal; public: void accept() { cout<<"nnttEnter the Emplyee Name : "; cin>>name; cout<<"nnttEnter the salary : "; cin>>sal; Employee ManagerProgrammer
  2. 2. } virtual void display() //virtual function { cout<<"nnttEmployee name : "; cout<<"nnttEmployee salary : "; } }; class Programmer:public Employee { protected: char name[20]; float sal; int dept_no; public: void take() { cout<<"nnttEnter the name of Programmer: "; cin>>name; cout<<"nnttEnter the salary : "; cin>>sal; cout<<"nnttEnter the department Number : "; cin>>dept_no;
  3. 3. } void display() //virtual function { cout<<"nnttThe naem of Programmer is : "<<name; cout<<"nnttThe salary is : "<<sal; cout<<"nnttThe department number is :"<<dept_no; } }; class Manager:public Employee { protected: char name[20],post[20]; public: void getdata() { cout<<"nnttEnter the Name of the Manager : "; cin>>name; cout<<"nnttEnter the post of Manager : "; cin>>post; } void display() //virtual function {
  4. 4. cout<<"nnttThe Name is : "<<name; cout<<"nnttThe Post is : "<<post; } }; void main() { clrscr(); Programmer p; // e.accept(); // e.display(); p.take(); p.display(); Manager m; m.getdata(); m.display(); getch(); }
  5. 5. OUTPUT :   
  6. 6. /***************************Page Number 133****************************/ #include<iostream.h> #include<conio.h> class Base { public: virtual void display() { cout<<"nnttBase Class "; } }; class Derived:public Base { public: void display() { cout<<"nnttDerived Class"; } }; void main() { clrscr();
  7. 7. Base b; Derived d; b.display(); d.display(); getch(); } OUTPUT : 
  8. 8. /**********************Page Number 125*******************/ #include<iostream.h> #include<conio.h> class complex { int a,b,c; public: complex() {} void getvalue() { cout<<"Enter the two Numbers : "; cin>>a>>b; } void operator++() { a=++a; b=++b; } void operator--() { a=--a; b=--b; }
  9. 9. void display() { cout<<a<<"+t"<<b<<"i"<<endl; } }; void main() { clrscr(); complex obj; obj.getvalue(); obj++; cout<<"Increment Complex numbern"; obj.display(); obj--; cout<<"Decrement Complex Numbern"; obj.display(); getch(); }
  10. 10. OUTPUT:  
  11. 11. ******************Page Number 126******************* #include<iostream.h> #include<conio.h> class Sample { private: int p,q,r; public: void getdata(int p,int q,int r); void show() { cout<<"np="<<p; cout<<"nq="<<q; cout<<"nr="<<r; } void operator-(); }; void Sample::getdata(int m,int n,int z) { p=m;
  12. 12. q=n; r=z; } void Sample::operator-() { p=p*p*p; q=q*q*q; r=r*r*r; } void main() { clrscr(); Sample P; P.getdata(1,12,24); P.show(); -P; P.show(); getch(); }
  13. 13. OUTPUT   
  14. 14. /***************************Page Number 127******************/ #include<iostream.h> #include<conio.h> class SYIT { protected: int count; public: SYIT() { count=0; } void operator++() { count++; } void display() { cout<<endl<<"nntt"<<count; } }; void main()
  15. 15. { clrscr(); SYIT s; s++; s.display(); ++s; s.display(); getch(); }
  16. 16. OUTPUT:  
  17. 17. /*Program using function overloading to calculate addition of ten integer number and five floating numbers.*/ #include<iostream.h> #include<conio.h> int add(int,int,int,int,int,int,int,int,int,int); float add(float,float,float,float,float); int add(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j) { return (a+b+c+d+e+f+g+h+i+j); } float add(float k,float l,float m,float n,float o) { return (k+l+m+n+o); } void main() { clrscr(); int x; float y; x=add(1,2,3,4,5,6,7,8,9,10); y=add(1.0,1.1,1.2,1.3,1.4);
  18. 18. cout<<"nnttThe sum of ten Integers numbers : "<<x; cout<<"nnttThe sum of five floating numbers : "<<y; getch(); }
  19. 19. OUTPUT:  
  20. 20. /*Program to declare a class student having data members as roll_no and percentage. Using ‘this’ pointer invoke member functions to accept and display this data for one object of the class.*/ #include<iostream.h> #include<conio.h> #include<math.h> class student { private: int r_no,per; public: void accept() { cout<<"nnttEnter the Roll Number : "; cin>>r_no; cout<<"nnttEnter the Percentage : "; cin>>per; } void display() { cout<<"nnttRoll Number is : "; cout<<this->r_no;
  21. 21. cout<<"nnttPercentage is : "; cout<<this->per; } }; void main() { clrscr(); student s1; s1.accept(); s1.display(); getch(); }
  22. 22. OUTPUT   
  23. 23. /************************Page Number 61***************/ #include<iostream.h> #include<conio.h> #include<math.h> class example { int a,b; public: example(int x,int y) { a=x; b=y; cout<<"nnttI am Constructor "; } void display() { cout<<"nnttValues : "<<a<<"t"<<b; } }; void main() {
  24. 24. clrscr(); example obj(10,20); obj.display(); getch(); } OUTPUT:  
  25. 25. /*Program to define a class salary which will contain member variable basic,ta,da,hra. Devlop a program using constructor with default value(s) for da and hra and calculate the salary of employee*/ #include<iostream.h> #include<conio.h> #include<math.h> class salary { float basic,ta,da,hra; public: salary(float b,float t,float d=1000,float h=1000) { basic=b; ta=t; da=d; hra=h; } void display_sal() { float gross_sal; gross_sal=(basic+ta+da+hra); cout<<"nnttGross Salary : "<<gross_sal;
  26. 26. } }; void main() { clrscr(); salary s(1000,1000); s.display_sal(); getch(); } OUTPUT:  

×