GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 31-May-2004, 20:53
tinzi tinzi is offline
New Member
 
Join Date: May 2004
Posts: 2
tinzi is on a distinguished road

complex number


I'm using VB6 and tried to add two sets of complex numbers. This is the codes me and my friend worked at but could go no where. See if i can get any fix here. THanks

CPP / C++ / C Code:
#include <iostream>
using std::endl;
using std::ostream;
using std::cout;


class complex {
	public:
		complex ();
		complex (double.double);
		void setreal (double)
			double getreal ();
		double get image;
		complex operator+(complex);
		void print ()

private;
		double real, imag;
};

complex::complex() {
	real = imag = 0

		complex::complex(double r. double i) {
		real = r;
		imag = i;
	}

	void complex::setreal(double r) {
		real = r;
	}

	double complex::getreal(){
		return real;
		double complex::getimag(){
			return imag;
			complex complex::operator *=+(complex x) {
				complex result;
				result.real = x.real + real;
				result.imag = x.imag + imag;
				return result;
			}

			void complex::print (){
				cout <<"real = " <<real<<", image = "<<imag<<endl; 
			}

			int main (void) {
				complex a;
				complex b (3,5);
				cout <<"Before: b.real = " <<b.getreal()<<endl;
				b.setreal (9)
					cout << "after: b.real = "<<b.getreal()<<endl;

				complex c1 (3,5);
				complex c2 (2,4);
				complex c3 = (c1+c2);
				c3.print ();

			return 0;
			}
Last edited by dsmith : 01-Jun-2004 at 09:41. Reason: Please use [c] & [/c] for syntax highlighting
  #2  
Old 31-May-2004, 21:37
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Hello tinzi,

Welcome to the GIDforum and please read this first :GIDForums enables New C/C++ tags

first of all, u and your friend job is really a mess!! lots of missing backets, lots
of typo, missing semiclones, ... did u type this whole code in one go??

U guys need to learn to program step by step, u can't just do one program by
tryng to type the whole program at once, this type of errors and typos is
what u will get,

Here is your code:
CPP / C++ / C Code:
#include <iostream>
using std::endl;
using std::ostream;
using std::cout;


class complex 
{
public:
	complex ();
	complex (double,double);
	void setreal (double);
	double getreal ();
	double getimage();
	complex operator+(complex);
	void print ();

private:
	double real, imag;
};

complex::complex() 
{
	real = imag = 0;
}

complex::complex(double r, double i) 
{
	real = r;
	imag = i;
}

void complex::setreal(double r)		
{
	real = r;
}

double complex::getreal()
{
	return real;
}

double complex::getimage()	
{
	return imag;
}

complex complex::operator +(complex x) 
{
	complex result;
	result.real = x.real + real;
	result.imag = x.imag + imag;
	return result;
}

void complex::print ()
{
	cout <<"real = " <<real<<", image = "<<imag<<endl; 
}

int main (void) 
{
	complex a;
	complex b (3,5);
	cout <<"Before: b.real = " <<b.getreal()<<endl;
	b.setreal (9);
	cout << "after: b.real = "<<b.getreal()<<endl;

	complex c1 (3,5);
	complex c2 (2,4);
	complex c3 = (c1+c2);
	c3.print ();

	return 0;
}
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #3  
Old 01-Jun-2004, 15:47
tinzi tinzi is offline
New Member
 
Join Date: May 2004
Posts: 2
tinzi is on a distinguished road
Thank you very much for fixing the codes for us. After working around with your codes, me and my friend can do subtraction and multiplication. Multiplication did takes time to figure it out, but we are totally stucked on division... Does it needs two formulas to put it together??? so confusing....

I have no idea how to put the multiplication into the original codes, i think we need some explainations to understand even with the solution because we are still newbie...

very appreciated for the help, thank you very much!
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using an array and finding the element number (subscript) tommy69 C Programming Language 27 05-Apr-2004 13:23
Breaking the number into two digits amir_b C Programming Language 3 16-Feb-2004 13:28
c: array comparison jack C Programming Language 7 26-Jan-2004 12:21
How to find the last 6 digits of a 8 digit number? rjd72285 C++ Forum 3 28-Oct-2003 09:21
auto number skyloon MySQL / PHP Forum 1 30-Jun-2003 09:33

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:40.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.