Showing posts with label programs. Show all posts
Showing posts with label programs. Show all posts

Wednesday, 26 June 2013

String manipulation functions-very worth

                       string manipulation functions


#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main ()
{
 string firstWord, secondWord, thirdWord, fourthWord, fifthWord;

 cout << "Enter a five-word phrase." << endl;
 cin >> firstWord >> secondWord >> thirdWord >> fourthWord >> fifthWord;

 cout << "Your first word is: " << firstWord << endl
  << "Your second word is: " << secondWord << endl
  << "Your third word is: " << thirdWord << endl
  << "Your fourth word is: " << fourthWord << endl
  << "Your fifth word is: " <<fifthWord << endl;

 return 0;
}

Read more ...

complex number arithemetic operation using friend function

  Using friend function write a c++ program to add 2 complex

                                  numbers.

#include<iostream.h>
#include<conio.h>
class Complex{
private:
int real,imaginary;
public:
void getComplexNo()
{
cout<<"Input real and Imaginary part for Complex No";
cin>>real>>imaginary;
}
void printComplexNO()
{
cout<<"Complex NO-->"<<"+i"<<imaginary<<"\n";
}
friend Complex AddComplex(Complex C1,Complex c2);
};
Complex AddComplex(Complex C1,Complex C2)
{
Complex T;
T.real=C1.real+C2.real;
T.imaginary=C1.imaginary+C2.imaginary;
return T;
}
void main()
{
Complex A,B;
cot<<"Get First Complex number\n";
A.getComplexNo();
cout<<"Get Second Complex Number\n";
B.getComplexNo();
cout<<"Finding total of complex No's\n";
Complex Tot=AddComplex(A,B);
getch();
clrscr();
cout<<"First Complex No\n";
cout<<"------------------\n";
A.printComplexNo();
cout<<"Second Complex No\n";
cout<<"----------------\n";
B.printcomplexNo();
cout<<"Printing the Result\n";
cout<<"-------------------\n";
Tot.printComplexNo();
cot<<"-----------------\n";
getch();
}


Output:
First Complex No
-----------------
Complex No=2+i3
Second Complex No
----------------
Complex No=5+i2
Printing the Result
---------------------
Complex No=7 +i5
-------------------
Get First Complex number
Input real and Imaginary part for Complex No12
Input real and Imaginary part for Complex No12
4
Get Second Complex Number
Input real and Imaginary part for Complex No9
4
Finding Total of Complex no's
First Complex No
------------------
Complex no-->12+i4
Second Complex No
-----------------
complex No-->9+i4
Printing the Result
----------------- 
Complex No-->21+i8
------------------
Read more ...

Complex number arithmetic operation-using c++(inheritance)

         Program for add and multiply complex numbers implemented using hierarchical inheritance and also using        

                                   constructor


#include<iostream.h>
#include<conio.h>
 
class A     //Base class
{
    public:
    double a,b;
    void getnumber()     // Member function
    {
           cout<<"\n\n\tEnter Number for complex number:::\n";
           cin>>a>>b;
           cout<<"\n\tComplex number is :::\t";
           if(b>0)
           cout<<a<<"+"<<b<<"i";
           else
           cout<<a<<b<<"i";
    }
};
 
class B : public A    // Derived class 1
{
    public:
    B(double a,double b,double c,double d) //parameterized constructor
    {
 
        if((b+d)>0)
        cout<<"\n\nAddition of complex number :::\t"<<(a+c)<<"+"<<(b+d)<<"i";
        else
        cout<<"\n\nAddition od complex number :::\t"<<(a+c)<<(b+d)<<"i";
 
    }
 
};
 
class C : public A   // Derived class 2
{
    public:
    C(double a,double b,double c,double d) //parameterized constructor
    {
 
        if(((a*d)*(b*c))>0)
    cout<<"\n\nMultiplication of complex number :::\t"<<((a*c)+((b*d)*(-1)))<<"+"<<(a*d)+(b*c)<<"i";
        else
    cout<<"\n\nMultiplication of complex number :::\t"<<((a*c)+((b*d)*(-1)))<<(a*d)+(b*c)<<"i";
 
    }
};
 
int main()
{
    clrscr();
    A a1;     // a1 is object of class A
    a1.getnumber();  // It call member function ( getnumber() ) of class A
    A a2;     // a2 is another object of class A
    cout<<"\n\n---------------------------------------------------";
    a2.getnumber(); // It call member function ( getnumber() ) of class A
    cout<<"\n\n---------------------------------------------------";
    B(a1.a,a1.b,a2.a,a2.b);  // It call class B constructor
    cout<<"\n\n---------------------------------------------------";
    C(a1.a,a1.b,a2.a,a2.b);  // It call class C constructor
    cout<<"\n\n---------------------------------------------------";
 
    getch();
}
/*
If 10+20i is complex number then
a1.a=10  and  a1.b=20
and another complex number for add and multiply is 30+40i then
a2.a=30  and  a2.b=40
*/



Read more ...