C++ program to add two complex numbers using class


Asked by admin @ in Computer Science viewed by 401 People


Write a c++ program to perform addition of two complex numbers using classes​

Answered by admin @



Answer:

Explanation:

#include <iostream>

using namespace std;


class complex

{

  public :

     int real, img;

};


int main()

{

  complex a, b, c;


  cout << "Enter a and b where a + ib is the first complex number.";

  cout << "\na = ";

  cin >> a.real;

  cout << "b = ";

  cin >> a.img;

  cout << "Enter c and d where c + id is the second complex number.";

  cout << "\nc = ";

  cin >> b.real;

  cout << "d = ";

  cin >> b.img;

   

  c.real = a.real + b.real;

  c.img = a.img + b.img;


  if (c.img >= 0)

     cout << "Sum of two complex numbers = " << c.real << " + " << c.img << "i";

  else

     cout << "Sum of two complex numbers = " << c.real << " " << c.img << "i";


  return 0;

}


Similar Questions

Program to find sum of two numbers in c++

Asked by admin @ in Computer Science viewed by 350 persons

Write a program in C++ to display the sum of two numbers 20 and 30.

C program to print number in words using switch case

Asked by admin @ in Computer Science viewed by 358 persons

C program to display the number in words using switch case where a sample input and output is given

C++ program to perform arithmetic operations using objects and classes

Asked by admin @ in General viewed by 416 persons

How do you write a C++ program to find the arithmetic operations on complex numbers using operator overloading using the C++ language?

A 4 digit number uses only two different digits

Asked by maham237 @ in Mathematics viewed by 311 persons

A 3-digit number uses only two different digits.

If alpha and beta are two different complex numbers

Asked by admin @ in Math viewed by 410 persons

Question 17 If α and β are different complex numbers with | β |= 1, then find | (β-α)/(1- αβ) |. Class X1 - Maths -Complex Numbers and Quadratic Equations …

C program to count number of words in a file

Asked by admin @ in Computers and Technology viewed by 346 persons

Write a c program to count the total number of commented characters and words in a c file taking both types of c file comments (single line and block) into …

Name two chemicals used to disinfect water class 7

Asked by admin @ in Environmental Sciences viewed by 413 persons

Name two chemicals used to disinfect water. NCERT Solutions for Class 7th Science Chapter 18 Wastewater Story Page 228 Exercise Question 7

Write a program to swap two numbers in python

Asked by admin @ in Computer Science viewed by 344 persons

Write a program is python to swap two numbers.

C++ program to calculate area of rectangle using constructor

Asked by admin @ in Computer Science viewed by 346 persons

C++ program to calculate area of traingle circle and rectangle using constructor overloading

Use the number line and add the following integers

Asked by admin @ in Math viewed by 364 persons

Add the following integers using number line. (i) 7+(-6)(ii) (-8) + (-2)(iii) (-6) + (-5) + (+2)(iv) (-8) + (-9)+(+17)(v) (-3) + (-8) + (-5) (vi) …

Sum and difference of two numbers in c hackerrank solution

Asked by admin @ in Math viewed by 378 persons

Sum and difference of two numbers hackerrank solution

The hyphen in "two-thirds" is used because:

Asked by maham237 @ in English viewed by 499 persons

The hyphen in "two-thirds" is used because A. two modifies three B. two is a prefix C. two thirds is a fraction D. two thirds is a number

C programing

Asked by pranav94 @ in Engineering viewed by 469 persons

Do two whole numbers always have a least common multiple

Asked by admin @ in Mathematics viewed by 368 persons

In your own words, what is the least common multiple of two whole numbers? How can you find it?

Describe two tools that doctors use to detect genetic disorders

Asked by admin @ in Biology viewed by 327 persons

What are two tools that doctors and genetic councilors use to predict genetic disorders?

Most viewed questions in Computer Science


A programmer mistakenly writes gor instead of for

Asked by admin @ in Computer Science viewed by 19016 persons


Domestic data entry operator ncert book class 9 solutions

Asked by admin @ in Computer Science viewed by 15799 persons


Information technology code 402 class 9 solutions chapter 1

Asked by admin @ in Computer Science viewed by 10964 persons



Ncert solutions for class 8 computer chapter 1 computer system

Asked by admin @ in Computer Science viewed by 10397 persons


A scrum team works on a 4 weeks sprint

Asked by admin @ in Computer Science viewed by 8719 persons


Which of the following occupies more memory in c

Asked by admin @ in Computer Science viewed by 8128 persons



A database of motor vehicles has the base entity

Asked by admin @ in Computer Science viewed by 7838 persons


The network architecture can be termed as a mcq

Asked by admin @ in Computer Science viewed by 6482 persons


Cat5 and cat6 cabling refer to which reference model layer

Asked by admin @ in Computer Science viewed by 5786 persons



Class 7 computer chapter 3 questions and answers

Asked by admin @ in Computer Science viewed by 5684 persons


Choose the correct options about usability and user experience

Asked by admin @ in Computer Science viewed by 5472 persons


Which advocates daily team meetings for coordination and integration

Asked by admin @ in Computer Science viewed by 4978 persons



Which three security features match the database security level

Asked by admin @ in Computer Science viewed by 4969 persons


Which of the dbms package is not available

Asked by admin @ in Computer Science viewed by 4680 persons


________ aid a business grow and attain its objectives

Asked by admin @ in Computer Science viewed by 4485 persons