c++ 질문이 있습니다 ㅠ

쿠키앤 크림 (쿠앤크)@Google의 이미지

 #include <iostream>
using namespace std;
class complex{
protected :
	int real;
	int image;	
public:
	complex(int r=0,int i=0);
	friend istream &operator>>(istream &in,complex &a);
	friend ostream &operator<<(ostream &os,complex &a);
	friend complex operator+(complex left,complex right);
 
};
complex::complex(int r,int i) : real(r),image(i)
{}
complex operator+(complex left,complex right)
{
	complex result;
	result.real=left.real+right.real;
	result.real=left.image+right.image;
	return result;
}
ostream &operator<<(ostream &os,complex &a)
{
	os<<a.real<<"+"<<a.image<<"i";
	return os;
}
istream &operator>>(istream &in,complex &a)
{
	cout<<endl<<"복소수 입력"<<endl<<endl;
	cout<<"실수부 입력 = ";
	in>>a.real;
	cout<<"허수부 입력 = ";
	in>>a.image;
	return in;
}
 
class matrix : public complex{
public :
	complex a;
	ostream &operator=(ostream &os,complex &b);
};
void main()
{
	matrix x[3][3];
	matrix y[3][3];
	matrix z[3][3];
	complex a[3][3];
	cout<<"첫번째 행렬 입력"<<endl;
	for(int r=0;r<3;r++){
		for(int i=0;i<3;i++){
	cin>>x[r][i];
		}
	}
	cout<<endl<<"두번째 행렬 입력"<<endl;
	for(int r=0;r<3;r++){
		for(int i=0;i<3;i++){
	cin>>y[r][i];
		}
	}
	cout<<endl;
	for(int r=0;r<3;r++){
		for(int i=0;i<3;i++){
			cout<<x[r][i]<<"\t";
		}
		cout<<endl;
	}
	cout<<endl;
	for(int r=0;r<3;r++){
		for(int i=0;i<3;i++){
			cout<<y[r][i]<<"\t";
		}
		cout<<endl;
	}
	for(int r=0;r<3;r++){
		for(int i=0;i<3;i++){
			a[r][i]=x[r][i]+y[r][i];
			z[r][i]=a[r][i];
		}
	}
 
 
}

3x3 행렬인데 복소수가 있는 행렬 두개의 사칙연산을 만들고있습니다.
앉아서 씨름하고 있는데 여기서 막히네요 ㅠㅠ 도움을 청합니다..
연산자 오버로딩을 꼭 써야하는데요 matrix z의 원소에 complex a를 넣으려고 하는데
=를 따로 오버로딩을 해야될거같은데 잘 모르겠네요 ㅠㅠ

 의 이미지

이것저것 문제가 많아 보이는 C++ 코드입니다만, 과제물이라는 게 너무 명백하니 따로 드릴 말씀은 없군요.

일단 바라시는 내용에 대한 레퍼런스를 드립니다. 대입 연산자를 제대로 작성한다면 동작하게 만들 수는 있을 겁니다.

http://en.cppreference.com/w/cpp/language/copy_assignment

세벌의 이미지

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.