473,507 Members | 13,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how can i debug an error saying illegal structure operation ??? plz help

2 New Member
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. #include<stdio.h>
  5. class complex
  6. {
  7. int real,imag;
  8. public:
  9. void read()
  10. {
  11. cout<<"enter real part:\n";
  12. cin>>real;
  13. cout<<"enter the imag part:\n";
  14. cin>>imag;
  15. }
  16. void display()
  17. {
  18. cout<<"\n"<<real<<"+"<<imag<<"\n";
  19. }
  20. complex add(complex a2)
  21. {
  22. complex temp;
  23. temp.real=real+temp.real;
  24. temp.imag=imag+temp.imag;
  25. return temp;
  26. }
  27. complex subtract(complex a2)
  28. {
  29. complex temp;
  30. temp.real=real-temp.real;
  31. temp.imag=imag-temp.imag;
  32. return temp;
  33. }
  34. complex multi(complex a2)
  35. {
  36. complex temp;
  37. temp.real=(real*a2.real)-(a2.imag*imag);
  38. temp.imag=(real*a2.imag)+(imag*a2.real);
  39. return temp;
  40. }
  41. complex division(complex a2)
  42. {
  43. complex temp;
  44. temp.real=((real*a2.real)+(imag*a2.imag))/((imag*a2.imag)*(real*a2.real));
  45. temp.imag=((imag*a2.real)-(real*a2.imag))/((imag*a2.imag)*(real*a2.real));
  46. return temp;
  47. }
  48. };
  49. void main()
  50. {
  51. int ch;
  52. clrscr();
  53. complex a,b,c;
  54. do
  55. {
  56. cout<<"enter\n 1.addition  2.subtraction  3.multiplication  4.division  5.exit\n";
  57. cout<<"enter ur choice:\n";
  58. cin>>ch;
  59. switch(ch)
  60. {
  61. case 1:cout<<"enter 1st complex no:";
  62.        a.read();
  63.        a.display();
  64.        cout<<"enter 2nd complex no:";
  65.        b.read();
  66.        b.display();
  67.        c=a+b;
  68.        c.display();
  69.        break;
  70. case 2:cout<<"enter 1st complex no:";
  71.        a.read();
  72.        a.display();
  73.        cout<<"enter 2nd complex no:";
  74.        b.read();
  75.        b.display();
  76.        c=b-a;
  77.        c.display();
  78.        break;
  79. case 3:cout<<"enter 1st complex no:";
  80.        a.read();
  81.        a.display();
  82.        cout<<"enter 2nd complex no:";
  83.        b.read();
  84.        b.display();
  85.        c=a*b;
  86.        c.display();
  87.        break;
  88. case 4:cout<<"enter 1st complex no:";
  89.        a.read();
  90.        a.display();
  91.        cout<<"enter 2nd complex no:";
  92.        b.read();
  93.        b.display();
  94.        c=a/b;
  95.        c.display();
  96.        break;
  97. }
  98. }while(1);
  99. }
Dec 20 '13 #1
2 10546
weaknessforcats
9,208 Recognized Expert Moderator Expert
You have class named complex to work with complex numbers. Like this:

Expand|Select|Wrap|Line Numbers
  1. complex a,b,c;
  2. //get values for a and b
  3.  
  4.         c = a + b;
  5.  
which is all fine except the compiler doesn't know how to handle the + operation on your class. Ditto for -,+, and /.

You need to write operator methods for your class and then it will compile.

Expand|Select|Wrap|Line Numbers
  1. complex complex::operator+(complex& rhs)
  2. {
  3.      //add this and the argument
  4.      //return the result}
Dec 20 '13 #2
sumanpoonia
2 New Member
thanx it works.....:)
Dec 21 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
6395
by: AmyAdmin | last post by:
I am running windows 2000 with IIS 5.0 and I have ASP and .NET apps running on that server, and I've been getting the error message in my event viewer: DCom got error "Overlapped I/O operation is...
1
2328
by: pardhi a via SQLMonster.com | last post by:
Hi when i right click table and click design table then error occured (an unexpected error occured during this operation) If any one knows please let let me know your help would be appreciated ....
5
2596
by: Ash | last post by:
Hi, I've just installed Visual Studio.NET on my computer, which runs on windows2000 server. When i creat web application and try run it from vb.net, i get the following error: ===============...
6
13527
by: BlueTrin | last post by:
Hello I was adapting a C version of SolvOpt in C++ to use it within a virtual class. However I am stuck with the overriding of evaluation and gradiant functions. cStepCurveEvaluator.cpp...
0
6678
by: JCD | last post by:
I am using Office XP Professional on Windows XP Home. When I try to open a Word document, I get a Microsoft Visual C++ Debug Library window stating Debug Error! Program:C\Program Files\Microsoft...
4
11787
momotaro
by: momotaro | last post by:
the problem is in the function "Swap" This is the error message that i get: Error 3 error C2088: '*' : illegal for struct and this is my prog: #include <stdio.h> typedef struct {
1
6868
by: cppcompiler1000 | last post by:
when i was writing a program i got an error of " illegal structure operation" , in which situation compiler gives this type of error?
15
3585
by: Fuzz13 | last post by:
I'm writing a program that a user loads a file (txt or csv) in which it reads newlines and commas as new object delimiters. Each new object is put into an array creating a new array object each time....
2
7125
by: Mark05 | last post by:
#include<conio.h> #include<iostream> using namespace std; int main() { double ManfCode,ProdCode; int Checkdigit, SecondManf, FourthManf; int FirstProd,ThirdProd,FifthProd; int...
2
8581
by: sahar7203 | last post by:
i got this error(error C2297: '%' : illegal, right operand has type 'double') in this programmig, who can help me? #include<stdio.h> int main(void) { printf("Amount of sale ($):\t");...
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.