C++ :: Multiplication Of Complex Numbers?
Apr 17, 2013I am trying to write a class that can multiply complex numbers but without overloading operators
View 1 RepliesI am trying to write a class that can multiply complex numbers but without overloading operators
View 1 RepliesBelow is a code that is used to calculate complex numbers (a+bi, where i = sqroot (-1)) through multiplication and addition.
However, on my output file, no Header is being printed; the only thing that is being printed is "8 + 7i + = "
"complex.h" is included at the end of the code.
Code:
// Trey Brumley// CMPS
// Dr. Tina Johnson
// March 1, 2013
// Program 2: Classes
// This program will demonstrate the use of classes by using a custom "complex-number" (a+bi) class.
[Code] ......
I have a program written to add 2 complex numbers. Everything is working, except when the sum gets written, it gives me a number that is way off.
#include <iostream>
#include <complex>
#include <fstream>
#include <cstdlib>
#include <math.h>
class complex {
public:
complex();
complex(double r, double i){
[Code] .....
And my output ends up being Enter a complex number (a+bi) :
1+2i
Enter a complex number (a+bi) :
2+3i
x 1+2i
y 2+3i
4.8784e-270+4.85593e-270i
1.What would regex pattern look like for addition of integers?
2.What would regex pattern look like for subtraction of complex numbers?
I created an algorithm that uses imaginary numbers. It is fine on Dev C++, and now I am trying to port to VS2008. I figured out most things, including how to declare complex numbers. However, I've been having an incredible hard time trying to figure how to use the " i " number! For example:
In Dev C++:
Code:
z_cmplx = cexp(I * f1/Fs * 2 * PI);
Where "I" is a macro from the library!
In VS2008:
Code:
z_cmplx = std::exp(I * f1/Fs * 2 * PI);
Although I DID include <complex> library just like I did before, the compiler gives me: error C2065: 'I' : undeclared identifier.
I have a tree structure that works likes this.
Each node (if its a 'normal' node) can have 2, 3 or 4 children. I know how to linearize a normal quadtree though it is not memory efficient in this case as the linearization only works for full trees. I'm okay with holes though.
But my tree is slightly odd in that it has non-normal nodes. For example, two leaves will point to a 'dead' node and that dead node has 3 children. Sometimes, 3 leaves will point to a dead node and that dead node will have 2 children. Sometimes, 4 leaves will point to a dead node and that dead node will have 4 children.
So normally, a node will only have one parent and multiple children or it'll just be a leaf. But there are dead nodes that can have 2, 3, or 4 parents and will subsequently have 3, 2 or 4 children respectively.
This is for point location within a Delaunay triangulation and operates off of the idea of volume spanning.
What I abstracted in my code is a 2-to-3, 3-to-2 and 4-to-4 flip. The idea is ,we take 2 tetrahedra and replace them with 3 good tetrahedra but they span the same volume which is good for point location.
As of now, the code that I have works fine. It triangulates tetrahedra and repairs them accordingly but for certain inserts, the search algorithm takes incredibly long and I'm trying to fix that.
I figured a linear structure would be a good attempt so how to linearize a tree that behaves almost polymorphically.
I have some complex declarations to simplify with typedef I have done a try
1. Code:
char (*x[10]) (int);
/* typedef char FUNC(int);
typedef FUNC *FUNC_PTR;
FUNC_PTR x[10]; */ Why we don't use * symbol in the last statement in front of FUNC_PTR?
2. Code:
int (*x(int))[5] I can't do this :/
3. Code:
float *(*x(void))(int);
/* typedef float *FUNC(int);
FUNC *x(void); */
I'm not sure if I was some weird syntax problem or the way Ive ordered things. But a conditional statement I have created is not performing the way I want it to.
else if ( !( xDif == -1 && yDif == 1 && prevXDif == 1 && prevYDif == 0 ) )
{
foundArr[lastX][lastY] = 1;
}
When debugging, the condition was activated with the values:
xDif = -1
yDif = 1
prevXDif = -1
prevYDif = 0
However, I want the condition not to follow through as I am using the 'NOT' or '!' operator to negative the entire statement. For some reason, the line of code within the else if is still running.
the only problem I have is where to add
want to play again? y
OK, I am thinking of a number. Try to guess it.
Your guess?
...
want to play again? no
Goodbye
Code :
#include <stdio.h>
#define TARGET 23
#define LOW 1
#define HIGH 100
#define TRUE 1
#define FALSE 0
#define GUESS 6
int process( int guess, int target );
[Code] ....
//complxCalc.cpp//
#include "complx.h"
using namespace std;
ifstream infile ("in.dat");
int main() {
int i = 0;
complx tempComplx;
double d = 4.5;
[Code] ....
//in.dat//
(4,4) (6,7) (2.5, 9.3) (3,8.4) (13, 26.5) (2.2, 3.4)
My plan is to make this a menu driven program, I have already got the program to give the answers but now I want it to give the user choices as well. The first step in this project is to add a menu to the program. The first menu the user sees should ask the user if the program will be taking input from a file or from the user directly via the keyboard. Regardless of option chosen, the user should then be prompted to specify whether a multiplication,subtraction or addition operation should be performed.
If the user originally chose the file input method then the program should proceed to display to the screen the results of those operations on each pair of data elements in the file and terminate. If the user chose to input via the keyboard then the user should be prompted to input the two numbers, perform the operation on those two numbers and display the results to the screen and ask the user which mathematical operation they would like to do next and continue in this manner until the user chooses to exit the program via a menu option. Fortunately the only file that needs to be edited are in.dat and complxcalc.cpp files.
1 create a struct called complex which reprensts a complex number . both the real and imaginary compoents should be represented as doubles . ( 1 marks) .
2 write down a function called magnitude which has one parameter ( a struc complex) and a return type of double . it should return the maginude of the given parameter . ( 3marks) .
3 write a function called find_largest which has two parameter (one of type struct complex const * and the other type int) and a return type of struc complex . the two parameter represent an array of complex numbers and number of elements in that array . the function should return elements from array which has largest magnitude . this fucntion must called the magnitude function . ( 5 marks)
4 write a main function . your main fucntion . Your main fucntion should repeately prompt the user for complex number , storing them in an array. you should continuing reading in complex number until the user enters in both componets , at this point you should stop . you should not make an assumptions how many complex number the user will enter , ( i.e use realloc) after reading in complex numbers from the user you should print out real and imaginary components of the complex number with the largest magnitude.
Code:
#include<stdio.h>
struct complex {
double real;
double imag;
[code]....
Write c/c++ code of overloading ^operator in complex number class.
If we have two objects of complex number class as fellows,complex obj3 =obj1 ^obj2 ;
Obj3 reak and imaginary pars will be ,
Obj3.real = (obj1.real)obj2.real
And
obj3.img = (obj1.img)obj2.img
you have been tasked to write a program that takes two complex number and return their sum.However the + operator will not worl with complex numbers and you figure you need to verload the + and the assignment opeartor=.Ypu have come across the program [URL]
implement it and the client code to see it rune for the following complex numbers:
c1=3.0-4i,c2=8+4i
i have 3 files,driver.cpp,Complexnumber.cpp and complexNumber.h
complex.cpp is as follows
#include <iostream>
using namespace std;
class ComplexNumber {
private:
double real;
double image;
[code]....
I am trying to use std::sort to sort a vector of complex objects using a custom function. However, it keeps erroring "Unresolved overloaded function type".
encounter::encounter(){
// ... cut
std::sort (allpeople.begin(), allpeople.end(), sortByInit);}
bool encounter::sortByInit (character& a, character& b) {
if (a.getinit () == b.getinit ()) {
[Code] ....
I wrote a simple Complex Class and overload input/output and +/- Operators in it!But there is something that doesn't work correctly!I can print an object of that class but I can't print sum of two object or something like that!
Code:
#ifndef COMPLEX_H
#define COMPLEX_H
#include <iostream>
using namespace std;
class Complex {
friend ostream & operator<<(ostream &, const Complex &);
[Code] .....
cout << c3 is Working fine But cout << c1 + c2 is not giving me correct output!
I am working on an assignment to create a Complex number calculator. In this assignment I am to ask the user for input to the calculator. We are given a sample run output that looks like this.
Enter operand1: 3 4
operand1: (3, 4)
Enter operation : +
Enter operand2: 1 2
(3, 4) + (1, 2) = (4, 6)
My question is how would I take from the user: an integer followed by a space followed by another integer and convert that into two seperate accessible int values that I can save as real and imaginary values.
This code is meant to open a file and use overloaded operators for a complex number class. I am getting a lot of errors in my class declaration/definition but I am not sure why.
#include <iostream>
#include <cmath>
#include <fstream>
class CN {
public:
double real;
double im;
[Code] ....
I want to set an integer to zero when it easy equal to another integer, but it seems that the program for some reason won't set the integer to zero. Here is the example of that code:
#include <iostream>
using namespace std;
int main () {
int n = 2;
int r = 2;
if(n==r)
n++;
r*0;
cout << " n is " << n << endl;
cout << " r is " << r << endl;
}
What am I doing wrong, it should say that "n is 3" and "r is 0".
Code:
#include<stdio.h>
#include<conio.h>
void main()
[Code] .....
This program on running returns an error of "ILLEGAL USE OF POINTER".
I want to declare a 2D 4*4 array, and fills the array with the multiplication table of an integer x from the user, for example: x*1,x*2,x*3, ....., x*16 and how to pass that array to a function to print the array and to another function that swaps a column with another column chosen by the user.
View 3 Replies View RelatedCode:
#include<stdio.h> Code: #include<conio.h>
void main() {
int *a[2][2],*b[2][2],*c[2][2],i,j,k;
Printf("
ENTER a MATRIX ELEMENTS
[Code] .....
I need to include validation to only accept numbers and to only the last four odd numbers in the table.
Code:
#include <stdio.h>void main() {
int upper, range, i;
printf("Enter an integer to find multiplication table: ");
scanf("%d",&upper);
[Code].....
How would i be able to overload a multiplication operator that if, in the main example(0, 5, 0) * example (0, 5, 0) is given, it gives me 25?
View 1 Replies View Related how to print a multiplication table of 2,3 ,4 or any table using functions in c++.. ?
Remember using "Functions" e.g Multiplication(int x)
{ }
int main{
then call the function}
int main() {
int x;
int y=1;
for(x=1 ; x<=12 ; x++ , y=y*x ) {
cout<<y<<'
';
}
}
This code give x! ( x factorial).
whenever ,in x<=12 , we change the 12 to any number n where n>=1 and n<=12
the code works and give the (x factorial)
for example 12!=479001600
the problem begins with the number 13.
when we put 13 like this x<=13 or for(x=1 ; x<=13 ; x++ , y=y*x )
the compiler gives a wrong result : it gives 1932053504 which is wrong because the true result is 6227020800
I'm trying to solve Project Euler 16 where you have to calculate 2^1000. SO I made a program that would solve multiplying a number b a single digit factor through manual multiplication in a vector, just to test things out.
The problem is when I take things out of main and try to make a separate function, the original number is never multiplied.
Here's my code with functions...
/*Using vectors manually to multiply a number to a positive power.*/
#include <iostream>
#include <vector>
using namespace std;
void print_vector(const vector<int>& v);
[code]....
Here is the other code, not using functions but even if I use an extra for loop to multiply by the same factor several times, it still does the same thing.
/*Using vectors manually to multiply a number by two (or any single digit factor).*/
#include <iostream>
#include <vector>
using namespace std;
void print_vector(const vector<int>& v);
[code]....