I am receiving an error of \'error C4430: missing type specifier - int assumed.
ID: 3645084 • Letter: I
Question
I am receiving an error of 'error C4430: missing type specifier - int assumed.Im using visual studio C++
#include "stdafx.h"
#include<iostream>
#include<conio.h>
#include<string.h>
#include<stdio.h>
using namespace std;
class complex
{
int i,r;
public:
void read()
{
cout<<" Enter Real Part:";
cin>>r;
cout<<"Enter Imaginary Part:";
cin>>i;
}
void display()
{
cout<<" = "<<r<<"+"<<i<<"i";
}
complex operator+(complex a2)
{
complex a;
a.r=r+a2.r;
a.i=i+a2.i;
return a;
}
complex operator-(complex a2)
{
complex a;
a.r=r-a2.r;
a.i=i-a2.i;
return a;
}
complex operator*(complex a2)
{
complex a;
a.r=(r*a2.r)-(i*a2.i);
a.i=(r*a2.i)+(i*a2.r);
return a;
}
complex operator/(complex a2)
{
complex a;
a.r=((r*a2.r)+(i*a2.i))/((a2.r*a2.r)+(a2.i*a2.i));
a.i=((i*a2.r)-(r*a2.i))/((a2.r*a2.r)+(a2.i*a2.i));
return a;
}
};
main()
{
int ch;
// clrscr();
complex a,b,c;
do
{
cout<<" 1.Addition 2.Substraction";
cout<<" 3.Mulitplication 4.Division 5.Exit ";
cout<<" Enter the choice :";
cin>>ch;
switch(ch)
{
case 1:
cout<<" Enter The First Complex Number:";
a.read();
a.display();
cout<<" Enter The Second Complex Number:";
b.read();
b.display();
c=a+b;
c.display();
break;
case 2:
cout<<" Enter The First Complex Number:";
a.read();
a.display();
cout<<" Enter The Second Complex Number:";
b.read();
b.display();
c=b-a;
c.display();
break;
case 3:
cout<<" Enter The First Complex Number:";
a.read();
a.display();
cout<<" Enter The Second Complex Number:";
b.read();
b.display();
c=a*b;
c.display();
break;
case 4:
cout<<" Enter The First Complex Number:";
a.read();
a.display();
cout<<" Enter The Second Complex Number:";
b.read();
b.display();
c=a/b;
c.display();
break;
}
}while(ch!=5);
getch();
}
Explanation / Answer
please rate - thanks
//#include "stdafx.h" not needed
#include<iostream>
//#include<conio.h> needed for getch() which you don't need
#include<string.h>
//#include<stdio.h> needed for C I/O printf, scanf, so don't need
using namespace std;
class complex
{
int i,r;
public:
void read()
{
cout<<" Enter Real Part:";
cin>>r;
cout<<"Enter Imaginary Part:";
cin>>i;
}
void display()
{
cout<<" = "<<r<<"+"<<i<<"i";
}
complex operator+(complex a2)
{
complex a;
a.r=r+a2.r;
a.i=i+a2.i;
return a;
}
complex operator-(complex a2)
{
complex a;
a.r=r-a2.r;
a.i=i-a2.i;
return a;
}
complex operator*(complex a2)
{
complex a;
a.r=(r*a2.r)-(i*a2.i);
a.i=(r*a2.i)+(i*a2.r);
return a;
}
complex operator/(complex a2)
{
complex a;
a.r=((r*a2.r)+(i*a2.i))/((a2.r*a2.r)+(a2.i*a2.i));
a.i=((i*a2.r)-(r*a2.i))/((a2.r*a2.r)+(a2.i*a2.i));
return a;
}
};
int main() //every function must have a return type-main is nothing more then a function with type int
{
int ch;
// clrscr();
complex a,b,c;
do
{
cout<<" 1.Addition 2.Substraction";
cout<<" 3.Mulitplication 4.Division 5.Exit ";
cout<<" Enter the choice :";
cin>>ch;
switch(ch)
{
case 1:
cout<<" Enter The First Complex Number:";
a.read();
a.display();
cout<<" Enter The Second Complex Number:";
b.read();
b.display();
c=a+b;
c.display();
break;
case 2:
cout<<" Enter The First Complex Number:";
a.read();
a.display();
cout<<" Enter The Second Complex Number:";
b.read();
b.display();
c=b-a;
c.display();
break;
case 3:
cout<<" Enter The First Complex Number:";
a.read();
a.display();
cout<<" Enter The Second Complex Number:";
b.read();
b.display();
c=a*b;
c.display();
break;
case 4:
cout<<" Enter The First Complex Number:";
a.read();
a.display();
cout<<" Enter The Second Complex Number:";
b.read();
b.display();
c=a/b;
c.display();
break;
}
}while(ch!=5);
//getch(); not C++, C also not needed in VC++ this keeps the DOS window open
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.