Posts

Showing posts from September, 2019

string

#include<iostream> using namespace std; int main() {     int i;     char temp[50],str1[10],str2[10],str[20];     int j,l=0,l1=0;     cout<<"enter the FIRST string:=";     cin>>str1;     cout<<"enter the second string:=";     cin>>str2;     cout<<"\ncopy string is:";     for(i=0;str1[i]!='\0';i++)     {         str[i]=str1[i];             }     str[i]='\0';     cout<<str;         //compare two string     i=0;     while(str1[i]==str2[i] && str1[i]!='\0')     {         i++;         if(str1[i]<str2[i])         {   ...

complex number addition and multiplication using friend function

Image
#include<iostream> using namespace std; class Complex { int real,img; public: friend istream &operator>>(istream &in , Complex &c) { in>>c.real>>c.img; return in; } friend ostream &operator<<(ostream &out,Complex &c) { out<<c.real<<"+"<<c.img<<"i"; } Complex operator+(Complex c2); Complex operator*(Complex c2); }; Complex Complex::operator+(Complex c2) { Complex temp; temp.real=real+c2.real; temp.img=img+c2.img; return (temp); } Complex Complex::operator*(Complex c2) { Complex temp; temp.real=real*c2.real; temp.img=img*c2.img; return (temp); } int main() { Complex c1,c2,c3,c4; cout<<"enter the real and imag :="; cin>>c1; cout<<"enter the real and imag :="; cin>>c2; cout<<"\n display the first complex:="; cout<<c1; cout<<"\n di...

c++ calculator object oriented programming

Image
#include<iostream> using namespace std; class calculator { float num1,num2; char operator1; public: void getdata(); void display(); }; void calculator::getdata() { cout<<"enter the first number:="; cin>>num1; cout<<"enter the operator(+,-,*,/):="; cin>>operator1; cout<<"enter the second number:="; cin>>num2; } void calculator::display() { switch(operator1) { case'+': cout<<"addition is:="<<num1+num2<<"\n"; break; case'-': cout<<"subtraction is:="<<num1-num2<<"\n"; break; case'*': cout<<"multiplication is:="<<num1*num2<<"\n"; break; case'/': cout<<"division is:="<<num1/num2<<"\n"; break; default: cout<<"incorrect operator:"...