C++ Programs

C++ class program to perform complex arithmetic using operator overloading

Write a program to perform complex arithmetic using operator overloading #include<iostream.h> #include<stdio.h> #include<conio.h> #include<process.h> class complex { int real; float image; public: void getdata() { cout<<"\n enter the real part of the complex"; cin>>real; cout<<"\n enter the imaginary part of the complex"; cin>>image; } void operator + (complex); void operator – (complex); };   void […]


C++ class program to perform rational number arithmetic

Write a program to perform rational number arithmetic. #include<stdio.h> #include<iostream.h> #include<conio.h> class rational { int numer; int denom; public: void getdata() { cout<<"\n enter the numerator part of the rational no."; cin>>numer; cout<<"\n enter the denominator part of the rational no."; cin>>denom; } void operator+(rational); void operator-(rational); void operator *(rational); void operator /(rational); }; void […]


C++ program using class to multiply by 10 to every member of a list

Write a program using class which reads a list of N number of integer type in an array. It modifies the list by multiplying 10 to every number of the list. The modified list is displayed. #include<iostream.h> #include<conio.h> class array { public: void readarray(); void multiply(); }; void array::readarray() { int a[10]; cout<<"Enter the elements […]


C++ program to calculate the factorial of a number using recursion.

Write a program to calculate the factorial of a number using recursion. #include<iostream.h> #include<conio.h> void main() { int n,fact; int rec(int); clrscr(); cout<<"Enter the number:->"; cin>>n; fact=rec(n); cout<<endl<<"Factorial Result are:: "<<fact<<endl; getch(); } rec(int x) { int f; if(x==1) return(x); else { f=x*rec(x-1); return(f); } }


C++ program to calculate a to the power b without using power function

Write a C++ program to calculate a to the power b without using power function. #include<iostream.h> #include<conio.h> void main() { int a,b,i,temp=1; clrscr(); cout<<"Enter number for operation"; cin>>a>>b; for(i=1;i<=b;i++) { temp=temp*a; } cout<<endl<<"Result are:: "<<temp; getch(); }


C++ program to multiply two numbers without using multiplication operator

Write a c++ program to multiply two numbers without using multiplication operator. #include<iostream.h> #include<conio.h> void main () { int a,b,i,temp=0; clrscr(); cout<<"Enter Two numbers for multiplication"; cin>>a>>b; for(i=1;i<=b;i++) { temp=temp+a; } cout<<endl<<"Result are:: "<<temp; getch(); }


C++ program to copy one file to anothere file

AIM A program to copy one file to another file and convert the lower case characters to upper case characters. ALGORITHM 1) Start the process 2) Create the input file and out put file. 3) Get the input file name to fname1. 4) Get the output file name to fname2. 5) Open the infile(fanme1) 6) […]


C++ class program to illestrate File operations

AIM Write a program to illustrate the write() member function which are usually used for transfer of data blocks to the file. ALGORITHM 1. Start the process 2. Invoke the class a. Create two inline member functions .ie, getdata() and dispdata() i. getdata() for input ii. dispdata() for display 3. Open the file in fstream […]


C++ program to implement Pure Virtual Functions

AIM A program to demonstrate how a pure virtual function is defined, declared and invoked from the object of derived class through the pointer of the base class. ALGORITHM 1. Start the process 2. Invoke the class with pointer 3. Assign ptrgetdata() a. Get the roll no and name of the student 5. Call the […]


C++ program to illestrate virtual functions

AIM A program to access the member of the derived class objects through an array of members. In this program, both the base class and the derived class member functions are preceded by the keyword ALGORITHM 1. Start the process 2. Invoke the class with pointer 3. Assign ptr[0]