Posts

C++ Program to Add Complex Numbers by Passing Structure to a Function

Add Complex Numbers by Passing Structure to a Function This program takes two complex numbers as structures and adds them with the use of functions. Example: Source Code to Add Two Complex Numbers // Complex numbers are entered by the user #include <iostream> using namespace std ; typedef struct complex { float real ; float imag ; } complexNumber ; complexNumber addComplexNumbers ( complex , complex ); int main () { complexNumber n1 , n2 , temporaryNumber ; char signOfImag ; cout << "For 1st complex number," << endl ; cout << "Enter real and imaginary parts respectively:" << endl ; cin >> n1 . real >> n1 . imag ; cout << endl << "For 2nd complex number," << endl ; cout << "Enter real and imaginary parts respectively:" << endl ; cin >> n2 . real >> n2 . imag ; ...

Structures and Functions in c++

Structures and Functions in c++ n this article, you'll find relevant examples to pass structures as an argument to a function, and use them in your program. Structure  variables can be passed to a  function  and returned in a similar way as normal arguments. Passing structure to function in C++ A structure variable can be passed to a function in similar way as normal argument. Consider this example: Example 1: C++ Structure and Function #include <iostream> using namespace std ; struct Person { char name [ 50 ]; int age ; float salary ; }; void displayData ( Person ); // Function declaration int main () { Person p ; cout << "Enter Full name: " ; cin . get ( p . name , 50 ); cout << "Enter age: " ; cin >> p . age ; cout << "Enter salary: " ; cin >> p . salary ; // Function call with structure variable as an argument...