473,662 Members | 2,631 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 10567
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
6399
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 in progress" and was unable to logon .\IWAM_servername in order to run the server. Followed by another error: The server stop serving requests for application __________ because of the number of out of process component crashes exceeded a...
1
2338
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 . thanks pardhi
5
2598
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: =============== Error while trying to run project: unable to start debugging on the web server. Server side-error occured during http request.
6
13565
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 cStepCurveEvaluator.cpp(14) : error C2296: '.*' : illegal, left operand
0
6696
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 Office\Office10\WINWORD.EXE abnormal program termination Clicking on Abort or Retry returns me to the Word document icon I was trying to open. Clicking on Ignore generates a Microsoft Visual C++ Runtime Library stating Runtime Error!...
4
11829
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
6903
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
3601
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. There is also several tests in place to check the data being read into the program to return an error if there are characters that can't be used for a file or folder. There is an option to clean the data being read in which it will read a line of...
2
7150
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 SecondProd,ForthProd;
2
8603
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"); float a;
0
8435
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8768
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7368
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4181
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.